Drop does/did when turning a negative verb positive

This commit is contained in:
dualfroz committed 2026-10-03 03:15:27 +02:00
1 parent 8124553282
commit 8fd9ece28a
3 files changed
+51

No files matched your search

+11
View File
@@ -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) {
@@ -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()
})
@@ -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()
})