Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

polarity

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

polarity

Detect the polarity (sentiment) of text

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

polarity Build Status Coverage Status

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: 5,
 *   positive: [ 'positive', 'happy' ],
 *   negative: []
 * }
 */

polarity(['darn', 'self-deluded', 'abandoned', 'dogs']); /* {
 *   polarity: -4,
 *   positive: [],
 *   negative: [ 'self-deluded', 'abandoned' ]
 * }
 */

polarity(['some', 'positive', 'happy', 'cats'], {
  'cats' : Infinity
}); /* {
 *   polarity: Infinity,
 *   positive: [ 'positive', 'happy', 'cats' ],
 *   negative: []
 * }
 */

polarity.inject({
    'dogs' : -Infinity /* What?! */
});

polarity(['darn', 'self-deluded', 'abandoned', 'dogs']); /* {
 *   polarity: -Infinity,
 *   positive: [],
 *   negative: [ '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 # Just once of course.
$ 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

Keywords

FAQs

Package last updated on 17 Aug 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc