added WNdb module to obtain WordNet files offline

This commit is contained in:
moos 2012-05-06 02:44:21 -07:00
parent 518725c189
commit 017c0029f4
5 changed files with 24 additions and 29 deletions

View File

@ -10,7 +10,7 @@ Usage
```js ```js
var WordPOS = require('./wordpos'), var WordPOS = require('./wordpos'),
wordpos = new WordPOS('dict'); wordpos = new WordPOS();
wordpos.getAdjectives('The angry bear chased the frightened little squirrel.', function(result){ wordpos.getAdjectives('The angry bear chased the frightened little squirrel.', function(result){
console.log(result); console.log(result);
@ -30,8 +30,16 @@ Installation
Get the script `wordpos.js` and use it. (npm module may be coming.) 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 -- or use a git path in your package.json dependencies:
but I've found this to be unreliable as some of the files get truncated, leading the program to hang. ```
...
"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. Note: `wordpos-bench.js` requires a [forked uubench](https://github.com/moos/uubench) module.
@ -212,22 +220,3 @@ License
(The MIT License) (The MIT License)
Copyright (c) 2012, mooster@42at.com 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.

View File

@ -1,21 +1,22 @@
{ {
"name": "wordpos", "name": "wordpos",
"description": "wordpos is a set of part-of-speech utilities for Node.js using natural's WordNet module.", "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", "homepage": "https://github.com/moos/wordpos",
"engines": { "engines": {
"node": ">=0.4.10" "node": ">=0.4.10"
}, },
"dependencies": { "dependencies": {
"natural": "latest", "natural": "latest",
"underscore": ">=1.3.1" "underscore": ">=1.3.1",
"WNdb": "git://github.com/moos/WNdb.git"
}, },
"devDependencies": { "devDependencies": {
"uubench": "git://github.com/moos/uubench.git" "uubench": "git://github.com/moos/uubench.git"
}, },
"repository" : { "repository" : {
"type" : "git", "type" : "git",
"url" : "http://github.com/moos/wordpos.git" "url" : "git://github.com/moos/wordpos.git"
}, },
"author": "Moos <mooster@42at.com>", "author": "Moos <mooster@42at.com>",
"keywords": ["natural", "language", "wordnet", "pos"], "keywords": ["natural", "language", "wordnet", "pos"],

View File

@ -3,7 +3,7 @@ var uubench = require('uubench'), // from: https://github.com/moos/uubench
fs = require('fs'), fs = require('fs'),
_ = require('underscore')._, _ = require('underscore')._,
WordPOS = require('./wordpos'), WordPOS = require('./wordpos'),
wordpos = new WordPOS('dict'); wordpos = new WordPOS();
suite = new uubench.Suite({ suite = new uubench.Suite({
type: 'fixed', type: 'fixed',

View File

@ -12,7 +12,8 @@ var _ = require('underscore')._,
natural = require('natural'), natural = require('natural'),
WordNet = natural.WordNet, WordNet = natural.WordNet,
tokenizer = new natural.WordTokenizer(), tokenizer = new natural.WordTokenizer(),
stopwords = ' '+ natural.stopwords.join(' ') +' '; stopwords = ' '+ natural.stopwords.join(' ') +' ',
WNdb = require('WNdb');
function normalize(word) { function normalize(word) {
return word.toLowerCase().replace(/\s+/g, '_'); return word.toLowerCase().replace(/\s+/g, '_');
@ -65,7 +66,11 @@ function get(isFn) {
var WordPOS = function() { 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); util.inherits(WordPOS, WordNet);

View File

@ -6,7 +6,7 @@
*/ */
var WordPOS = require('./wordpos'), var WordPOS = require('./wordpos'),
wordpos = new WordPOS('dict'); wordpos = new WordPOS();
var str = "The angry bear chased the frightened little squirrel", var str = "The angry bear chased the frightened little squirrel",
expected = { expected = {