updated README.
This commit is contained in:
parent
40411b7f3a
commit
6ef8c8ce5b
165
README.md
165
README.md
|
@ -1,48 +1,47 @@
|
||||||
wordpos
|
wordpos
|
||||||
=======
|
=======
|
||||||
|
|
||||||
wordpos is a set of part-of-speech utilities for Node.js using [natural's](http://github.com/NaturalNode/natural) WordNet module.
|
wordpos is a set of part-of-speech utilities for Node.js using [natural's] http://github.com/NaturalNode/natural) WordNet module.
|
||||||
|
|
||||||
There is no lexigraphical intelligence here. Only dictionary lookup.
|
There is no lexigraphical intelligence here. Only dictionary lookup.
|
||||||
|
|
||||||
|
Usage
|
||||||
|
-------
|
||||||
|
|
||||||
|
```js
|
||||||
|
var WordPOS = require('./wordpos'),
|
||||||
|
wordpos = new WordPOS('dict');
|
||||||
|
|
||||||
|
wordpos.getAdjectives('The angry bear chased the frightened little squirrel.', function(result){
|
||||||
|
console.log(result);
|
||||||
|
});
|
||||||
|
// [ 'little', 'angry', 'frightened' ]
|
||||||
|
|
||||||
|
wordpos.isAdjective('awesome', function(result){
|
||||||
|
console.log(result);
|
||||||
|
});
|
||||||
|
// true
|
||||||
|
```
|
||||||
|
|
||||||
|
See `wordpos_spec.js` for full usage.
|
||||||
|
|
||||||
Installation
|
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 from [here](http://wordnet.princeton.edu/wordnet/download/current-version/).
|
You may also want to manually download WordNet files from [here](http://wordnet.princeton.edu/wordnet/download/current-version/). Unpack into folder (say `dict`, see below). [natrual](http://github.com/NaturalNode/natural) will auto-download WordNet files --
|
||||||
Unpack into folder (say `dict`, see below). [natrual](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 and the core program hangs.
|
but I've found this to be unreliable as some of the files get truncated and the core program hangs.
|
||||||
|
|
||||||
Note: `wordpos-bench` requires a customized [uubench](https://github.com/moos/uubench) module (forthcoming).
|
Note: `wordpos-bench` requires a customized [uubench](https://github.com/moos/uubench) module (forthcoming).
|
||||||
|
|
||||||
Usage
|
|
||||||
-------
|
|
||||||
|
|
||||||
```js
|
|
||||||
var WordPOS = require('./wordpos'),
|
|
||||||
wordpos = new WordPOS('dict');
|
|
||||||
|
|
||||||
wordpos.getAdjectives('The angry bear chased the frightened little squirrel.', function(result){
|
|
||||||
console.log(result);
|
|
||||||
});
|
|
||||||
// [ 'little', 'angry', 'frightened' ]
|
|
||||||
|
|
||||||
wordpos.isAdjective('awesome', function(result){
|
|
||||||
console.log(result);
|
|
||||||
});
|
|
||||||
// true
|
|
||||||
```
|
|
||||||
|
|
||||||
See `wordpos_spec.js` for full usage.
|
|
||||||
|
|
||||||
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](https://github.com/NaturalNode/natural#wordnet) class
|
WordPOS is a subclass of natural's [WordNet class](https://github.com/NaturalNode/natural#wordnet) and inherits call its methods.
|
||||||
and inherits call it's methods.
|
|
||||||
|
|
||||||
|
|
||||||
### getX()
|
### getX()
|
||||||
|
@ -50,24 +49,24 @@ and inherits call it's methods.
|
||||||
Get POS from text.
|
Get POS from text.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
wordpos.getPOS(str, callback) -- callback receives a result object:
|
wordpos.getPOS(str, callback) -- callback receives a result object:
|
||||||
{
|
{
|
||||||
nouns:[], Array of str words that are nouns
|
nouns:[], Array of str words that are nouns
|
||||||
verbs:[], Array of str words that are verbs
|
verbs:[], Array of str words that are verbs
|
||||||
adjectives:[], Array of str words that are adjectives
|
adjectives:[], Array of str words that are adjectives
|
||||||
adverbs:[], Array of str words that are adverbs
|
adverbs:[], Array of str words that are adverbs
|
||||||
rest:[] Array of str words that are not in dict
|
rest:[] Array of str words that are not in dict
|
||||||
}
|
}
|
||||||
|
|
||||||
Note: a word may appear in multiple POS (eg, 'great' is both a noun and an adjective)
|
|
||||||
|
|
||||||
wordpos.getNouns(str, callback) -- callback receives an array of nouns in str
|
Note: a word may appear in multiple POS (eg, 'great' is both a noun and an adjective)
|
||||||
|
|
||||||
|
wordpos.getNouns(str, callback) -- callback receives an array of nouns in str
|
||||||
|
|
||||||
wordpos.getVerbs(str, callback) -- callback receives an array of verbs in str
|
wordpos.getVerbs(str, callback) -- callback receives an array of verbs in str
|
||||||
|
|
||||||
wordpos.getAdjectives(str, callback) -- callback receives an array of adjectives in str
|
wordpos.getAdjectives(str, callback) -- callback receives an array of adjectives in str
|
||||||
|
|
||||||
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
|
NB: If you're only interested in a certain POS (say, adjectives), using the particular getX() is faster
|
||||||
|
@ -79,8 +78,8 @@ are stripped out from str before lookup.
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
wordpos.getNouns('The angry bear chased the frightened little squirrel.', console.log)
|
wordpos.getNouns('The angry bear chased the frightened little squirrel.', console.log)
|
||||||
// [ 'bear', 'squirrel', 'little', 'chased' ]
|
// [ 'bear', 'squirrel', 'little', 'chased' ]
|
||||||
```
|
```
|
||||||
|
|
||||||
getNouns() returns all words within given (context-free) string of words that can be considered nouns (via
|
getNouns() returns all words within given (context-free) string of words that can be considered nouns (via
|
||||||
|
@ -93,29 +92,29 @@ would be considered nouns. (see http://nltk.googlecode.com/svn/trunk/doc/book/c
|
||||||
Determine if a word is a particular POS.
|
Determine if a word is a particular POS.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
wordpos.isNoun(word, callback) -- callback receives result (true/false) if word is a noun.
|
wordpos.isNoun(word, callback) -- callback receives result (true/false) if word is a noun.
|
||||||
|
|
||||||
wordpos.isVerb(word, callback) -- callback receives result (true/false) if word is a verb.
|
wordpos.isVerb(word, callback) -- callback receives result (true/false) if word is a verb.
|
||||||
|
|
||||||
wordpos.isAdjective(word, callback) -- callback receives result (true/false) if word is an adjective.
|
wordpos.isAdjective(word, callback) -- callback receives result (true/false) if word is an adjective.
|
||||||
|
|
||||||
wordpos.isAdverb(word, callback) -- callback receives result (true/false) if word is an adverb.
|
wordpos.isAdverb(word, callback) -- callback receives result (true/false) if word is an adverb.
|
||||||
```
|
```
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
wordpos.isVerb('fish', console.log);
|
wordpos.isVerb('fish', console.log);
|
||||||
// true
|
// true
|
||||||
|
|
||||||
wordpos.isNoun('fish', console.log);
|
wordpos.isNoun('fish', console.log);
|
||||||
// true
|
// true
|
||||||
|
|
||||||
wordpos.isAdjective('fishy', console.log);
|
wordpos.isAdjective('fishy', console.log);
|
||||||
// true
|
// true
|
||||||
|
|
||||||
wordpos.isAdverb('fishly', console.log);
|
wordpos.isAdverb('fishly', console.log);
|
||||||
// false
|
// false
|
||||||
```
|
```
|
||||||
|
|
||||||
### lookupX()
|
### lookupX()
|
||||||
|
@ -124,39 +123,41 @@ These calls are similar to natural's [lookup()](https://github.com/NaturalNode/n
|
||||||
already know the POS of the word.
|
already know the POS of the word.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
wordpos.lookupNoun(word, callback) -- callback receives array of lookup objects for a noun
|
wordpos.lookupNoun(word, callback) -- callback receives array of lookup objects for a noun
|
||||||
|
|
||||||
wordpos.lookupVerb(word, callback) -- callback receives array of lookup objects for a verb
|
wordpos.lookupVerb(word, callback) -- callback receives array of lookup objects for a verb
|
||||||
|
|
||||||
wordpos.lookupAdjective(word, callback) -- callback receives array of lookup objects for an adjective
|
wordpos.lookupAdjective(word, callback) -- callback receives array of lookup objects for an adjective
|
||||||
|
|
||||||
wordpos.lookupAdverb(word, callback) -- callback receives array of lookup objects for an adverb
|
wordpos.lookupAdverb(word, callback) -- callback receives array of lookup objects for an adverb
|
||||||
```
|
```
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
wordpos.lookupAdjective('awesome', console.log);
|
wordpos.lookupAdjective('awesome', console.log);
|
||||||
// output:
|
// output:
|
||||||
[ { synsetOffset: 1282510,
|
[ { synsetOffset: 1282510,
|
||||||
lexFilenum: 0,
|
lexFilenum: 0,
|
||||||
pos: 's',
|
pos: 's',
|
||||||
wCnt: 5,
|
wCnt: 5,
|
||||||
lemma: 'amazing',
|
lemma: 'amazing',
|
||||||
synonyms: [ 'amazing', 'awe-inspiring', 'awesome', 'awful', 'awing' ],
|
synonyms: [ 'amazing', 'awe-inspiring', 'awesome', 'awful', 'awing' ],
|
||||||
lexId: '0',
|
lexId: '0',
|
||||||
ptrs: [],
|
ptrs: [],
|
||||||
gloss: 'inspiring awe or admiration or wonder; "New York is an amazing city"; "the Grand Canyon is an awe-inspiring
|
gloss: 'inspiring awe or admiration or wonder; "New York is an amazing city"; "the Grand Canyon is an awe-inspiring
|
||||||
sight"; "the awesome complexity of the universe"; "this sea, whose gently awful stirrings seem to speak of some hidden s
|
sight"; "the awesome complexity of the universe"; "this sea, whose gently awful stirrings seem to speak of some hidden s
|
||||||
oul beneath"- Melville; "Westminster Hall\'s awing majesty, so vast, so high, so silent" ' } ]
|
oul beneath"- Melville; "Westminster Hall\'s awing majesty, so vast, so high, so silent" ' } ]
|
||||||
```
|
```
|
||||||
In this case only one lookup was found. But there could be several.
|
In this case only one lookup was found. But there could be several.
|
||||||
|
|
||||||
|
|
||||||
Or use WordNet's inherited method directly:
|
Or use WordNet's inherited method directly:
|
||||||
|
|
||||||
wordpos.lookup('great', console.log);
|
```js
|
||||||
// ...
|
wordpos.lookup('great', console.log);
|
||||||
|
// ...
|
||||||
|
```
|
||||||
|
|
||||||
Benchmark
|
Benchmark
|
||||||
----------
|
----------
|
||||||
|
|
Loading…
Reference in New Issue