diff --git a/src/3-three/sentences/parse/mainClause.js b/src/3-three/sentences/parse/mainClause.js index af95cae..2e906e7 100644 --- a/src/3-three/sentences/parse/mainClause.js +++ b/src/3-three/sentences/parse/mainClause.js @@ -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 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 const mainClause = function (s) { let m = s @@ -14,7 +29,7 @@ const mainClause = function (s) { return m } // this is a signal for subordinate-clauses - m = m.ifNo(subordinate) + m = dropIntroducedBy(m, subordinate) m = m.ifNo('^even (if|though)') m = m.ifNo('^so that') m = m.ifNo('^rather than') @@ -23,7 +38,7 @@ const mainClause = function (s) { return m } // relative clauses - m = m.ifNo(relative) + m = dropIntroducedBy(m, relative) if (m.length === 1) { return m } diff --git a/tests/three/sentences/svo.test.js b/tests/three/sentences/svo.test.js index 9575c5c..e1e3c5b 100644 --- a/tests/three/sentences/svo.test.js +++ b/tests/three/sentences/svo.test.js @@ -40,6 +40,13 @@ test('svo parser', function (t) { 'the students', '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'], // ['The boy who you saw at the store committed a robbery.', 'the boy', 'committed'],