Giter Site home page Giter Site logo

sentiment's Introduction

sentiment

AFINN-based sentiment analysis for Node.js

Build Status

Sentiment is a Node.js module that uses the AFINN-111 wordlist to perform sentiment analysis on arbitrary blocks of input text. Sentiment provides serveral things:

  • Performance (see benchmarks below)
  • The ability to append and overwrite word / value pairs from the AFINN wordlist
  • A build process that makes updating sentiment to future versions of the AFINN word list trivial

Installation

npm install sentiment

Usage

var sentiment = require('sentiment');

var r1 = sentiment('Cats are stupid.');
console.dir(r1);        // Score: -2, Comparative: -0.666

var r2 = sentiment('Cats are totally amazing!');
console.dir(r2);        // Score: 4, Comparative: 1

Adding / overwriting words

You can append and/or overwrite values from AFINN by simply injecting key/value pairs into a sentiment method call:

var sentiment = require('sentiment');

var result = sentiment('Cats are totally amazing!', {
    'cats': 5,
    'amazing': 2  
});
console.dir(result);    // Score: 7, Comparative: 1.75

Benchmarks

The primary motivation for designing sentiment was performance. As such, it includes a benchmark script within the test directory that compares it against the Sentimental module which provides a nearly equivalent interface and approach. Based on these benchmarks, running on an older MacBook Air with Node 0.10.26, sentiment is more than twice as fast as alternative implementations:

sentiment (Latest) x 244,901 ops/sec ±0.49% (100 runs sampled)
Sentimental (1.0.1) x 94,135 ops/sec ±0.50% (100 runs sampled)

To run the benchmarks yourself, simply:

make benchmark

Testing

npm test

sentiment's People

Contributors

thisandagain avatar joshbeckman avatar monteslu avatar micahfulton avatar

Watchers

James Cloos avatar joshua chavanne avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.