Public
Edited
Nov 24, 2022
2 stars
Insert cell
Insert cell
nlp('let the blossoming of Millhouse begin').match('#Noun').out('array')
Insert cell
Insert cell
nlp('let the blossoming of Millhouse begin').nouns().out('array')
Insert cell
Insert cell
{
let doc = nlp('bottles')// compromise guesses this is a Verb
doc.debug()// see the tags like this

//because it's a Verb, this will do nothing, now
doc.nouns().toSingular()
//instead, co-erce the text to particular Tags
doc.tag('Plural')
doc.nouns().toSingular() //now this will work
return doc.text()
}
Insert cell
Insert cell
{
let doc = nlp('walks') // assumed to be a verb
// tag it as a noun (neither plural or singular)
doc.tag('Noun')
// this method will do some plural/singular guesswork
if (doc.nouns().isPlural()) {
doc.tag('Plural')
}
//now this will work
return doc.nouns().toSingular().text()
}
Insert cell
Insert cell
nlp('trousers').json()[0].terms[0].tags //see the tag
Insert cell
nlp('trousers').nouns().toSingular().text() //it doesn't become 'trouser'
Insert cell
Insert cell
{
let lex= {scissors:'Uncountable'}
let doc= nlp('scissors', lex).debug()//it now has the #Uncountable tag
doc.nouns().toSingular() //ah, ok cool
return doc.text()
}
Insert cell
Insert cell
{
let {methods, model} = nlp.world()
const { toSingular, toPlural } = methods.two.transform.noun

let a = toSingular('cookies', model)
let b= toPlural('cookie', model)
return [a, b]
}
Insert cell
Insert cell
Insert cell
nlp(`so, do you come to Milwaukee often?`).nouns().out('array')
Insert cell
Insert cell
nlp(`Milwaukee has certainly had its share of visitors`).nouns().json()[0]
Insert cell
Insert cell
nlp('the big red door').nouns().adjectives().out('array')
Insert cell
Insert cell
nlp('the purple dinosaur').nouns().toPlural().all().text()
Insert cell
nlp('i drank a margharita').nouns().toPlural().all().text()
Insert cell
Insert cell
nlp('seven swans a swimming').nouns().toSingular().all().text()
Insert cell
Insert cell
nlp('two turtledoves and a partridge in a pear tree').nouns().isPlural().out('array')
Insert cell
Insert cell
nlp('two turtledoves and a partridge in a pear tree').nouns().isSingular().out('array')
Insert cell
Insert cell
Insert cell
Insert cell
{
let doc = nlp('tied my shoelaces')
doc.nouns().toSingular()
return doc.text()
}
Insert cell
{
let doc=nlp('the last hour')
doc.nouns().toPlural()
return doc.text()
}
Insert cell
Insert cell
nlp('All my life I’ve had one dream, to accomplish my many goals.').nouns().isPlural().out('array')
Insert cell
Insert cell
{
nlp.extend((_Doc, world) => {
world.addPlurals({ neglectee: 'neglecterinos' })
})
const doc = nlp('neglectee')
return doc.nouns().toPlural().text()
}
Insert cell
Insert cell
Insert cell
Insert cell
{
//get the wikipedia plaintext with wtf_wikipedia
let text = await wtf.fetch(article).then(doc=>doc.plaintext())
//get all the nouns from the text
let nouns = nlp(text).nouns()
//sort them by frequency
let res = nouns.out('topk')
// show just the top
res=res.sort((a,b)=> a.count < b.count).slice(0, 15)
return JSON.stringify(res, null, 2)
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more