Skip to content

Commit

Permalink
verb methods moved-over
Browse files Browse the repository at this point in the history
  • Loading branch information
spencermountain committed Feb 2, 2017
1 parent 8fc8f0f commit 9055635
Show file tree
Hide file tree
Showing 29 changed files with 44 additions and 58 deletions.
2 changes: 1 addition & 1 deletion scratch_file.js
Expand Up @@ -14,4 +14,4 @@ const nlp = require('./src/index');
console.log('------');
var m = nlp('he ate the alligator');
// m.insertAt(2, 'fun');
console.log(m.nouns().data());
console.log(m.verbs().toPastTense().data());
5 changes: 2 additions & 3 deletions src/data/lexicon.js
Expand Up @@ -3,10 +3,10 @@
//the way we make it rn is a bit of a mess.
const data = require('./index');
const fns = require('./fns');
const fastConjugate = require('../term/verb/conjugate/faster');
const toPlural = require('../result/subset/nouns/methods/pluralize');
const adj = require('../result/subset/adjectives/methods/index');
const toAdjective = require('../term/verb/toAdjective');
const toAdjective = require('../result/subset/verbs/methods/toAdjective');
const fastConjugate = require('../result/subset/verbs/methods/conjugate/faster');
let lexicon = {};
// console.time('lexicon');

Expand Down Expand Up @@ -136,5 +136,4 @@ module.exports = lexicon;
// console.log(lexicon['will walk']);
// let t = new Term('shake');
// t.tag.Verb = true;
// console.log(t.verb.conjugate())
// console.timeEnd('lexicon');
1 change: 1 addition & 0 deletions src/result/subset/adjectives/methods/convertable.js
@@ -1,6 +1,7 @@
'use strict';
//an obj of adjectives that can be converted to superlative + comparative, via the lexicon data
const data = require('../../../../data');

