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 apostropheT from './apostrophe-t.js'
import isPossessive from './isPossessive.js'
import wannaNoun from './wanna.js'
const byApostrophe = /'/
@@ -61,6 +62,10 @@ const contractionTwo = view => {
document.forEach((terms, n) => {
// loop through terms backwards
for (let i = terms.length - 1; i >= 0; i -= 1) {
if (wannaNoun(terms, i)) {
reIndex(terms)
continue
}
// is it already a contraction
if (terms[i].implicit) {
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