/
toNegative.js
60 lines (53 loc) · 1.74 KB
/
toNegative.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'use strict';
//turns a verb negative - may not have enough information to do it properly
// (eg 'did not eat' vs 'does not eat') - needs the noun
const toInfinitive = require('./methods/toInfinitive');
const toNegative = (ts, plural) => {
//would not walk
let modal = ts.match('#Auxillary').first(); //.notIf('(is|are|was|will|has|had)').first(); //.first();
if (modal.found) {
let index = modal.list[0].index();
return ts.parentTerms.insertAt(index + 1, 'not', 'Verb');
}
//is not
let copula = ts.match('(#Copula|will|has|had)').first();
if (copula.found) {
let index = copula.list[0].index();
return ts.parentTerms.insertAt(index + 1, 'not', 'Verb');
}
//walked -> did not walk
let past = ts.match('#PastTense').last();
if (past.found) {
let vb = past.list[0];
let index = vb.index();
vb.terms[0].text = toInfinitive(vb.terms[0]);
return ts.parentTerms.insertAt(index, 'did not', 'Verb');
}
//walks -> does not walk
let pres = ts.match('#PresentTense').last();
if (pres.found) {
let vb = pres.list[0];
let index = vb.index();
vb.terms[0].text = toInfinitive(vb.terms[0]);
return ts.parentTerms.insertAt(index, 'does not', 'Verb');
}
//not walking
let gerund = ts.match('#Gerund').last();
if (gerund.found) {
let index = gerund.list[0].index();
return ts.parentTerms.insertAt(index, 'not', 'Verb');
}
//walk -> do not walk
let vb = ts.match('#Verb').last();
if (vb.found) {
vb = vb.list[0];
let index = vb.index();
vb.terms[0].text = toInfinitive(vb.terms[0]);
if (plural) {
return ts.parentTerms.insertAt(index, 'does not', 'Verb');
}
return ts.parentTerms.insertAt(index, 'did not', 'Verb');
}
return ts;
};
module.exports = toNegative;