New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
22
increased by46.67%
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:

$ component install wooorm/polarity

Bower:

$ bower install 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.

Benchmark

On a MacBook Air, it detects the polarity of 141,980 tweets per second. This is with a manual tokenisation step (like the competition) taken into account. Without the tokenisation step, polarity is much faster.

         benchmarks * 20 tweets (10 pos, 10 neg)
  7,099 op/s » polarity -- this module
  4,484 op/s » sentiment
  3,207 op/s » sediment
  2,298 op/s » Sentimental

License

MIT © Titus Wormer

Keywords

FAQs

Package last updated on 31 Oct 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