Public
Edited
Mar 24, 2022
1 star
Insert cell
Insert cell
Insert cell
nlp.tokenize(`as shocks go, this one's a real zaperoo.`).json(0).terms
Insert cell
Insert cell
{
nlp.plugin({
// add new tags
tags:{
"Food": {
"isA": "Noun"
},
"Dessert": {
"isA": "Food"
},
"Vegetable":{
"isA": "Food",
"notA": "Dessert"
}
},

// add new words to the lexicon
words:{
rutabaga: 'Vegetable',
'spotted dick': 'Dessert',
},

api:(View)=>{
//add a new method to compromise
View.prototype.isHealthy = function(){
return this.match('#Food+').notIf('Dessert')
}
}
})
// see our plugin in-action:
return nlp('i ate rutabaga and a carrot cake').isHealthy().out('array')
}
Insert cell
{
let doc = nlp(`as shocks go, this one's a real zaperoo.`)
let data = doc.json()
// (you can put this into a database, or something)
//... ok, load this data as a new doc object
let doc2 = nlp(data)
return doc2.json()
}
Insert cell
Insert cell
{
// turn-on verbose mode
nlp.verbose('tagger')
nlp("why can't i have no kids and three money?")
//see the output in the developer console
}
Insert cell
Insert cell
nlp.version
Insert cell
Insert cell
nlp.world()
Insert cell
Insert cell
{
let matchString = 'who . (the|that)'
// parse it into a faster format
let matchObj = nlp.parseMatch(matchString)
let docs=[
`who controls the British crown?`,
`Who keeps the metric system down?`,
`the leader? who's that, some kind of leader?`
]
return docs.map(str => {
let doc = nlp(str)
//avoid re-parsing the match-string, each time
return doc.match(matchObj).text()
})
}
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