polarity
Detect the polarity of text, based on AFINN-111.
Uses wooorm/afinn-111.
Installation
NPM:
$ npm install polarity
Component.js:
$ component install wooorm/polarity
Usage
var polarity = require('polarity');
polarity(['some', 'positive', 'happy', 'cats']);
polarity(['darn', 'self-deluded', 'abandoned', 'dogs']);
polarity(['some', 'positive', 'happy', 'cats'], {
'cats' : Infinity
});
polarity.inject({
'dogs' : -Infinity
});
polarity(['darn', 'self-deluded', 'abandoned', 'dogs']);
API
polarity(values[string]?, inject?)
Get a polarity result from given values, optionally with one time injections.
polarity does not tokenise values. There are better tokenisers around (hint hint, parse-latin). However, the following will work pretty good:
function tokenize(value) {
return value.toLowerCase().replace(/[^-a-z0-9 ]/g, '').split(' ');
}
polarity.inject(inject{word: weight})
Replace AFINN weights with your own.
polarity.afinn
Direct access to afinn-111.
Supported words
polarity supports all AFINN-111 words/phrases. afinn-111 has more information on what words and phrases are supported.
Other polarity detection libraries
Benchmark
Run the benchmark yourself:
$ npm run install-benchmark
$ npm run benchmark
On a MacBook Air, it detects the polarity of 168,820 tweets per second.
This is with a manual tokenisation step (like the others do) taken into account.
Without the tokenisation step, polarity is of course much faster.
benchmarks * 20 tweets (10 pos, 10 neg)
8,441 op/s » polarity -- this module
7,708 op/s » sentiment
3,950 op/s » sediment
2,604 op/s » Sentimental
License
MIT