Skip to content

words/polarity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

polarity Build Status Coverage Status

Detect the polarity of text, based on afinn-165 and emoji-emotion.

Installation

npm:

npm install polarity

Usage

var 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']
}

API

polarity(words[, inject])

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)
}
Parameters
  • words (Array.<string>) — Words to parse
  • inject (Object.<number>, optional) — Custom valences for words
Returns

Object:

  • polarity (number) — Calculated polarity of input
  • positivity (number) — Total positivity
  • negativity (number) — Total negativity
  • positive (Array.<string>) — All positive words
  • negative (Array.<string>) — All negative words

polarity.inject(words)

Insert custom values.

polarity.polarities

Direct access to the internal values.

Related

  • afinn-96 — AFINN list from 2009, containing 1468 entries
  • afinn-111 — AFINN list from 2011, containing 2477 entries
  • afinn-169 — AFINN list from 2015, containing 3382 entries
  • emoji-emotion — Like AFINN, but for emoji

License

MIT © Titus Wormer

About

Detect the polarity (sentiment) of text

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Contributors 2

  •  
  •