Public
Edited
Dec 7, 2022
Insert cell
Insert cell
{
let doc = nlp('Who holds back the electric car? Who made Steve Guttenberg a star?')
let nouns = doc.match('#Person+')
return nouns.json({offset:true})[0].offset
}
Insert cell
Insert cell
{
let txt=' 🎶 Who made Steve Guttenberg a star? 🎵'
let doc = nlp(txt)
let json = doc.match('#Person+').json({offset:true})[0]
let offset = json.offset
//replace the string at offset
let before = txt.substring(0, offset.start)
let replacement = `**${json.text}**` //add highlight
let after = txt.substring(offset.start + offset.length)
return `${before}${replacement}${after}`
}
Insert cell
Insert cell
{
let doc = nlp("soft and yielding like a nerf ball")
return doc.wrap({
'#Adjective': (m) => `[${m.text()}]`
})
}
Insert cell
Insert cell
{
let doc = nlp("bold and italic")
return doc.wrap({
'bold and': (m) => `<b>${m.text()}</b>`,
'and italic': (m) => `<i>${m.toUpperCase().text()}</i>` //ignored
})
}
Insert cell
{
let doc = nlp("it was bold and uppercase")
return doc.wrap({
'bold': (m) => `<b>${m.text()}</b>`,
'bold and uppercase': (m) => `<b>${m.toUpperCase().text()}</b>`
})
}
Insert cell
Insert cell
Insert cell
{
let doc = nlp(`The aurora borealis? At this time of year?`).debug()
let str= doc.html({
'.red': 'aurora #Noun', //a class name : match
})
return html`${str}`
}
Insert cell
Insert cell
Insert cell
{
let doc = nlp(sentence)
let out = doc.out({
'#Person+': (m) => {
let page = encodeURIComponent(m.text().replace(/ /g, '_')) //some wikipedia encoding
return `<a href="https://en.m.wikipedia.org/wiki/${page}" target="_blank">${m.text()}</a>`
}
})
return html`${out}`
}
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