Don't read a titlecase gerund after a colon as a proper noun

This commit is contained in:
dualfroz committed 2026-10-03 15:24:07 +02:00
1 parent b22c9bdc67
commit 99447e00a1
3 files changed
+27 -4

No files matched your search

@@ -20,7 +20,7 @@ const nope = {
}
// if it's a unknown titlecase word, it's a propernoun
const checkCase = function (terms, i, model) {
const checkCase = function (terms, i, model, afterColon) {
const term = terms[i]
// assume terms are already indexed
term.index ||= [0, 0]
@@ -40,6 +40,12 @@ const checkCase = function (terms, i, model) {
if (/["']$/.test(term.pre)) {
return null
}
// gerund after a colon - 'Tutorial: Creating a cake'
const before = terms[i - 1]
const hasColon = before ? /:/.test(before.post) : afterColon
if (hasColon && term.tags.has('Gerund')) {
return null
}
if (term.normal === 'the') {
return null
}
+6 -3
View File
@@ -37,7 +37,7 @@ const firstPass = function (docs, model, world) {
}
// these methods don't care about word-neighbours
const secondPass = function (terms, model, world, isYelling) {
const secondPass = function (terms, model, world, isYelling, afterColon) {
for (let i = 0; i < terms.length; i += 1) {
// skip frozen terms, for now
if (terms[i].frozen === true) {
@@ -47,7 +47,7 @@ const secondPass = function (terms, model, world, isYelling) {
tagSwitch(terms, i, model)
// is it titlecased?
if (isYelling === false) {
checkCase(terms, i, model)
checkCase(terms, i, model, afterColon)
}
// look at word ending
checkSuffix(terms, i, model)
@@ -104,8 +104,11 @@ const preTagger = function (view) {
const terms = document[n]
// is it all upper-case?
const isYelling = ignoreCase(terms)
// does it follow a colon?
const before = document[n - 1]
const afterColon = before !== undefined && /:/.test(before[before.length - 1].post)
// guess by the letters
secondPass(terms, model, world, isYelling)
secondPass(terms, model, world, isYelling, afterColon)
// guess by the neighbours
thirdPass(terms, model, world, isYelling)
}
+14
View File
@@ -119,3 +119,17 @@ test('match:', function (t) {
})
t.end()
})
test('titlecase after a colon', function (t) {
const arr = [
['Tutorial: Creating a cake', '. #Gerund #Determiner #Noun'],
['Step two: Mixing the flour', '. #Value #Gerund the #Noun'],
['On Tuesday: Baking a cake', 'on #Date #Singular a #Noun'],
]
arr.forEach(function (a) {
const [str, match] = a
const doc = nlp(str)
t.equal(doc.match(match).text(), doc.text(), here + str)
})
t.end()
})