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

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