Published
Edited
Mar 24, 2022
1 star
Insert cell
Insert cell
nlp('Hi Bart. Hello mrs Cumberdale.').document
Insert cell
Insert cell
{
let doc = nlp("that's it. Back to Winnipeg!")
let json = doc.document //grab it
json[1][0].text = json[1][0].text.toUpperCase() //mess around
return doc.text()
}
Insert cell
Insert cell
// See the pointer as just array indexes
// [1st sentence, start on 2nd term, end 3rd term, expected term-id]
nlp("that's it. Back to Winnipeg!").match('#Place').pointer[0]
Insert cell
Insert cell
{
let doc = nlp('before middle after')
let m = doc.match('middle')
// add an extra word
doc.match('before').insertAfter('EXTRA')
return m.text() // match is consistent
}
Insert cell
Insert cell
{
let doc = nlp(`he hadn't really walked away.`)
let tmp = doc.clone()
// throw-around our temporary text
tmp.contractions().expand()
tmp.remove('(#Adverb|not)')
// run the analysis on a normalized form
if(tmp.has('had #PastTense')){
return `[found-verb-tense] - ${doc.text()}`
}
}
Insert cell
Insert cell
{
let doc = nlp('January the 12th of 2022 at 3pm')
// mutate a clone
let tmp = doc.clone()
tmp.remove('(the|of|at|#Time)')
tmp.numbers().toCardinal()
// now 'january 12 2022'
let tmpYear = tmp.match('#Month . [#Value]$', 0)
// '2022'
// get the match in the original document
let year = doc.match(tmpYear) // just throw it in..
// '2022' (a different one)
// prove we're in the original
return year.grow('*').text()
}
Insert cell
Insert cell
{
let doc = nlp('one two three')
let tmp = doc.clone()
// mutate the original
doc.remove('two')
// return a partial match
return doc.match(tmp).text()
}
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