Detect the polarity of text, based on afinn-165 and
emoji-emotion.
npm:
npm install polarityvar polarity = require('polarity')
polarity(['some', 'positive', 'happy', 'cats'])Yields:
{
polarity: 5,
positivity: 5,
negativity: 0,
positive: ['happy', 'positive'],
negative: []
}polarity(['darn', 'self-deluded', 'abandoned', 'dogs'])Yields:
{
polarity: -4,
positivity: 0,
negativity: -4,
positive: [],
negative: ['abandoned', 'self-deluded']
}Get a polarity result from given values, optionally with one time injections.
polarity does not tokenise values. There are better tokenisers around (parse-latin). However, the following will work pretty good:
function tokenize(value) {
return value.toLowerCase().match(/\S+/g)
}words(Array.<string>) — Words to parseinject(Object.<number>, optional) — Custom valences for words
Object:
polarity(number) — Calculated polarity of inputpositivity(number) — Total positivitynegativity(number) — Total negativitypositive(Array.<string>) — All positive wordsnegative(Array.<string>) — All negative words
Insert custom values.
Direct access to the internal values.
afinn-96— AFINN list from 2009, containing 1468 entriesafinn-111— AFINN list from 2011, containing 2477 entriesafinn-169— AFINN list from 2015, containing 3382 entriesemoji-emotion— Like AFINN, but for emoji