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

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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.

License

MIT © Titus Wormer

Keywords

FAQs

Package last updated on 04 Jan 2017

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