Published
Edited
Mar 23, 2022
2 forks
13 stars
Insert cell
Insert cell
// var nlp = require('compromise');
nlp(`we don't need no education`).text()
Insert cell
Insert cell
{
//parse the text, again
let doc = nlp(`we don't need no education`)
//grab the contractions
doc.contractions().expand()
//print it again, as text
return doc.text()
}
Insert cell
Insert cell
nlp(`homer's odyssey`).has('#Possessive')
Insert cell
Insert cell
nlp(`homer's hungry`).has('#Possessive')
Insert cell
Insert cell
nlp(`homer's hungry`).json()
Insert cell
nlp(`homer's odyssey`).out('tags')
Insert cell
Insert cell
nlp('Hey, teacher! leave those kids alone').match('those #Plural').text()
Insert cell
Insert cell
Insert cell
nlp('Somebody once told me the world was gonna roll me.').match('the .').text()
Insert cell
Insert cell
{
let doc = nlp('i went and saw Boston') //interprets this as a #Place
//grab the one word..
let word = doc.match('boston')
//give it a new tag,
word.tag('RockBand')
//now this word can be found this way:
return doc.match('#RockBand').text()
}
Insert cell
Insert cell
{
//declare new tags in a plugin,
const myPlugin = (doc, world)=>{
world.addTags({
RockBand:{
isA: 'Organization'
}
})
}
nlp.extend(myPlugin)
//parse the document again
let doc = nlp('boston was loud')
//grab the word, and tag it
doc.match('boston').tag('RockBand')
//see if it's still a #Place now
return doc.match('#Place').length
}
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