Don't read a titlecase gerund after a colon as a proper noun
This commit is contained in:
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
|
// 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]
|
const term = terms[i]
|
||||||
// assume terms are already indexed
|
// assume terms are already indexed
|
||||||
term.index ||= [0, 0]
|
term.index ||= [0, 0]
|
||||||
@@ -40,6 +40,12 @@ const checkCase = function (terms, i, model) {
|
|||||||
if (/["']$/.test(term.pre)) {
|
if (/["']$/.test(term.pre)) {
|
||||||
return null
|
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') {
|
if (term.normal === 'the') {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ const firstPass = function (docs, model, world) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// these methods don't care about word-neighbours
|
// 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) {
|
for (let i = 0; i < terms.length; i += 1) {
|
||||||
// skip frozen terms, for now
|
// skip frozen terms, for now
|
||||||
if (terms[i].frozen === true) {
|
if (terms[i].frozen === true) {
|
||||||
@@ -47,7 +47,7 @@ const secondPass = function (terms, model, world, isYelling) {
|
|||||||
tagSwitch(terms, i, model)
|
tagSwitch(terms, i, model)
|
||||||
// is it titlecased?
|
// is it titlecased?
|
||||||
if (isYelling === false) {
|
if (isYelling === false) {
|
||||||
checkCase(terms, i, model)
|
checkCase(terms, i, model, afterColon)
|
||||||
}
|
}
|
||||||
// look at word ending
|
// look at word ending
|
||||||
checkSuffix(terms, i, model)
|
checkSuffix(terms, i, model)
|
||||||
@@ -104,8 +104,11 @@ const preTagger = function (view) {
|
|||||||
const terms = document[n]
|
const terms = document[n]
|
||||||
// is it all upper-case?
|
// is it all upper-case?
|
||||||
const isYelling = ignoreCase(terms)
|
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
|
// guess by the letters
|
||||||
secondPass(terms, model, world, isYelling)
|
secondPass(terms, model, world, isYelling, afterColon)
|
||||||
// guess by the neighbours
|
// guess by the neighbours
|
||||||
thirdPass(terms, model, world, isYelling)
|
thirdPass(terms, model, world, isYelling)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,3 +119,17 @@ test('match:', function (t) {
|
|||||||
})
|
})
|
||||||
t.end()
|
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()
|
||||||
|
})
|
||||||
Reference in new issue
Block a user