Public
Edited
Nov 3, 2022
1 star
Insert cell
Insert cell
{
let doc = nlp('he probably misses his old glasses')
return doc.match('{miss/verb}').text()
}
Insert cell
Insert cell
{
let doc = nlp('Salvaging sunken barges for scrap iron')
//compute all roots
doc.compute('root')
// retrieve them from .json() response
return doc.json()[0].terms.map(t=>t.root || t.normal)
}
Insert cell
{
let doc = nlp('Salvaging sunken barges for scrap iron')
//grab part of the document
let m = doc.matchOne('#Verb')
//compute root for only one word (salvaging)
m.compute('root')
//output root forms, as text
return doc.text('root')
}
Insert cell
Insert cell
nlp('he walked quickly').match('he {walk}').text()
Insert cell
Insert cell
nlp('slicking his hair back').match('{slick/adjective}').found
Insert cell
nlp('slicking his hair back').match('{slick/verb}').found
Insert cell
nlp.parseMatch('{slick/verb}')[0]
Insert cell
nlp.parseMatch('{slick/adjective}')[0]
Insert cell
Insert cell
{
let doc = nlp('i walked downtown').compute('root')
doc.swap('walk', 'stroll') //use root-forms
return doc.text()
}
Insert cell
Insert cell
{
let doc = nlp('two hot dogs please').compute('root')
doc.swap('hot dog', 'hamburger') //use singular-forms
return doc.text()
}
Insert cell
Insert cell
{
let doc = nlp('he ran faster than her')
doc.compute('root')
doc.swap('fast','quick')
return doc.text()
}
Insert cell
Insert cell
{
let doc = nlp('i dug up the solution, while digging up treasure.')
doc.compute('root')
return doc.swap('dig up', 'find').text()
}
Insert cell
Insert cell
{
let words = ['run', 'walk', 'splin']
// pre-compile them into a trie datastructure
let trie = nlp.compile(words)
let doc = nlp(`Well, I'm running down the road tryin' to loosen my load`)
doc.compute('root')
// now this is super-efficient
let m = doc.lookup(words, {form:'root'})
return m.out('array')
}
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more