Match lexicon words that start with # or @
This commit is contained in:
1 parent
1a4531e30f
commit
3ff36c655a
2 files changed
+21
No files matched your search
@@ -17,6 +17,11 @@ const checkLexicon = function (terms, i, world) {
|
|||||||
setTag([t], lexicon[word], world, false, '1-lexicon')
|
setTag([t], lexicon[word], world, false, '1-lexicon')
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
// '#gojetsgo' can be in the lexicon with its hash
|
||||||
|
if (t.machine && Object.hasOwn(lexicon, t.normal)) {
|
||||||
|
setTag([t], lexicon[t.normal], world, false, '1-lexicon-normal')
|
||||||
|
return true
|
||||||
|
}
|
||||||
// lookup aliases in the lexicon
|
// lookup aliases in the lexicon
|
||||||
if (t.alias) {
|
if (t.alias) {
|
||||||
const found = t.alias.find(str => Object.hasOwn(lexicon, str))
|
const found = t.alias.find(str => Object.hasOwn(lexicon, str))
|
||||||
|
|||||||
@@ -74,6 +74,22 @@ test('apostrophe lexicon:', function (t) {
|
|||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('hashtag lexicon:', function (t) {
|
||||||
|
const lex = {
|
||||||
|
'#GoJetsGo': 'SportsTeam',
|
||||||
|
'@NHLJets': 'SportsTeam',
|
||||||
|
}
|
||||||
|
let doc = nlp('#GoJetsGo', lex)
|
||||||
|
t.equal(doc.match('#SportsTeam').text(), '#GoJetsGo', here + 'lexicon w/ hashtag')
|
||||||
|
|
||||||
|
doc = nlp('go @NHLJets', lex)
|
||||||
|
t.equal(doc.match('#SportsTeam').text(), '@NHLJets', here + 'lexicon w/ at-mention')
|
||||||
|
|
||||||
|
doc = nlp('GoJetsGo', lex)
|
||||||
|
t.equal(doc.has('#SportsTeam'), false, here + 'no hashtag, no match')
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
test('long lexicon:', function (t) {
|
test('long lexicon:', function (t) {
|
||||||
nlp.addWords({ 'new york yankees are cool and not bad': 'Long' })
|
nlp.addWords({ 'new york yankees are cool and not bad': 'Long' })
|
||||||
let doc = nlp('the new york yankees are cool and smart')
|
let doc = nlp('the new york yankees are cool and smart')
|
||||||
|
|||||||
Reference in new issue
Block a user