only treat subordinators as secondary-clause signals before the verb
mainClause() dropped any clause merely containing 'that', 'before', 'who' etc, so a main clause with a nested relative clause lost to a comma-list fragment and the wrong verb was reported. Only drop a clause when the word comes before the clause's own verb, and parse the pattern once per call rather than once per clause. Fixes #1035
This commit is contained in:
1 parent
4328bab986
commit
5424b39d8d
2 files changed
+24
-2
No files matched your search
@@ -2,6 +2,21 @@
|
|||||||
const subordinate = `(after|although|as|because|before|if|since|than|that|though|when|whenever|where|whereas|wherever|whether|while|why|unless|until|once)`
|
const subordinate = `(after|although|as|because|before|if|since|than|that|though|when|whenever|where|whereas|wherever|whether|while|why|unless|until|once)`
|
||||||
const relative = `(that|which|whichever|who|whoever|whom|whose|whomever)`
|
const relative = `(that|which|whichever|who|whoever|whom|whose|whomever)`
|
||||||
|
|
||||||
|
// a subordinator or relative pronoun only makes the clause secondary when it
|
||||||
|
// introduces the clause - after the verb it belongs to a nested clause instead
|
||||||
|
const dropIntroducedBy = function (m, pattern) {
|
||||||
|
// parse the pattern once here, instead of once per clause
|
||||||
|
const reg = m.world.methods.one.parseMatch(pattern, {}, m.world)
|
||||||
|
return m.filter(c => {
|
||||||
|
const found = c.matchOne(reg)
|
||||||
|
if (!found.found) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
const verb = c.matchOne('#Verb')
|
||||||
|
return verb.found && verb.fullPointer[0][1] <= found.fullPointer[0][1]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
//try to remove secondary clauses
|
//try to remove secondary clauses
|
||||||
const mainClause = function (s) {
|
const mainClause = function (s) {
|
||||||
let m = s
|
let m = s
|
||||||
@@ -14,7 +29,7 @@ const mainClause = function (s) {
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
// this is a signal for subordinate-clauses
|
// this is a signal for subordinate-clauses
|
||||||
m = m.ifNo(subordinate)
|
m = dropIntroducedBy(m, subordinate)
|
||||||
m = m.ifNo('^even (if|though)')
|
m = m.ifNo('^even (if|though)')
|
||||||
m = m.ifNo('^so that')
|
m = m.ifNo('^so that')
|
||||||
m = m.ifNo('^rather than')
|
m = m.ifNo('^rather than')
|
||||||
@@ -23,7 +38,7 @@ const mainClause = function (s) {
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
// relative clauses
|
// relative clauses
|
||||||
m = m.ifNo(relative)
|
m = dropIntroducedBy(m, relative)
|
||||||
if (m.length === 1) {
|
if (m.length === 1) {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,13 @@ test('svo parser', function (t) {
|
|||||||
'the students',
|
'the students',
|
||||||
'remained',
|
'remained',
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'She led a diverse advisory committee throughout the process that included membership from schools, city planning departments, state engineering departments, transit agencies, and AARP.',
|
||||||
|
'she',
|
||||||
|
'led',
|
||||||
|
],
|
||||||
|
['He bought the car that the dealer, the bank, and the broker all recommended.', 'he', 'bought'],
|
||||||
|
['I ate dinner before I went to bed.', 'i', 'ate'],
|
||||||
|
|
||||||
// ['every day the kitten tries to eat the mouse', 'the kitten', 'tries to eat'],
|
// ['every day the kitten tries to eat the mouse', 'the kitten', 'tries to eat'],
|
||||||
// ['The boy who you saw at the store committed a robbery.', 'the boy', 'committed'],
|
// ['The boy who you saw at the store committed a robbery.', 'the boy', 'committed'],
|
||||||
|
|||||||
Reference in new issue
Block a user