Don't add an implicit 'to' after 'wanna' when a noun follows

This commit is contained in:
dualfroz committed 2026-10-03 01:05:43 +02:00
1 parent 2f6cf3b20d
commit fd61e5bc5a
3 files changed
+45

No files matched your search

@@ -3,6 +3,7 @@ import apostropheS from './apostrophe-s.js'
import apostropheD from './apostrophe-d.js' import apostropheD from './apostrophe-d.js'
import apostropheT from './apostrophe-t.js' import apostropheT from './apostrophe-t.js'
import isPossessive from './isPossessive.js' import isPossessive from './isPossessive.js'
import wannaNoun from './wanna.js'
const byApostrophe = /'/ const byApostrophe = /'/
@@ -61,6 +62,10 @@ const contractionTwo = view => {
document.forEach((terms, n) => { document.forEach((terms, n) => {
// loop through terms backwards // loop through terms backwards
for (let i = terms.length - 1; i >= 0; i -= 1) { for (let i = terms.length - 1; i >= 0; i -= 1) {
if (wannaNoun(terms, i)) {
reIndex(terms)
continue
}
// is it already a contraction // is it already a contraction
if (terms[i].implicit) { if (terms[i].implicit) {
continue continue
@@ -0,0 +1,24 @@
// 'i wanna pickle' is [want, pickle], not [want, to, pickle]
const hasObject = term => term && ['Determiner', 'Pronoun', 'Possessive'].some(tag => term.tags.has(tag))
const wannaNoun = function (terms, i) {
if (terms[i].normal !== 'wanna') {
return false
}
const to = terms[i + 1]
const next = terms[i + 2]
if (!to || to.implicit !== 'to' || !next) {
return false
}
if (next.tags.has('Verb') || next.tags.has('Adverb')) {
return false
}
// 'wanna pickle the beets' is still a verb, before its object
if (hasObject(terms[i + 3])) {
return false
}
terms[i].post = to.post
terms.splice(i + 1, 1)
return true
}
export default wannaNoun
+16
View File
@@ -33,6 +33,22 @@ test('basic is contractions', function (t) {
t.end() t.end()
}) })
test('wanna before a noun', function (t) {
const arr = [
['I wanna pickle', 'I want pickle'],
['I wanna a cookie', 'I want a cookie'],
['do you wanna coffee?', 'do you want coffee?'],
['I wanna go', 'I want to go'],
['I wanna pickle some beets', 'I want to pickle some beets'],
]
arr.forEach(([str, want]) => {
const r = nlp(str)
r.contractions().expand()
t.equal(r.text(), want, here + str)
})
t.end()
})
test('do-not contractions', function (t) { test('do-not contractions', function (t) {
let r = nlp(`please do not eat the marshmellow`) let r = nlp(`please do not eat the marshmellow`)
r.contractions().expand() r.contractions().expand()