From 59098d75c74c062e4c07673065e3fae66180936e Mon Sep 17 00:00:00 2001 From: dualfroz Date: Fri, 2 Oct 2026 16:10:32 +0200 Subject: [PATCH] Contract 'can not' to can't, and 'did not' and 'were not' too --- src/2-two/contraction-two/api/contract.js | 5 ++++- tests/two/contractions/contract.test.js | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/2-two/contraction-two/api/contract.js b/src/2-two/contraction-two/api/contract.js index c697bf7..e9e93c2 100644 --- a/src/2-two/contraction-two/api/contract.js +++ b/src/2-two/contraction-two/api/contract.js @@ -46,8 +46,11 @@ const contract = function () { m = doc.match('#Person would') setContraction(m, `'d`) // would not -> wouldn't - m = doc.match('(is|was|had|would|should|could|do|does|have|has|can) not') + m = doc.match('(is|was|were|had|would|should|could|do|does|did|have|has) not') setContraction(m, `n't`) + // can not -> can't + m = doc.match('can not') + setContraction(m, `'t`) // i have -> i've m = doc.match('(i|we|they) have') setContraction(m, `'ve`) diff --git a/tests/two/contractions/contract.test.js b/tests/two/contractions/contract.test.js index 79f153b..fe64afb 100644 --- a/tests/two/contractions/contract.test.js +++ b/tests/two/contractions/contract.test.js @@ -74,3 +74,20 @@ test('multiple contraction in sentence', function (t) { t.equal(doc.match('he is dead').length, 2, here + 'multi-contraction-count') t.end() }) + +test('contract negatives', function (t) { + const arr = [ + ['I can not go', `I can't go`], + ['You Can not go', `You Can't go`], + ['i did not go', `i didn't go`], + ['they were not here', `they weren't here`], + ] + arr.forEach(a => { + const doc = nlp(a[0]) + doc.contract() + t.equal(doc.text(), a[1], here + a[0]) + doc.contractions().expand() + t.equal(doc.text(), a[0], here + 'expand ' + a[0]) + }) + t.end() +})