UNPKG

compromise

Version:

modest natural language processing

62 lines (61 loc) • 1.71 kB
import question from '../../verbs/api/conjugate/question.js' import { firstGroup } from '../../verbs/api/conjugate/coordinate.js' const toFuture = function (s) { const inverted = question(s, 'future') if (inverted) return inverted let verbs = s.verbs() // translate the first verb, no-stress const first = firstGroup(verbs) first.toFutureTense() s = s.fullSentence() verbs = s.verbs()//re-do it // verbs.debug() // force agreement with any 2nd/3rd verbs: if (verbs.length > 1) { verbs = verbs.slice(first.length) // which following-verbs should we also change? const toChange = verbs.filter((vb) => { // remove any sorta infinitive - 'to engage' if (vb.lookBehind('to$').found) { return false } // is watching if (vb.has('#Cop #Ger')) { return true } // keep -ing verbs if (vb.has('#Ger')) { return false } // he is green and he is friendly if (vb.has('#Cop')) { return true } // 'he will see when he watches' if (vb.has('#Pres') && !vb.has('#Inf') && vb.lookBefore('(he|she|it|that|which)$').found) { return false } return true }) // otherwise, change em too if (toChange.found) { toChange.forEach(m => { //extra rules for 'is' if (m.has('#Cop')) { // when he was out.. m.match('was').replaceWith('is') // when he is out m.match('is').replaceWith('will be') return } // if (m.has('#PastTense')) { // m.toPresentTense() // return // } m.toInfinitive() }) } } return s } export default toFuture