Introduction

wink-sentiment

Accurate & fast sentiment scoring of phrases with #hashtags, emoticons:) & emojisπŸŽ‰

Build Status Coverage Status dependencies Status devDependencies Status

Analyze sentiment of tweets, product reviews, social media content or any text using wink-sentiment. It is a part of wink β€” a growing family of high quality packages for Statistical Analysis, Natural Language Processing and Machine Learning in NodeJS.

It is based on AFINN and Emoji Sentiment Ranking; it's features include:

  1. Intelligent negation handling; for example, phrase "good product" will get a positive score whereas "not a good product" gets a negative score.
  2. Automatic detection and scoring of two-word phrases in a text; for example, "cool stuff", "well done", and "short sighted".
  3. Processes each emoji, emoticon and/or hashtag separately while scoring.
  4. Embeds a powerful tokenizer that returns the tokenized phrase.
  5. Returns the sentiment score and tokens. Each token contains a set of properties defining its sentiment, if any.
  6. Achieves accuracy of 77%, when validated using Amazon Product Review Sentiment Labelled Sentences Data Set at UCI Machine Learning Repository.

Installation

Use npm to install:

npm install wink-sentiment --save

Example

// Load wink-sentiment package.
var sentiment = require( 'wink-sentiment' );
// Just give any phrase and checkout the sentiment score. A positive score
// means a positive sentiment, whereas a negative score indicates a negative
// sentiment. Neutral sentiment is signalled by a near zero score.
sentiment( 'Excited to be part of the @imascientist team:-)!' );
// -> { score: 5,
//      normalizedScore: 2.5,
//      tokenizedPhrase: [
//        { value: 'Excited', tag: 'word', score: 3 },
//        { value: 'to', tag: 'word' },
//        { value: 'be', tag: 'word' },
//        { value: 'part', tag: 'word' },
//        { value: 'of', tag: 'word' },
//        { value: 'the', tag: 'word' },
//        { value: '@imascientist', tag: 'mention' },
//        { value: 'team', tag: 'word' },
//        { value: ':-)', tag: 'emoticon', score: 2 },
//        { value: '!', tag: 'punctuation' }
//      ]
//    }

Documentation

Check out the wink sentiment API documentation to learn more.

Need Help?

If you spot a bug and the same has not yet been reported, raise a new issue or consider fixing it and sending a pull request.

Copyright & License

wink-sentiment is copyright 2017-18 GRAYPE Systems Private Limited.

It is licensed under the under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License.

sentiment

Computes the absolue and normalized sentiment scores of the input phrase, after tokenizing it.

The normalized score is computed by taking into account of absolute scores of words, emojis, emoticons, and hashtags and adjusting it on the basis of total words in the text; this is always between -5 and +5. A score of less than 0 indicates negative sentiments and a score of more than 0 indicates positive sentiments; wheras a near zero score suggests a neutral sentiment. While counting tokens only the ones tagged as word, emoji, or emoticon are counted; and one letter words are ignored.

It performs tokenization using wink-tokenizer. During sentiment analysis, each token may be assigned up to 3 new properties. These properties are:

  1. score β€” contains the sentiment score of the word, emoji, emoticon or hashtag, which is always between -5 and +5. This is added only when the word in question has a positive or negative sentiment associated with it.
  2. negation β€” is added & set to true whenever the score of the token has beeen impacted due to a negation word apprearing prior to it.
  3. grouped β€” is added whenever, the token is the first word of a short idiom or a phrase. It's value provides the number of tokens that have been grouped together to form the phrase/idiom.
sentiment(phrase: string): object
Parameters
phrase (string) β€” whoes sentiment score needs to be computed.
Returns
object: β€” absolute score , normalizedScore and tokenizedPhrase of phrase .
Example
sentiment( 'not a good product #fail' );
// -> { score: -5,
//      normalizedScore: -2.5,
//      tokenizedPhrase: [
//        { value: 'not', tag: 'word' },
//        { value: 'a', tag: 'word' },
//        { value: 'good', tag: 'word', negation: true, score: -3 },
//        { value: 'product', tag: 'word' },
//        { value: '#fail', tag: 'hashtag', score: -2 }
//      ]
//    }