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

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