Published
Edited
Mar 25, 2022
Insert cell
Insert cell
{
let doc = nlp("Hey bart. Hi Bart. hello mrs Cumberdale.")
return doc.map(d=> d.text())
}
Insert cell
Insert cell
{
let doc = nlp("Hey bart. Hi Bart. hello mrs Cumberdale.")
return doc.terms().map(d=> d.text())
}
Insert cell
Insert cell
{
let doc = nlp('Larry, Curly, and Moe')
let people = doc.match('#Noun') // (any one noun)
//sort them alphabetically:
people.sort('alpha')
return people.map(d=> d.text('normal'))
}
Insert cell
Insert cell
{
let doc = nlp("we've also arrested your older, balder, fatter son.")
let adj = doc.match('#Adjective')
adj.sort() // default method: alphabetical
return adj.out('array')
}
Insert cell
Insert cell
Insert cell
{
// ADD CUSTOM SORT METHOD
let doc = nlp('Eeny, meeny, miny, moe')
//split up each term
let terms = doc.terms()
//use a custom sort method
terms.sort((a, b) => {
//sort by length of normalized text
if (a.text('reduced').length > b.text('reduced').length) {
return -1
}
return 1
})
let arr = terms.map(d => d.text('normal'))
return arr
}
Insert cell
Insert cell
{
let doc = nlp(`Springfield, springfield! it's a hell of a town.`)
let terms = doc.terms() //split by term
//remove duplicate matches
terms = terms.unique()
return terms.out('array')
}
Insert cell
Insert cell
Insert cell
{
let doc = nlp("that's it. Back to Winnipeg!")
// reverse the order of the sentences
doc = doc.reverse()
//clean-up the whitespace
doc.normalize({ whitespace: true })
return doc.map(d => d.text('normal'))
}
Insert cell
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