Public
Edited
Jul 17, 2022
1 fork
2 stars
Insert cell
Insert cell
Insert cell
{
let doc = nlp('you are Lisa Simpson')
let m = doc.match('#FirstName @isTitleCase')
return m.text()
}
Insert cell
{
let doc = nlp('you could still go to McGill, the Harvard of Canada!')
let m = doc.match('the . of #Country')
m = m.match('#ProperNoun of #ProperNoun') //nested matches are like an 'AND'
m.match('(harvard|yale|brown)').toUpperCase() // change a bit of it
return m.text()
}
Insert cell
Insert cell
nlp('you are Lisa Simpson').not('#Person').text()
Insert cell
Insert cell
nlp('one two match three').not('match').out('array')
Insert cell
Insert cell
{
let doc = nlp('one two match three')
let m = doc.not('match') // "one two", "three"
return m.match('two three').found
}
Insert cell
Insert cell
{
let doc = nlp(`why can't i have no kids and three money?`)
let vb = doc.match('#Verb') // "can't", "have"
return doc.not(vb).out('array')
}
Insert cell
Insert cell
nlp('you are Lisa Simpson. Langdon Alger likes puzzles.').matchOne('#Person+').text()
Insert cell
Insert cell
nlp(`Hey bart. Hi Bart. hello mrs Cumberdale.`).if('bart').text()
Insert cell
Insert cell
nlp(`Hey bart. Hi Bart. hello mrs Cumberdale.`).ifNo('bart').text()
Insert cell
Insert cell
nlp(`Hey bart. Hi Bart. hello mrs Cumberdale.`).has('bart')
Insert cell
Insert cell
nlp('one two three four five. one three four').match('three').lookBehind('#Value$').out('array')
Insert cell
Insert cell
nlp('one two three four five. one three four').match('three').lookAhead('^#Value').out('array')
Insert cell
Insert cell
nlp('one two three four five. one three four').match('three').growLeft('two').out('array')
Insert cell
Insert cell
nlp('one two three four five. one three four').match('two').growRight('three four').out('array')
Insert cell
Insert cell
{
let words = ['west philadelphia', 'b ball', 'west milwaukee']
// pre-compile them into a trie datastructure
let trie = nlp.compile(words)
let doc = nlp(freshPrince)
// now this is super-efficient
let m = doc.lookup(words)
return m.out('array')
}
Insert cell
Insert cell
Insert cell
Insert cell
{
let doc = nlp('june 2022')
return doc.match('june [2022]', 0).text() //return just inside the brackets
}
Insert cell
{
let doc = nlp('first, turn left and enter the tunnel')
// or name the capture group something:
return doc.match('turn [<direction>(left|right|up|down)]', 'direction').text()
}
Insert cell
Insert cell
{
let doc = nlp('i went on a talk with a corn stalk.')
let m = doc.match('. ~walk~', null, { fuzzy: 0.6 }) // default is 0.8
return m.out('array')
}
Insert cell
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