const convertables = {};
data.superlatives.forEach((a) => {
convertables[a] = true;
Expand Down
6 changes: 3 additions & 3 deletions src/result/subset/sentences/sentence.js
Expand Up @@ -35,21 +35,21 @@ class Sentence extends Terms {
toPastTense() {
let verb = this.mainVerb();
if (verb) {
verb.verb.toPastTense();
verb.toPastTense();
}
return this;
}
toPresentTense() {
let verb = this.mainVerb();
if (verb) {
verb.verb.toPresentTense();
verb.toPresentTense();
}
return this;
}
toFutureTense() {
let verb = this.mainVerb();
if (verb) {
verb.verb.toFutureTense();
verb.toFutureTense();
}
return this;
}
Expand Down
8 changes: 0 additions & 8 deletions src/result/subset/verbs/conjugate.js

This file was deleted.

7 changes: 2 additions & 5 deletions src/result/subset/verbs/index.js
Expand Up @@ -66,11 +66,8 @@ class Verbs extends Text {
});
return this;
}
toAdjective() {
this.list.forEach((ts) => {
ts.toAdjective();
});
return this;
asAdjective() {
return this.list.map((ts) => ts.asAdjective());
}

static find(r, n) {
Expand Down
10 changes: 5 additions & 5 deletions src/result/subset/verbs/interpret.js
@@ -1,4 +1,5 @@
'use strict';
const predict = require('./methods/predict');

//'walking' - aka progressive
const isContinuous = function(ts) {
Expand Down Expand Up @@ -65,14 +66,13 @@ const getTense = function(ts) {
}
}
//look at the main verb tense
if (ts.verb.list[0] && ts.verb.list[0].terms[0]) {
if (ts.verb) {
const tenses = {
PastTense: 'Past',
FutureTense: 'Future',
FuturePerfect: 'Future',
};
let t = ts.verb.list[0].terms[0];
let tense = t.verb.conjugation(); //yikes
let tense = predict(ts.verb); //yikes
return tenses[tense] || 'Present';
}
return 'Present';
Expand All @@ -83,7 +83,7 @@ const getTense = function(ts) {

// detect signals in auxillary verbs
// 'will' -> future, 'have'->perfect, modals, negatives, adverbs
const predict = (ts) => {
const interpret = (ts) => {
let isNeg = isNegative(ts);
// let aux = ts.auxillary.clone();
// aux = aux.not('(#Negative|#Adverb)');
Expand All @@ -97,4 +97,4 @@ const predict = (ts) => {
};
return obj;
};
module.exports = predict;
module.exports = interpret;
File renamed without changes.
File renamed without changes.
@@ -1,6 +1,6 @@
'use strict';
//non-specifc, 'hail-mary' transforms from infinitive, into other forms
const fns = require('./paths').fns;
const fns = require('../../../../../fns'); //jaja!

const generic = {

Expand Down
Expand Up @@ -4,6 +4,8 @@ const suffixPass = require('./suffixes');
const toActor = require('./toActor');
const toAdjective = require('./toAdjective');
const generic = require('./generic');
const predict = require('../predict');
const toInfinitive = require('../toInfinitive');

//turn a verb into all it's forms
const conjugate = function(t, verbose) {
Expand All @@ -22,12 +24,12 @@ const conjugate = function(t, verbose) {
Pluperfect: null,
};
//first, get its current form
let form = t.verb.conjugation(verbose);
let form = predict(t);
if (form) {
all[form] = t.normal;
}
if (form !== 'Infinitive') {
all['Infinitive'] = t.verb.infinitive(verbose) || '';
all['Infinitive'] = toInfinitive(t, verbose) || '';
}
//check irregular forms
const irregObj = checkIrregulars(all['Infinitive']) || {};
Expand Down
@@ -1,5 +1,5 @@
'use strict';
const irregulars = require('./paths').data.irregular_verbs;
const irregulars = require('../../../../../data').irregular_verbs;
const infArr = Object.keys(irregulars);
const forms = [
'Participle',
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions src/result/subset/verbs/methods/paths.js
@@ -0,0 +1 @@
module.exports = require('../../../paths');
@@ -1,6 +1,5 @@
'use strict';
const paths = require('../paths');
const fns = paths.fns;
const fns = require('../../../../../fns'); //jaja!
const suffix_rules = require('./suffix_rules');

const goodTypes = {
Expand Down
File renamed without changes.
File renamed without changes.
@@ -1,7 +1,8 @@
'use strict';
//turn any verb into its infinitive form
const rules = require('./rules');
let irregulars = require('../paths').data.irregular_verbs;
let irregulars = require('../../../../../data').irregular_verbs;
const predict = require('../predict');

//map the irregulars for easy infinitive lookup
// {bought: 'buy'}
Expand All @@ -25,7 +26,7 @@ const toInfinitive = function(t) {
return irregulars[t.normal];
}
//check the suffix rules
let form = t.verb.conjugation();
let form = predict(t);
if (rules[form]) {
for (let i = 0; i < rules[form].length; i++) {
let rule = rules[form][i];
Expand Down
File renamed without changes.
8 changes: 5 additions & 3 deletions src/result/subset/verbs/toNegative.js
@@ -1,6 +1,8 @@
'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();
Expand All @@ -21,7 +23,7 @@ const toNegative = (ts, plural) => {
if (past.found) {
let vb = past.list[0];
let index = vb.index();
vb.terms[0].text = vb.terms[0].verb.infinitive();
vb.terms[0].text = toInfinitive(vb.terms[0]);
return ts.parentTerms.insertAt(index, 'did not', 'Verb');
}

Expand All @@ -30,7 +32,7 @@ const toNegative = (ts, plural) => {
if (pres.found) {
let vb = pres.list[0];
let index = vb.index();
vb.terms[0].text = vb.terms[0].verb.infinitive();
vb.terms[0].text = toInfinitive(vb.terms[0]);
return ts.parentTerms.insertAt(index, 'does not', 'Verb');
}

Expand All @@ -46,7 +48,7 @@ const toNegative = (ts, plural) => {
if (vb.found) {
vb = vb.list[0];
let index = vb.index();
vb.terms[0].text = vb.terms[0].verb.infinitive();
vb.terms[0].text = toInfinitive(vb.terms[0]);
if (plural) {
return ts.parentTerms.insertAt(index, 'does not', 'Verb');
}
Expand Down
19 changes: 10 additions & 9 deletions src/result/subset/verbs/verb.js
@@ -1,6 +1,7 @@
'use strict';
const Terms = require('../../paths').Terms;
const conjugate = require('./conjugate');
const conjugate = require('./methods/conjugate');
const toAdjective = require('./methods/toAdjective');
const interpret = require('./interpret');
const toNegative = require('./toNegative');

Expand All @@ -10,7 +11,7 @@ class Verb extends Terms {
this.negative = this.match('#Negative');
this.adverbs = this.match('#Adverb');
let aux = this.clone().not('(#Adverb|#Negative)');
this.verb = aux.match('#Verb').last();
this.verb = aux.match('#Verb').last().list[0].terms[0];
this.auxillary = aux.match('#Auxillary+');
}
data(debug) {
Expand All @@ -24,12 +25,12 @@ class Verb extends Terms {
adverbs: this.adverbs.out('normal'),
},
interpret: interpret(this, debug),
conjugations: conjugate(this, debug)
conjugations: conjugate(this.verb, debug)
};
}

conjugate(debug) {
return conjugate(this, debug);
return conjugate(this.verb, debug);
}

/** negation **/
Expand All @@ -51,15 +52,15 @@ class Verb extends Terms {

/** conjugation **/
toPastTense() {
let obj = conjugate(this);
let obj = conjugate(this.verb);
return this.replaceWith(obj.PastTense);
}
toPresentTense() {
let obj = conjugate(this);
let obj = conjugate(this.verb);
return this.replaceWith(obj.Infinitive);
}
toFutureTense() {
let obj = conjugate(this);
let obj = conjugate(this.verb);
return this.replaceWith(obj.FutureTense);
}
toInfinitive() {
Expand All @@ -69,8 +70,8 @@ class Verb extends Terms {
return this;
}

toAdjective() {
return this;
asAdjective() {
return toAdjective(this.verb.out('normal'));
}

}
Expand Down
9 changes: 0 additions & 9 deletions src/term/index.js
Expand Up @@ -2,13 +2,6 @@
const fns = require('./paths').fns;
const build_whitespace = require('./whitespace');

const bindMethods = (o, str, self) => {
self[str] = {};
Object.keys(o).forEach((fn) => {
self[str][fn] = o[fn].bind(self);
});
};

class Term {
constructor(str) {
this._text = fns.ensureString(str);
Expand All @@ -21,8 +14,6 @@ class Term {
this.silent_term = '';
//has this term been modified
this.dirty = false;

bindMethods(require('./verb'), 'verb', this);
this.normalize();
}

Expand Down
1 change: 0 additions & 1 deletion src/term/verb/conjugate/paths.js

This file was deleted.

1 change: 0 additions & 1 deletion src/term/verb/paths.js

This file was deleted.

4 changes: 3 additions & 1 deletion src/terms/tagger/steps/12-phrasal_step.js
@@ -1,6 +1,8 @@
'use strict';
const log = require('../paths').log;
const phrasals = require('./data/phrasal_verbs');
const toInfinitive = require('../../../result/subset/verbs/methods/toInfinitive/index.js');

const path = 'tagger/phrasal';

//words that could be particles
Expand Down Expand Up @@ -42,7 +44,7 @@ const phrasals_step = function(ts) {
//look backwards
let last = ts.get(i - 1);
if (last.tag.Verb) {
let inf = last.verb.infinitive();
let inf = toInfinitive(last);
if (phrasals[inf + ' ' + t.normal]) {
t.tagAs('Particle', 'phrasalVerb-particle');
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/verb/to_adjective.test.js
Expand Up @@ -9,7 +9,7 @@ test('verb-to-adjective:', function(t) {
['convert', 'convertible'],
['see', 'visible'],
].forEach(function(a) {
var str = nlp(a[0]).list[0].terms[0].verb.asAdjective();
var str = nlp(a[0]).verbs().asAdjective()[0];
t.equal(str, a[1], str + ' -> ' + a[1]);
});
t.end();
Expand Down

0 comments on commit 9055635

Please sign in to comment.