Upstream spencermountain/compromise state of the touched files before c4984cdae1

This commit is contained in:
upstream committed 2026-09-14 16:17:27 +02:00
1 parent 6099cb9020
commit dfd30c3b15
2 files changed
+48 -15

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
import findMain from './mainClause.js'
const grammar = function (vb) {
let tense = null
if (vb.has('#PastTense')) {
tense = 'PastTense'
} else if (vb.has('#FutureTense')) {
tense = 'FutureTense'
} else if (vb.has('#PresentTense')) {
tense = 'PresentTense'
}
return {
tense
}
}
const parse = function (s) {
const clauses = s.clauses()
const main = findMain(clauses)
const chunks = main.chunks()
let subj = s.none()
let verb = s.none()
let pred = s.none()
chunks.forEach((ch, i) => {
if (i === 0 && !ch.has('<Verb>')) {
subj = ch
return
}
if (!verb.found && ch.has('<Verb>')) {
verb = ch
return
}
if (verb.found) {
pred = pred.concat(ch)
}
})
// cleanup a missed parse
if (verb.found && !subj.found) {
subj = verb.before('<Noun>+').first()
}
return {
subj,
verb,
pred,
grammar: grammar(verb)
}
}
export default parse
-15
View File
@@ -47,9 +47,6 @@ 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'],
@@ -65,15 +62,3 @@ 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()
})