From 64db6b2acb1dd272b013b9d0ea96eb89a44b7a50 Mon Sep 17 00:00:00 2001 From: DualFroz Date: Mon, 14 Sep 2026 16:17:27 +0200 Subject: [PATCH] Skip the verb of a relative clause after the subject --- src/3-three/sentences/parse/index.js | 12 ++++++++++++ tests/three/sentences/svo.test.js | 5 +++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/3-three/sentences/parse/index.js b/src/3-three/sentences/parse/index.js index 52ecaf5..8c4c936 100644 --- a/src/3-three/sentences/parse/index.js +++ b/src/3-three/sentences/parse/index.js @@ -21,12 +21,24 @@ const parse = function (s) { let subj = s.none() let verb = s.none() let pred = s.none() + // a relative clause right after the subject has a verb of its own + // ('the boy who you saw at the store committed a robbery') + const relative = + chunks.length > 2 && + !chunks.eq(0).has('') && + chunks.eq(1).has('^(who|whom|whose|which|that)$') && + chunks.filter(ch => ch.has('')).length > 1 + let skipped = false chunks.forEach((ch, i) => { if (i === 0 && !ch.has('')) { subj = ch return } if (!verb.found && ch.has('')) { + if (relative && !skipped) { + skipped = true + return + } verb = ch return } diff --git a/tests/three/sentences/svo.test.js b/tests/three/sentences/svo.test.js index e1e3c5b..a8c19b4 100644 --- a/tests/three/sentences/svo.test.js +++ b/tests/three/sentences/svo.test.js @@ -47,10 +47,11 @@ 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'], + ['The man who called yesterday is my uncle.', 'the man', 'is'], // ['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'], - // ['After dripping mustard all over his chest, the man who was wearing a red shirt wished that he had instead chosen ketchup for his hotdog.', 'the man', 'wished'], + ['The boy who you saw at the store committed a robbery.', 'the boy', 'committed'], + ['After dripping mustard all over his chest, the man who was wearing a red shirt wished that he had instead chosen ketchup for his hotdog.', 'the man', 'wished'], // ["please tell me you'll address the issue", 'you', 'will address'], // ['The store that the boy robbed is on the corner.', 'the store', 'is'], ]