Published
Edited
Mar 23, 2022
1 fork
Importers
10 stars
Insert cell
Insert cell
{
let text = await getText('Vladamir Putin')
let arr = nlp(text).people()
return printList(arr)
}
Insert cell
Insert cell
{
let text = await getText('Tom Green')
let arr = nlp(text).places()
return printList(arr)
}
Insert cell
Insert cell
{
let arr = nlp("If word gets out about this, Kwazy-Clown Airlines will be a laughing stock.").organizations()
return printList(arr)
}
Insert cell
Insert cell
{
let text = await getText('Alan Greenspan')
let arr = nlp(text).topics()
return printList(arr)
}
Insert cell
Insert cell
{
var text = `i went to Toronto's waterfront and saw the Toronto Blue Jays`
var topics = nlp(text).topics()
//normalize them
topics.normalize({possessives:true}) //maybe add plurals: true?
topics = topics.out('array')
//throw these at wikipedia (follows redirects)
let docs = await wtf.fetch(topics)
//get rid of empty results
docs = docs.filter(l=> l)
//render some html
let result= docs.map(doc=>{
return `<li id="result">${doc.sentences(0).text()}</li>` //print the first sentence of the article
}).join(' ')
return html`${result}`
}
Insert cell
Insert cell
{
let str = `Elizabeth Woolridge Grant (born June 21, 1985), known professionally as Lana Del Rey, is an American singer, songwriter, record producer, poet, and model.`;
let doc=nlp(str)
//grab default results
let topics=doc.topics()
//grab all titlecased words
let capitals=doc.clauses().match('#TitleCase+')
//add them in to our results
topics = topics.concat(capitals).unique().sort('chron')
return topics.out('array')
}
Insert cell
Insert cell
Insert cell
printList=function(doc){
return JSON.stringify(doc.out('array'), null, 2)
}
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