/
sentence.js
87 lines (82 loc) · 1.94 KB
/
sentence.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
'use strict';
const Terms = require('../../paths').Terms;
const toNegative = require('./toNegative');
const Verb = require('../verbs/verb');
class Sentence extends Terms {
constructor(arr, lexicon, refText, refTerms) {
super(arr, lexicon, refText, refTerms);
}
data() {
return {
text: this.out('text'),
normal: this.out('normal')
};
}
/** inflect the main/first noun*/
toSingular() {
let nouns = this.match('#Noun').match('!#Pronoun').firstTerm();
nouns.things().toSingular();
return this;
}
toPlural() {
let nouns = this.match('#Noun').match('!#Pronoun').firstTerm();
nouns.things().toPlural();
return this;
}
//returns a Term object
mainVerb() {
let terms = this.match('(#Verb|#Auxillary|#Adverb|#Particle)+').list[0].terms;
return new Verb(terms, this.lexicon, this.refText, this.refTerms);
}
/** sentence tense conversion**/
toPastTense() {
let verb = this.mainVerb();
if (verb) {
verb.toPastTense();
}
return this;
}
toPresentTense() {
let verb = this.mainVerb();
if (verb) {
verb.toPresentTense();
}
return this;
}
toFutureTense() {
let verb = this.mainVerb();
if (verb) {
verb.toFutureTense();
}
return this;
}
/** negation **/
isNegative() {
return this.match('#Negative').list.length === 1;
}
/** negate the main/first copula*/
toNegative() {
if (this.isNegative()) {
return this;
}
return toNegative(this);
}
toPositive() {
this.match('#Negative').first().remove();
return this;
}
setPunctuation(punct) {
let last = this.terms[this.terms.length - 1];
last.setPunctuation(punct);
}
getPunctuation() {
let last = this.terms[this.terms.length - 1];
return last.getPunctuation();
}
/** look for 'was _ by' patterns */
isPassive() {
//haha
return this.match('was #Adverb? #PastTense #Adverb? by').found;
}
}
module.exports = Sentence;