Public
Edited
Feb 12, 2024
1 star
Insert cell
Insert cell
world = nlp.world()
Insert cell
Insert cell
Insert cell
{
// add a new regular expression to run during the tagger
const plugin = {
mutate: world => {
// 'i before e, but not after c'
world.model.two.regexNormal.push([/(?<!c)ei/, 'Typo'])
},
}
nlp.plugin(plugin)
return nlp('relief, releif, receive').out('tags')[0]
}
Insert cell
Insert cell
{
world.methods.one.termMethods.hasVowel = (term)=> /[aeiou]/.test(term.text)
return nlp(`brrr it's cold`).match('@hasVowel').out('array')
}
Insert cell
{
const toPlural = world.methods.two.transform.noun.toPlural
return toPlural('shoe', nlp.model())
}
Insert cell
Insert cell
{
const methods = nlp.world().methods
//change the sentence-splitting tokenizer
methods.one.tokenize.splitSentences = function (str) {
return str.split(/[.?!]/) //(demonstration purposes!)
}
//change the term-splitting tokenizer
methods.one.tokenize.splitTerms = function (str) {
return str.split(/ /) //works for me!
}
//now the hyphenated term is combined:
return nlp('one two-three four five').terms().out('array')
}
Insert cell
Insert cell
nlp.world().methods
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