Skip to content

Commit

Permalink
move tests around
Browse files Browse the repository at this point in the history
  • Loading branch information
spencermountain committed Feb 3, 2017
1 parent 9055635 commit 4bf247a
Show file tree
Hide file tree
Showing 58 changed files with 159 additions and 173 deletions.
3 changes: 1 addition & 2 deletions .esformatter
@@ -1,7 +1,6 @@
{
"plugins": [
"esformatter-quotes",
"esformatter-parseint",
"esformatter-braces",
"esformatter-semicolons"
],
Expand Down Expand Up @@ -31,4 +30,4 @@
"EndOfFile": 1
}
}
}
}
9 changes: 5 additions & 4 deletions scratch_file.js
Expand Up @@ -10,8 +10,9 @@ const nlp = require('./src/index');
//bug 2. - gerund as nouns
// nlp('i like running').sentences().toNegative().check();


console.log('------');
var m = nlp('he ate the alligator');
// m.insertAt(2, 'fun');
console.log(m.verbs().toPastTense().data());
var neg = m.clone().sentences().toNegative();
var past = m.clone().sentences().toPastTense();
var pres = m.clone().sentences().toPresentTense();
var adv = m.clone().verbs().insertBefore('really');
console.log(m.out());
2 changes: 1 addition & 1 deletion scripts/test.js
Expand Up @@ -3,7 +3,7 @@ var tape = './node_modules/tape/bin/tape';
var tapSpec = './node_modules/tap-spec/bin/cmd.js --color';

//run tests server-side
exec(tape + ' ./test/unit/**/*.test.js | ' + tapSpec);
exec(tape + ' \'./test/unit/**/*.test.js\' | ' + tapSpec);

