update readme, cleaned spec.

This commit is contained in:
moos 2012-05-25 11:09:37 -07:00
parent 7c2a33b05c
commit 8c3ec4ea8a
4 changed files with 47 additions and 72 deletions

View File

@ -38,9 +38,7 @@ To run spec:
## API ## API
Please note: all API are async since the underlying WordNet library is async. Please note: all API are async since the underlying WordNet library is async. WordPOS is a subclass of natural's [WordNet class](https://github.com/NaturalNode/natural#wordnet) and inherits all its methods.
WordPOS is a subclass of natural's [WordNet class](https://github.com/NaturalNode/natural#wordnet) and inherits all its methods.
### getX()... ### getX()...
@ -68,10 +66,8 @@ wordpos.getAdjectives(str, callback) -- callback receives an array of adjectives
wordpos.getAdverbs(str, callback) -- callback receives an array of adverbs in str wordpos.getAdverbs(str, callback) -- callback receives an array of adverbs in str
``` ```
NB: If you're only interested in a certain POS (say, adjectives), using the particular getX() is faster If you're only interested in a certain POS (say, adjectives), using the particular getX() is faster
than getPOS() which looks up the word in all index files. than getPOS() which looks up the word in all index files. [stopwords] (https://github.com/NaturalNode/natural/blob/master/lib/natural/util/stopwords.js)
NB: [stopwords] (https://github.com/NaturalNode/natural/blob/master/lib/natural/util/stopwords.js)
are stripped out from str before lookup. are stripped out from str before lookup.
All getX() functions return the number of parsed words that will be looked up (less duplicates and stopwords). All getX() functions return the number of parsed words that will be looked up (less duplicates and stopwords).
@ -223,7 +219,6 @@ See blog article [Optimizing WordPos](http://blog.42at.com/optimizing-wordpos).
node wordpos-bench.js node wordpos-bench.js
Generally slow as it requires loading and searching large WordNet index files.
512-word corpus (< v0.1.4) : 512-word corpus (< v0.1.4) :
``` ```

View File

@ -18,22 +18,22 @@ var
describe('validate isX() using fastIndex', function() { describe('validate isX() using fastIndex', function() {
it('should validate index.noun', function() { it('should validate index.noun', function() {
exec('node validate index.noun', callback); exec('node ../tools/validate index.noun', callback);
asyncSpecWait(); asyncSpecWait();
}); });
it('should validate index.verb', function() { it('should validate index.verb', function() {
exec('node validate index.verb', callback); exec('node ../tools/validate index.verb', callback);
asyncSpecWait(); asyncSpecWait();
}); });
it('should validate index.adv', function() { it('should validate index.adv', function() {
exec('node validate index.adv', callback); exec('node ../tools/validate index.adv', callback);
asyncSpecWait(); asyncSpecWait();
}); });
it('should validate index.adj', function() { it('should validate index.adj', function() {
exec('node validate index.adj', callback); exec('node ../tools/validate index.adj', callback);
asyncSpecWait(); asyncSpecWait();
}); });

View File

@ -40,145 +40,128 @@ describe('getX()...', function() {
}); });
}); });
it('should get all POS', function() { it('should get all POS', function(done) {
wordpos.getPOS(str, function(result) { wordpos.getPOS(str, function(result) {
expect(result.nouns).toEqualUnordered(expected.nouns); expect(result.nouns).toEqualUnordered(expected.nouns);
expect(result.verbs).toEqualUnordered(expected.verbs); expect(result.verbs).toEqualUnordered(expected.verbs);
expect(result.adjectives).toEqualUnordered(expected.adjectives); expect(result.adjectives).toEqualUnordered(expected.adjectives);
expect(result.adverbs).toEqualUnordered(expected.adverbs); expect(result.adverbs).toEqualUnordered(expected.adverbs);
expect(result.rest).toEqualUnordered(expected.rest); expect(result.rest).toEqualUnordered(expected.rest);
asyncSpecDone(); done();
}); });
asyncSpecWait();
}); });
it('should get nouns', function() { it('should get nouns', function(done) {
wordpos.getNouns(str, function(result) { wordpos.getNouns(str, function(result) {
expect(result).toEqualUnordered(expected.nouns); expect(result).toEqualUnordered(expected.nouns);
asyncSpecDone(); done();
}); });
asyncSpecWait();
}); });
it('should get verbs', function() { it('should get verbs', function(done) {
wordpos.getVerbs(str, function(result) { wordpos.getVerbs(str, function(result) {
expect(result).toEqualUnordered(expected.verbs); expect(result).toEqualUnordered(expected.verbs);
asyncSpecDone(); done();
}); });
asyncSpecWait();
}); });
it('should get adjectives', function() { it('should get adjectives', function(done) {
wordpos.getAdjectives(str, function(result) { wordpos.getAdjectives(str, function(result) {
expect(result).toEqualUnordered(expected.adjectives); expect(result).toEqualUnordered(expected.adjectives);
asyncSpecDone(); done();
}); });
asyncSpecWait();
}); });
it('should get adverbs', function() { it('should get adverbs', function(done) {
wordpos.getAdverbs(str, function(result) { wordpos.getAdverbs(str, function(result) {
expect(result).toEqualUnordered(expected.adverbs); expect(result).toEqualUnordered(expected.adverbs);
asyncSpecDone(); done();
}); });
asyncSpecWait();
}); });
}); });
describe('isX()...', function() { describe('isX()...', function() {
it('should check if noun', function() { it('should check if noun', function(done) {
wordpos.isNoun(expected.nouns[0], function(result) { wordpos.isNoun(expected.nouns[0], function(result) {
expect(result).toBeTruthy(); expect(result).toBeTruthy();
asyncSpecDone(); done();
}); });
asyncSpecWait();
}); });
it('should check if verb', function() { it('should check if verb', function(done) {
wordpos.isVerb(expected.verbs[0], function(result) { wordpos.isVerb(expected.verbs[0], function(result) {
expect(result).toBeTruthy(); expect(result).toBeTruthy();
asyncSpecDone(); done();
}); });
asyncSpecWait();
}); });
it('should check if adjective', function() { it('should check if adjective', function(done) {
wordpos.isAdjective(expected.adjectives[0], function(result) { wordpos.isAdjective(expected.adjectives[0], function(result) {
expect(result).toBeTruthy(); expect(result).toBeTruthy();
asyncSpecDone(); done();
}); });
asyncSpecWait();
}); });
it('should check if adverb', function() { it('should check if adverb', function(done) {
wordpos.isAdverb(expected.adverbs[0], function(result) { wordpos.isAdverb(expected.adverbs[0], function(result) {
expect(result).toBeTruthy(); expect(result).toBeTruthy();
asyncSpecDone(); done();
}); });
asyncSpecWait();
}); });
}); });
describe('!isX()...', function() { describe('!isX()...', function() {
it('should check if !noun', function() { it('should check if !noun', function(done) {
wordpos.isNoun(garble, function(result) { wordpos.isNoun(garble, function(result) {
expect(result).not.toBeTruthy(); expect(result).not.toBeTruthy();
asyncSpecDone(); done();
}); });
asyncSpecWait();
}); });
it('should check if !verb', function() { it('should check if !verb', function(done) {
wordpos.isVerb(garble, function(result) { wordpos.isVerb(garble, function(result) {
expect(result).not.toBeTruthy(); expect(result).not.toBeTruthy();
asyncSpecDone(); done();
}); });
asyncSpecWait();
}); });
it('should check if !adjective', function() { it('should check if !adjective', function(done) {
wordpos.isAdjective(garble, function(result) { wordpos.isAdjective(garble, function(result) {
expect(result).not.toBeTruthy(); expect(result).not.toBeTruthy();
asyncSpecDone(); done();
}); });
asyncSpecWait();
}); });
it('should check if !adverb', function() { it('should check if !adverb', function(done) {
wordpos.isAdverb(garble, function(result) { wordpos.isAdverb(garble, function(result) {
expect(result).not.toBeTruthy(); expect(result).not.toBeTruthy();
asyncSpecDone(); done();
}); });
asyncSpecWait();
}); });
}); });
describe('lookupX()...', function() { describe('lookupX()...', function() {
it('should lookup noun', function() { it('should lookup noun', function(done) {
wordpos.lookupNoun('squirrel', function(result) { wordpos.lookupNoun('squirrel', function(result) {
expect(result[0].pos).toBe('n'); expect(result[0].pos).toBe('n');
expect(result[0].lemma).toBe('squirrel'); expect(result[0].lemma).toBe('squirrel');
asyncSpecDone(); done();
}); });
asyncSpecWait();
}); });
it('should lookup verb', function() { it('should lookup verb', function(done) {
wordpos.lookupVerb('bear', function(result) { wordpos.lookupVerb('bear', function(result) {
expect(result[0].pos).toBe('v'); expect(result[0].pos).toBe('v');
expect(result[0].lemma).toBe('have_a_bun_in_the_oven'); expect(result[0].lemma).toBe('have_a_bun_in_the_oven');
asyncSpecDone(); done();
}); });
asyncSpecWait();
}); });
it('should lookup adjective', function() { it('should lookup adjective', function(done) {
wordpos.lookupAdjective('angry', function(result) { wordpos.lookupAdjective('angry', function(result) {
expect(result[0].pos).toBe('s'); expect(result[0].pos).toBe('s');
expect(result[0].lemma).toBe('angry'); expect(result[0].lemma).toBe('angry');
asyncSpecDone(); done();
}); });
asyncSpecWait();
}); });
it('should lookup adverb', function() { it('should lookup adverb', function(done) {
wordpos.lookupAdverb('little', function(result) { wordpos.lookupAdverb('little', function(result) {
expect(result[0].pos).toBe('r'); expect(result[0].pos).toBe('r');
expect(result[0].lemma).toBe('little'); expect(result[0].lemma).toBe('little');
asyncSpecDone(); done();
}); });
asyncSpecWait();
}); });
}); });
@ -202,29 +185,26 @@ describe('profile option', function() {
var wp = new WordPOS({profile : true}); var wp = new WordPOS({profile : true});
it('should return time argument for isX()', function(){ it('should return time argument for isX()', function(done){
wp.isNoun(garble, function(result, word, time) { wp.isNoun(garble, function(result, word, time) {
expect(word).toEqual(garble); expect(word).toEqual(garble);
expect(time).toBeDefined(); expect(time).toBeDefined();
asyncSpecDone(); done();
}); });
asyncSpecWait();
}); });
it('should return time argument for getX()', function(){ it('should return time argument for getX()', function(done){
wp.getNouns(garble, function(result, time) { wp.getNouns(garble, function(result, time) {
expect(time).toBeDefined(); expect(time).toBeDefined();
asyncSpecDone(); done();
}); });
asyncSpecWait();
}); });
it('should return time argument for lookupX()', function(){ it('should return time argument for lookupX()', function(done){
wp.isNoun(garble, function(result, time) { wp.isNoun(garble, function(result, time) {
expect(time).toBeDefined(); expect(time).toBeDefined();
asyncSpecDone(); done();
}); });
asyncSpecWait();
}); });
}); });