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

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