2012-05-04 19:23:28 +00:00
|
|
|
// npm install jasmine-node -g
|
|
|
|
// jasmine-node wordpos_spec.js --verbose
|
|
|
|
|
|
|
|
/* Note: 'dict' folder should contain WordNet files.
|
|
|
|
* Download and unpack manually from http://wordnet.princeton.edu/wordnet/download/current-version/
|
|
|
|
*/
|
2012-05-02 23:18:10 +00:00
|
|
|
|
|
|
|
var WordPOS = require('./wordpos'),
|
2012-05-06 09:44:21 +00:00
|
|
|
wordpos = new WordPOS();
|
2012-05-02 23:18:10 +00:00
|
|
|
|
|
|
|
var str = "The angry bear chased the frightened little squirrel",
|
2012-05-04 19:23:28 +00:00
|
|
|
expected = {
|
|
|
|
nouns: [ 'bear', 'squirrel', 'little', 'chased' ],
|
|
|
|
verbs: [ 'bear' ],
|
|
|
|
adjectives: [ 'little', 'angry', 'frightened' ],
|
|
|
|
adverbs: [ 'little' ],
|
|
|
|
rest: [ 'the' ]
|
|
|
|
},
|
|
|
|
garble = 'garblegarble'; // expect not to find word
|
2012-05-02 23:18:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
describe('get POS', function() {
|
|
|
|
|
|
|
|
beforeEach(function() {
|
2012-05-04 19:23:28 +00:00
|
|
|
this.addMatchers({
|
|
|
|
// unordered (multiset) comparison -- NOTE: doesn't handle deep!
|
|
|
|
toEqualUnordered: function(expected) {
|
|
|
|
var mismatchKeys=[],
|
|
|
|
mismatchValues=[],
|
|
|
|
result = this.env.compareObjects_(this.actual, expected, mismatchKeys, mismatchValues);
|
|
|
|
return result || (mismatchKeys.length == 0 && mismatchValues.length > 0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2012-05-02 23:18:10 +00:00
|
|
|
it('should get all POS', function() {
|
|
|
|
wordpos.getPOS(str, function(result) {
|
|
|
|
expect(result.nouns).toEqualUnordered(expected.nouns);
|
|
|
|
expect(result.verbs).toEqualUnordered(expected.verbs);
|
|
|
|
expect(result.adjectives).toEqualUnordered(expected.adjectives);
|
|
|
|
expect(result.adverbs).toEqualUnordered(expected.adverbs);
|
2012-05-04 19:23:28 +00:00
|
|
|
expect(result.rest).toEqualUnordered(expected.rest);
|
2012-05-02 23:18:10 +00:00
|
|
|
asyncSpecDone();
|
|
|
|
});
|
|
|
|
asyncSpecWait();
|
|
|
|
});
|
2012-05-04 19:23:28 +00:00
|
|
|
|
2012-05-02 23:18:10 +00:00
|
|
|
it('should get nouns', function() {
|
2012-05-04 19:23:28 +00:00
|
|
|
wordpos.getNouns(str, function(result) {
|
|
|
|
expect(result).toEqualUnordered(expected.nouns);
|
|
|
|
asyncSpecDone();
|
|
|
|
});
|
|
|
|
asyncSpecWait();
|
2012-05-02 23:18:10 +00:00
|
|
|
});
|
2012-05-04 19:23:28 +00:00
|
|
|
|
2012-05-02 23:18:10 +00:00
|
|
|
it('should get verbs', function() {
|
2012-05-04 19:23:28 +00:00
|
|
|
wordpos.getVerbs(str, function(result) {
|
|
|
|
expect(result).toEqualUnordered(expected.verbs);
|
|
|
|
asyncSpecDone();
|
|
|
|
});
|
|
|
|
asyncSpecWait();
|
2012-05-02 23:18:10 +00:00
|
|
|
});
|
2012-05-04 19:23:28 +00:00
|
|
|
|
2012-05-02 23:18:10 +00:00
|
|
|
it('should get adjectives', function() {
|
2012-05-04 19:23:28 +00:00
|
|
|
wordpos.getAdjectives(str, function(result) {
|
|
|
|
expect(result).toEqualUnordered(expected.adjectives);
|
|
|
|
asyncSpecDone();
|
|
|
|
});
|
|
|
|
asyncSpecWait();
|
2012-05-02 23:18:10 +00:00
|
|
|
});
|
2012-05-04 19:23:28 +00:00
|
|
|
|
2012-05-02 23:18:10 +00:00
|
|
|
it('should get adverbs', function() {
|
2012-05-04 19:23:28 +00:00
|
|
|
wordpos.getAdverbs(str, function(result) {
|
|
|
|
expect(result).toEqualUnordered(expected.adverbs);
|
|
|
|
asyncSpecDone();
|
|
|
|
});
|
|
|
|
asyncSpecWait();
|
2012-05-02 23:18:10 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('is POS', function() {
|
|
|
|
it('should check if noun', function() {
|
|
|
|
wordpos.isNoun(expected.nouns[0], function(result) {
|
|
|
|
expect(result).toBeTruthy();
|
|
|
|
asyncSpecDone();
|
|
|
|
});
|
|
|
|
asyncSpecWait();
|
|
|
|
});
|
|
|
|
it('should check if verb', function() {
|
2012-05-04 19:23:28 +00:00
|
|
|
wordpos.isVerb(expected.verbs[0], function(result) {
|
|
|
|
expect(result).toBeTruthy();
|
|
|
|
asyncSpecDone();
|
|
|
|
});
|
|
|
|
asyncSpecWait();
|
2012-05-02 23:18:10 +00:00
|
|
|
});
|
|
|
|
it('should check if adjective', function() {
|
2012-05-04 19:23:28 +00:00
|
|
|
wordpos.isAdjective(expected.adjectives[0], function(result) {
|
|
|
|
expect(result).toBeTruthy();
|
|
|
|
asyncSpecDone();
|
|
|
|
});
|
|
|
|
asyncSpecWait();
|
2012-05-02 23:18:10 +00:00
|
|
|
});
|
|
|
|
it('should check if adverb', function() {
|
2012-05-04 19:23:28 +00:00
|
|
|
wordpos.isAdverb(expected.adverbs[0], function(result) {
|
|
|
|
expect(result).toBeTruthy();
|
|
|
|
asyncSpecDone();
|
|
|
|
});
|
|
|
|
asyncSpecWait();
|
2012-05-02 23:18:10 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('is !POS', function() {
|
2012-05-04 19:23:28 +00:00
|
|
|
it('should check if !noun', function() {
|
|
|
|
wordpos.isNoun(garble, function(result) {
|
|
|
|
expect(result).not.toBeTruthy();
|
|
|
|
asyncSpecDone();
|
|
|
|
});
|
|
|
|
asyncSpecWait();
|
|
|
|
});
|
|
|
|
it('should check if !verb', function() {
|
|
|
|
wordpos.isVerb(garble, function(result) {
|
|
|
|
expect(result).not.toBeTruthy();
|
|
|
|
asyncSpecDone();
|
|
|
|
});
|
|
|
|
asyncSpecWait();
|
|
|
|
});
|
|
|
|
it('should check if !adjective', function() {
|
|
|
|
wordpos.isAdjective(garble, function(result) {
|
|
|
|
expect(result).not.toBeTruthy();
|
|
|
|
asyncSpecDone();
|
|
|
|
});
|
|
|
|
asyncSpecWait();
|
|
|
|
});
|
|
|
|
it('should check if !adverb', function() {
|
|
|
|
wordpos.isAdverb(garble, function(result) {
|
|
|
|
expect(result).not.toBeTruthy();
|
|
|
|
asyncSpecDone();
|
|
|
|
});
|
|
|
|
asyncSpecWait();
|
|
|
|
});
|
2012-05-02 23:18:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('lookup POS', function() {
|
2012-05-04 19:23:28 +00:00
|
|
|
it('should lookup noun', function() {
|
|
|
|
wordpos.lookupNoun('squirrel', function(result) {
|
|
|
|
expect(result[0].pos).toBe('n');
|
|
|
|
expect(result[0].lemma).toBe('squirrel');
|
|
|
|
asyncSpecDone();
|
|
|
|
});
|
|
|
|
asyncSpecWait();
|
|
|
|
});
|
|
|
|
it('should lookup verb', function() {
|
|
|
|
wordpos.lookupVerb('bear', function(result) {
|
|
|
|
expect(result[0].pos).toBe('v');
|
|
|
|
expect(result[0].lemma).toBe('have_a_bun_in_the_oven');
|
|
|
|
asyncSpecDone();
|
|
|
|
});
|
|
|
|
asyncSpecWait();
|
|
|
|
});
|
|
|
|
it('should lookup adjective', function() {
|
|
|
|
wordpos.lookupAdjective('angry', function(result) {
|
|
|
|
expect(result[0].pos).toBe('s');
|
|
|
|
expect(result[0].lemma).toBe('angry');
|
|
|
|
asyncSpecDone();
|
|
|
|
});
|
|
|
|
asyncSpecWait();
|
|
|
|
});
|
|
|
|
it('should lookup adverb', function() {
|
|
|
|
wordpos.lookupAdverb('little', function(result) {
|
|
|
|
expect(result[0].pos).toBe('r');
|
|
|
|
expect(result[0].lemma).toBe('little');
|
|
|
|
asyncSpecDone();
|
|
|
|
});
|
|
|
|
asyncSpecWait();
|
|
|
|
});
|
2012-05-02 23:18:10 +00:00
|
|
|
});
|
|
|
|
|
2012-05-08 04:41:46 +00:00
|
|
|
describe('options passed to constructor', function() {
|
|
|
|
var wp, origProfile = WordPOS.defaults.profile;
|
|
|
|
|
|
|
|
it('should override default option', function(){
|
|
|
|
wp = new WordPOS({profile:123});
|
|
|
|
expect(wp.options.profile).toEqual(123);
|
|
|
|
expect(WordPOS.defaults.profile).toEqual(origProfile);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not erase default option', function(){
|
|
|
|
wp = new WordPOS({aaa:123});
|
|
|
|
expect(wp.options.aaa).toEqual(123);
|
|
|
|
expect(wp.options.profile).toEqual(WordPOS.defaults.profile);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('profile option', function() {
|
|
|
|
|
|
|
|
var wp = new WordPOS({profile : true});
|
|
|
|
|
|
|
|
it('should return time argument for isX()', function(){
|
|
|
|
wp.isNoun(garble, function(result, time) {
|
|
|
|
expect(time).toBeDefined();
|
|
|
|
asyncSpecDone();
|
|
|
|
});
|
|
|
|
asyncSpecWait();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return time argument for getX()', function(){
|
|
|
|
wp.getNouns(garble, function(result, time) {
|
|
|
|
expect(time).toBeDefined();
|
|
|
|
asyncSpecDone();
|
|
|
|
});
|
|
|
|
asyncSpecWait();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return time argument for lookupX()', function(){
|
|
|
|
wp.isNoun(garble, function(result, time) {
|
|
|
|
expect(time).toBeDefined();
|
|
|
|
asyncSpecDone();
|
|
|
|
});
|
|
|
|
asyncSpecWait();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|