//do code-coverage too
// var nyc = './node_modules/nyc/bin/nyc.js';
Expand Down
5 changes: 1 addition & 4 deletions src/result/index.js
@@ -1,5 +1,4 @@
'use strict';
const out = require('./methods/out');
//a Text is an array of termLists
class Text {
constructor(arr, lexicon, reference) {
Expand Down Expand Up @@ -42,9 +41,6 @@ class Text {
check(opts) {
return out(this, 'check', opts);
}
out(msg, opts) {
return out(this, msg, opts);
}
get whitespace() {
return {
before: (str) => {
Expand All @@ -66,6 +62,7 @@ class Text {
module.exports = Text;
Text = require('./methods/loops')(Text);
Text = require('./methods/array')(Text);
Text = require('./methods/out')(Text);
Text = require('./methods/termFns')(Text);
Text = require('./methods/tag')(Text);
Text = require('./methods/sort')(Text);
Expand Down
3 changes: 3 additions & 0 deletions src/result/methods/loops.js
Expand Up @@ -17,6 +17,9 @@ let foreach = [
'replaceWith',

'delete',

// 'tag',
// 'unTag',
];

const addMethods = (Text) => {
Expand Down
77 changes: 42 additions & 35 deletions src/result/methods/out/index.js
Expand Up @@ -3,7 +3,7 @@ const ngram = require('./ngram');
const edgegram = require('./edgegram');
const topk = require('./topk');

const render = {
const methods = {
text: (r) => {
return r.list.reduce((str, ts) => {
str += ts.out('text');
Expand Down Expand Up @@ -45,7 +45,7 @@ const render = {
html: (r) => {
let html = r.list.reduce((str, ts) => {
let sentence = ts.terms.reduce((sen, t) => {
sen += '\n ' + t.render.html();
sen += '\n ' + t.methods.html();
return sen;
}, '');
return str += '\n <span>' + sentence + '\n </span>';
Expand Down Expand Up @@ -77,38 +77,45 @@ const render = {
return topk(r);
}
};
render.plaintext = render.text;
render.normalized = render.normal;
render.debug = render.check;
render.freq = render.topk;
render.frequency = render.topk;
methods.plaintext = methods.text;
methods.normalized = methods.normal;
methods.debug = methods.check;
methods.freq = methods.topk;
methods.frequency = methods.topk;

//render/output fns
const out = (r, fn, opts) => {
if (render[fn]) {
return render[fn](r);
}
if (fn === 'bigram') {
opts = opts || {
size: [2]
};
return ngram(r, opts);
}
if (fn === 'trigram') {
opts = opts || {
size: [3]
};
return ngram(r, opts);
}
if (fn === 'edgegram') {
return edgegram.both(r, opts);
}
if (fn === 'startgram') {
return edgegram.start(r, opts);
}
if (fn === 'endgram') {
return edgegram.end(r, opts);
}
return render.text(r);
const addMethods = (Text) => {
Text.prototype.check = function() {
return methods.check(this);
};
Text.prototype.out = function(fn, opts) {
if (methods[fn]) {
return methods[fn](this);
}
if (fn === 'bigram') {
opts = opts || {
size: [2]
};
return ngram(this, opts);
}
if (fn === 'trigram') {
opts = opts || {
size: [3]
};
return ngram(this, opts);
}
if (fn === 'edgegram') {
return edgegram.both(this, opts);
}
if (fn === 'startgram') {
return edgegram.start(this, opts);
}
if (fn === 'endgram') {
return edgegram.end(this, opts);
}
return methods.text(this);
};
return Text;
};
module.exports = out;


module.exports = addMethods;
3 changes: 3 additions & 0 deletions src/result/subset/people/index.js
Expand Up @@ -7,6 +7,9 @@ class People extends Text {
data() {
return this.list.map((ts) => ts.data());
}
pronoun() {
return this.list.map((ts) => ts.pronoun());
}
static find(r, n) {
let people = r.clauses();
people = people.match('#Person+');
Expand Down
11 changes: 11 additions & 0 deletions src/result/subset/people/person.js
Expand Up @@ -12,6 +12,7 @@ class Person extends Terms {
middleName: this.middleName.out('normal'),
lastName: this.lastName.out('normal'),
genderGuess: this.guessGender(),
pronoun: this.pronoun(),
honorifics: this.honorifics.out('array')
};
}
Expand Down Expand Up @@ -53,6 +54,16 @@ class Person extends Terms {
//look-for regex clues
return guessGender(this.firstName.out('normal'));
}
pronoun() {
let g = this.guessGender();
if (g === 'Male') {
return 'he';
}
if (g === 'Female') {
return 'she';
}
return 'they';
}
root() {
let first = this.firstName.out('root');
let last = this.lastName.out('root');
Expand Down
9 changes: 6 additions & 3 deletions src/terms/methods/out.js
Expand Up @@ -25,6 +25,11 @@ const methods = {

html: function (ts) {
return ts.terms.map((t) => t.render.html()).join(' ');
},
check: function(ts) {
ts.terms.forEach((t) => {
t.out('check');
});
}
};
methods.plaintext = methods.text;
Expand All @@ -42,9 +47,7 @@ const renderMethods = (Terms) => {
};
//check method
Terms.prototype.check = function () {
this.terms.forEach((t) => {
t.render.check();
});
return methods.check(this);
};
return Terms;
};
Expand Down
32 changes: 0 additions & 32 deletions test/leak/index.html

This file was deleted.

6 changes: 0 additions & 6 deletions test/unit/lexicon/tricky.test.js
@@ -1,17 +1,11 @@
var test = require('tape');
var nlp = require('../lib/nlp');



var lexicon = {
'Jardas al Abid': 'Place',
'Umm Ar Rizam': 'Place',
'Tobruk': 'Place'
};
// var sentence = 'A suicide attack hit the centre of Tobruk killing one person (and the attacker) and injuring more than twenty.';
// var found = nlp(sentence).places().data()[0];
// console.log('Problem#1. Test to find locality in English without lexicon.');
// t.equal('Tobruk', found);

test('find locality which has hyphenation:', function (t) {
sentence = 'A suicide attack hit the centre of Jardas-al-Abid killing one person (and the attacker) and injuring more than twenty.';
Expand Down
File renamed without changes.
@@ -1,5 +1,5 @@
var test = require('tape');
var nlp = require('../lib/nlp');
var nlp = require('../../lib/nlp');
var terms_test = (r, arr, t) => {
var have = r.out('array').join(' - ');
arr = arr.join(' - ');
Expand Down
2 changes: 1 addition & 1 deletion test/unit/result/misc.test.js → test/unit/misc.test.js
@@ -1,5 +1,5 @@
var test = require('tape');
var nlp = require('../lib/nlp');
var nlp = require('./lib/nlp');

var garbage = [
'',
Expand Down
27 changes: 0 additions & 27 deletions test/unit/noun/pronoun.ignore.js

This file was deleted.

File renamed without changes.
File renamed without changes.
@@ -1,6 +1,6 @@
var test = require('tape');
var nlp = require('../lib/nlp');
var str_test = require('../lib/fns').str_test;
var nlp = require('../../lib/nlp');
var str_test = require('../../lib/fns').str_test;

test('==Adjective==', function (T) {

Expand Down
@@ -1,5 +1,5 @@
var test = require('tape');
var nlp = require('../lib/nlp');
var nlp = require('../../lib/nlp');

test('==Adverb==', function (T) {

Expand Down
File renamed without changes.
@@ -1,5 +1,5 @@
var test = require('tape');
var nlp = require('../lib/nlp');
var nlp = require('../../lib/nlp');

test('basic is contractions', function(t) {
var r = nlp(`he is cool.`);
Expand Down
@@ -1,6 +1,6 @@
var test = require('tape');
var nlp = require('../lib/nlp');
var str_test = require('../lib/fns').str_test;
var nlp = require('../../lib/nlp');
var str_test = require('../../lib/fns').str_test;

test('==contractions==', function(T) {

Expand Down
@@ -1,6 +1,6 @@
var test = require('tape');
var nlp = require('./lib/nlp');
var str_test = require('./lib/fns').str_test;
var nlp = require('../..b/nlp');
var str_test = require('../..b/fns').str_test;


test('date-parse :', function(t) {
Expand Down
@@ -1,5 +1,5 @@
var test = require('tape');
var nlp = require('../lib/nlp');
var nlp = require('../../lib/nlp');

let file = '';
if (typeof __filename !== 'undefined') {
Expand Down
@@ -1,5 +1,5 @@
var test = require('tape');
var nlp = require('../lib/nlp');
var nlp = require('../../lib/nlp');


test('one big dates', function (t) {
Expand Down
@@ -1,6 +1,6 @@
var test = require('tape');
var nlp = require('../lib/nlp');
var str_test = require('../lib/fns').str_test;
var nlp = require('../../lib/nlp');
var str_test = require('../../lib/fns').str_test;

test('.article():', function(t) {
[
Expand Down
@@ -1,6 +1,6 @@
var test = require('tape');
var nlp = require('../lib/nlp');
var str_test = require('../lib/fns').str_test;
var nlp = require('../../lib/nlp');
var str_test = require('../../lib/fns').str_test;

test('==Plurals==', function(T) {

Expand Down

0 comments on commit 4bf247a

Please sign in to comment.