From 017c0029f4a634ded8d68eaaa4fd631162357307 Mon Sep 17 00:00:00 2001 From: moos Date: Sun, 6 May 2012 02:44:21 -0700 Subject: [PATCH] added WNdb module to obtain WordNet files offline --- README.md | 33 +++++++++++---------------------- package.json | 7 ++++--- wordpos-bench.js | 2 +- wordpos.js | 9 +++++++-- wordpos_spec.js | 2 +- 5 files changed, 24 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 8687a38..fa93f96 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Usage ```js var WordPOS = require('./wordpos'), - wordpos = new WordPOS('dict'); + wordpos = new WordPOS(); wordpos.getAdjectives('The angry bear chased the frightened little squirrel.', function(result){ console.log(result); @@ -30,8 +30,16 @@ Installation Get the script `wordpos.js` and use it. (npm module may be coming.) -You may also want to manually download [WordNet files](http://wordnet.princeton.edu/wordnet/download/current-version/). Unpack into folder (say `dict`). [natural](http://github.com/NaturalNode/natural) will auto-download WordNet files -- -but I've found this to be unreliable as some of the files get truncated, leading the program to hang. +or use a git path in your package.json dependencies: +``` + ... + "dependencies": { + "wordpos": "git://github.com/moos/wordpos.git" + }, + ... +``` + +As of version 0.1.1, WordNet DB files are obtained off-line through dependency provided by moos/WBdb module. Note: `wordpos-bench.js` requires a [forked uubench](https://github.com/moos/uubench) module. @@ -212,22 +220,3 @@ License (The MIT License) Copyright (c) 2012, mooster@42at.com - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -'Software'), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/package.json b/package.json index 4068bc3..f2efb4c 100644 --- a/package.json +++ b/package.json @@ -1,21 +1,22 @@ { "name": "wordpos", "description": "wordpos is a set of part-of-speech utilities for Node.js using natural's WordNet module.", - "version": "0.1.0", + "version": "0.1.1", "homepage": "https://github.com/moos/wordpos", "engines": { "node": ">=0.4.10" }, "dependencies": { "natural": "latest", - "underscore": ">=1.3.1" + "underscore": ">=1.3.1", + "WNdb": "git://github.com/moos/WNdb.git" }, "devDependencies": { "uubench": "git://github.com/moos/uubench.git" }, "repository" : { "type" : "git", - "url" : "http://github.com/moos/wordpos.git" + "url" : "git://github.com/moos/wordpos.git" }, "author": "Moos ", "keywords": ["natural", "language", "wordnet", "pos"], diff --git a/wordpos-bench.js b/wordpos-bench.js index d397b38..451129d 100644 --- a/wordpos-bench.js +++ b/wordpos-bench.js @@ -3,7 +3,7 @@ var uubench = require('uubench'), // from: https://github.com/moos/uubench fs = require('fs'), _ = require('underscore')._, WordPOS = require('./wordpos'), - wordpos = new WordPOS('dict'); + wordpos = new WordPOS(); suite = new uubench.Suite({ type: 'fixed', diff --git a/wordpos.js b/wordpos.js index 8204480..187e23a 100644 --- a/wordpos.js +++ b/wordpos.js @@ -12,7 +12,8 @@ var _ = require('underscore')._, natural = require('natural'), WordNet = natural.WordNet, tokenizer = new natural.WordTokenizer(), - stopwords = ' '+ natural.stopwords.join(' ') +' '; + stopwords = ' '+ natural.stopwords.join(' ') +' ', + WNdb = require('WNdb'); function normalize(word) { return word.toLowerCase().replace(/\s+/g, '_'); @@ -65,7 +66,11 @@ function get(isFn) { var WordPOS = function() { - WordPOS.super_.apply(this, arguments); + if (arguments.length == 0) { + WordPOS.super_.call(this, WNdb.path); + } else { + WordPOS.super_.apply(this, arguments); + } }; util.inherits(WordPOS, WordNet); diff --git a/wordpos_spec.js b/wordpos_spec.js index 448d0cd..6fad43a 100644 --- a/wordpos_spec.js +++ b/wordpos_spec.js @@ -6,7 +6,7 @@ */ var WordPOS = require('./wordpos'), - wordpos = new WordPOS('dict'); + wordpos = new WordPOS(); var str = "The angry bear chased the frightened little squirrel", expected = {