diff --git a/src/3-three/verbs/api/api.js b/src/3-three/verbs/api/api.js index 2cfd367..7aa8d96 100644 --- a/src/3-three/verbs/api/api.js +++ b/src/3-three/verbs/api/api.js @@ -12,6 +12,8 @@ import getSubject from './parse/getSubject.js' import getGrammar from './parse/grammar/index.js' import toNegative from './conjugate/toNegative.js' import { getTense } from './lib.js' +import { inflect } from './conjugate/inflect.js' +const keep = { tags: true } const api = function (View) { @@ -146,6 +148,15 @@ const api = function (View) { if (m.found) { m.remove('do not') } + // 'does not walk' -> 'walks' + this.forEach(vb => { + const { root, auxiliary, negative } = parseVerb(vb) + if (negative.found && auxiliary.has('^(does|did)$')) { + const tense = auxiliary.has('did') ? 'PastTense' : 'PresentTense' + vb.replace(root, inflect(root, tense), keep).unTag('Infinitive').tag(tense) + vb.remove(auxiliary) + } + }) return this.remove('#Negative') } toNegative(n) { diff --git a/tests/three/sentences/negative-sentences.test.js b/tests/three/sentences/negative-sentences.test.js index a9fed99..96847e1 100644 --- a/tests/three/sentences/negative-sentences.test.js +++ b/tests/three/sentences/negative-sentences.test.js @@ -12,3 +12,13 @@ test('sentences.toPositive', function (t) { t.end() }) + +test('sentences.toPositive does-not', function (t) { + const doc = nlp(`He does not like camels.`) + doc.sentences().toPositive() + t.equal(doc.text(), 'He likes camels.', here + 'does not') + + doc.sentences().toNegative() + t.equal(doc.text(), 'He does not like camels.', here + 'back to neg') + t.end() +}) diff --git a/tests/three/verbs/negation/to-positive.test.js b/tests/three/verbs/negation/to-positive.test.js new file mode 100644 index 0000000..0868a4a --- /dev/null +++ b/tests/three/verbs/negation/to-positive.test.js @@ -0,0 +1,30 @@ +import test from 'tape' +import nlp from '../../_lib.js' +const here = '[three/verb-toPositive] ' + +test('inline verb toPositive:', function (t) { + const arr = [ + [`he does not like camels`, 'he likes camels'], + [`he did not like camels`, 'he liked camels'], + [`he doesn't like camels`, 'he likes camels'], + [`she didn't go home`, 'she went home'], + [`it does not matter`, 'it matters'], + [`he does not have a car`, 'he has a car'], + [`he does not really like camels`, 'he really likes camels'], + [`spencer did not walk`, 'spencer walked'], + // already worked + [`they do not like camels`, 'they like camels'], + [`i do not like camels`, 'i like camels'], + [`do not use reverse psychology`, 'use reverse psychology'], + [`he is not cool`, 'he is cool'], + [`he will not go`, 'he will go'], + [`he has not eaten`, 'he has eaten'], + ] + arr.forEach(function (a) { + const doc = nlp(a[0]) + doc.verbs().toPositive() + const str = doc.text('normal') + t.equal(str, a[1], here + a[1] + ' --- ' + str) + }) + t.end() +})