From 6099cb9020863c161d468241abfad2669137ab4b Mon Sep 17 00:00:00 2001 From: DualFroz Date: Mon, 14 Sep 2026 16:15:15 +0200 Subject: [PATCH] Recognize more openers of secondary clauses in mainClause --- src/3-three/sentences/parse/mainClause.js | 11 ++++++++++- tests/three/sentences/svo.test.js | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/3-three/sentences/parse/mainClause.js b/src/3-three/sentences/parse/mainClause.js index 2e906e7..d033dec 100644 --- a/src/3-three/sentences/parse/mainClause.js +++ b/src/3-three/sentences/parse/mainClause.js @@ -1,5 +1,6 @@ // if a clause starts with these, it's not a main clause -const subordinate = `(after|although|as|because|before|if|since|than|that|though|when|whenever|where|whereas|wherever|whether|while|why|unless|until|once)` +// followed by a number, 'since' or 'once' is a preposition or an adverb ('since 2010', 'once upon a time') +const subordinate = `(after|although|as|because|before|if|since|than|that|though|when|whenever|where|whereas|wherever|whether|while|why|unless|until|once) !(#Value|upon|then|now)` const relative = `(that|which|whichever|who|whoever|whom|whose|whomever)` // a subordinator or relative pronoun only makes the clause secondary when it @@ -34,6 +35,7 @@ const mainClause = function (s) { m = m.ifNo('^so that') m = m.ifNo('^rather than') m = m.ifNo('^provided that') + m = m.ifNo('^in case') if (m.length === 1) { return m } @@ -55,6 +57,13 @@ const mainClause = function (s) { return m } + // an infinitive or an inverted condition ('To win ...', 'Had I known ...') + m = m.ifNo('^to #Infinitive') + m = m.ifNo('^#Condition') + if (m.length === 1) { + return m + } + // did we go too far? if (m.length === 0) { m = s diff --git a/tests/three/sentences/svo.test.js b/tests/three/sentences/svo.test.js index e1e3c5b..e7be701 100644 --- a/tests/three/sentences/svo.test.js +++ b/tests/three/sentences/svo.test.js @@ -47,6 +47,9 @@ test('svo parser', function (t) { ], ['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'], + ['To win the race, you must train every day.', 'you', 'must train'], + ['Had I known, I would have left earlier.', 'i', 'would have left'], + ['In case you forget, we will remind you.', 'we', 'will remind'], // ['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'], @@ -62,3 +65,15 @@ test('svo parser', function (t) { }) t.end() }) + +test('svo main clause after a preposition', function (t) { + const arr = [ + ['Since 2010 we have lived here, and we love it.', 'have lived'], + ['Once upon a time there lived a king, and he was rich.', 'lived'], + ] + arr.forEach(a => { + const obj = nlp(a[0]).sentences().json()[0] + t.equal(obj.sentence.verb, a[1], here + 'verb: ' + a[1]) + }) + t.end() +})