1 | ## sentiment
|
2 | #### AFINN-based sentiment analysis for Node.js
|
3 |
|
4 | [![Build Status](https://travis-ci.org/thisandagain/sentiment.svg?branch=develop)](https://travis-ci.org/thisandagain/sentiment)
|
5 | [![Coverage Status](https://coveralls.io/repos/thisandagain/sentiment/badge.svg?branch=develop&service=github)](https://coveralls.io/github/thisandagain/sentiment?branch=develop)
|
6 | [![Dependency Status](https://david-dm.org/thisandagain/sentiment.svg)](https://david-dm.org/thisandagain/sentiment)
|
7 | [![devDependency Status](https://david-dm.org/thisandagain/sentiment/dev-status.svg)](https://david-dm.org/thisandagain/sentiment#info=devDependencies)
|
8 |
|
9 | Sentiment is a Node.js module that uses the [AFINN-111](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6010) wordlist to perform [sentiment analysis](http://en.wikipedia.org/wiki/Sentiment_analysis) on arbitrary blocks of input text. Sentiment provides serveral things:
|
10 |
|
11 | - Performance (see benchmarks below)
|
12 | - The ability to append and overwrite word / value pairs from the AFINN wordlist
|
13 | - A build process that makes updating sentiment to future versions of the AFINN word list trivial
|
14 |
|
15 | ### Installation
|
16 | ```bash
|
17 | npm install sentiment
|
18 | ```
|
19 |
|
20 | ### Usage
|
21 | ```javascript
|
22 | var sentiment = require('sentiment');
|
23 |
|
24 | var r1 = sentiment('Cats are stupid.');
|
25 | console.dir(r1); // Score: -2, Comparative: -0.666
|
26 |
|
27 | var r2 = sentiment('Cats are totally amazing!');
|
28 | console.dir(r2); // Score: 4, Comparative: 1
|
29 | ```
|
30 |
|
31 | ### Adding / overwriting words
|
32 | You can append and/or overwrite values from AFINN by simply injecting key/value pairs into a sentiment method call:
|
33 | ```javascript
|
34 | var sentiment = require('sentiment');
|
35 |
|
36 | var result = sentiment('Cats are totally amazing!', {
|
37 | 'cats': 5,
|
38 | 'amazing': 2
|
39 | });
|
40 | console.dir(result); // Score: 7, Comparative: 1.75
|
41 | ```
|
42 |
|
43 | ---
|
44 |
|
45 | ### Benchmarks
|
46 | 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](https://github.com/thinkroth/Sentimental) module which provides a nearly equivalent interface and approach. Based on these benchmarks, running on a MacBook Pro with Node 0.12.7, `sentiment` is **twice as fast** as alternative implementations:
|
47 |
|
48 | ```bash
|
49 | sentiment (Latest) x 544,714 ops/sec ±0.83% (99 runs sampled)
|
50 | Sentimental (1.0.1) x 269,417 ops/sec ±1.06% (96 runs sampled)
|
51 | ```
|
52 |
|
53 | To run the benchmarks yourself, simply:
|
54 | ```bash
|
55 | make benchmark
|
56 | ```
|
57 |
|
58 | ---
|
59 |
|
60 | ### Testing
|
61 | ```bash
|
62 | npm test
|
63 | ```
|