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.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
increased by10%
Maintainers
1
Weekly downloads
 
Created
Source

polarity Build Status Coverage Status

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

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, 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().match(/\S+/g);
}

polarity.inject(words)

Insert custom values.

polarity.polarities

Direct access to the internal values.

Supported words

See Support.md.

Benchmark

On a MacBook Air, it detects the polarity of 142,300 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,218 op/s » polarity -- this module
  4,374 op/s » sentiment
  3,182 op/s » sediment
  2,284 op/s » Sentimental

License

MIT © Titus Wormer

Keywords

FAQs

Package last updated on 30 Nov 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