Code Monkey home page Code Monkey 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:

  • A fully async interface for performing sentiment analysis
  • A build process that makes updating sentiment to future versions of the AFINN word list trivial
  • Performance (see benchmarks below)

Installation

npm install sentiment

Usage

var sentiment = require('sentiment');

sentiment('Cats are stupid.', function (err, result) {
    console.dir(result);    // Score: -2, Comparative: -0.666
});

sentiment('Cats are totally amazing!', function (err, result) {
    console.dir(result);    // 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');

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

Testing

npm test

Benchmarks

The primary motivation for designing sentiment was performance. As such, sentiment 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.8.9, sentiment is about 33 times faster than the alternative implementation:

sentiment (v0.1.0)
1000 operations  |  33ms
2000 operations  |  75ms
4000 operations  |  138ms
8000 operations  |  252ms
16000 operations |  506ms
32000 operations |  1120ms
64000 operations |  2268ms

--------------------------
--------------------------

Sentimental (v0.0.2)
1000 operations  |  1189ms
2000 operations  |  2392ms
4000 operations  |  4760ms
8000 operations  |  9469ms
16000 operations |  19513ms
32000 operations |  41018ms
64000 operations |  86931ms

sentiment's People

Contributors

thisandagain avatar

Watchers

Syah Reza Octadian avatar James Cloos 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.