Recognize more openers of secondary clauses in mainClause

This commit is contained in:
dualfroz committed 2026-09-14 16:15:15 +02:00
1 parent 5424b39d8d
commit 6099cb9020
2 files changed
+25 -1

No files matched your search

+10 -1
View File
@@ -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
+15
View File
@@ -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()
})