1 | ## sentiment
|
2 | #### AFINN-based sentiment analysis for Node.js
|
3 |
|
4 | [![Build Status](https://secure.travis-ci.org/thisandagain/sentiment.png)](http://travis-ci.org/thisandagain/sentiment)
|
5 |
|
6 | 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:
|
7 |
|
8 | - Performance (see benchmarks below)
|
9 | - The ability to append and overwrite word / value pairs from the AFINN wordlist
|
10 | - A build process that makes updating sentiment to future versions of the AFINN word list trivial
|
11 |
|
12 | ### Installation
|
13 | ```bash
|
14 | npm install sentiment
|
15 | ```
|
16 |
|
17 | ### Usage
|
18 | ```javascript
|
19 | var sentiment = require('sentiment');
|
20 |
|
21 | var r1 = sentiment('Cats are stupid.');
|
22 | console.dir(r1); // Score: -2, Comparative: -0.666
|
23 |
|
24 | var r2 = sentiment('Cats are totally amazing!');
|
25 | console.dir(r2); // Score: 4, Comparative: 1
|
26 | ```
|
27 |
|
28 | ### Adding / overwriting words
|
29 | You can append and/or overwrite values from AFINN by simply injecting key/value pairs into a sentiment method call:
|
30 | ```javascript
|
31 | var sentiment = require('sentiment');
|
32 |
|
33 | var result = sentiment('Cats are totally amazing!', {
|
34 | 'cats': 5,
|
35 | 'amazing': 2
|
36 | });
|
37 | console.dir(result); // Score: 7, Comparative: 1.75
|
38 | ```
|
39 |
|
40 | ---
|
41 |
|
42 | ### Benchmarks
|
43 | 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 an older MacBook Air with Node 0.10.26, `sentiment` is **more than twice as fast** as alternative implementations:
|
44 |
|
45 | ```bash
|
46 | sentiment (Latest) x 244,901 ops/sec ±0.49% (100 runs sampled)
|
47 | Sentimental (1.0.1) x 94,135 ops/sec ±0.50% (100 runs sampled)
|
48 | ```
|
49 |
|
50 | To run the benchmarks yourself, simply:
|
51 | ```bash
|
52 | make benchmark
|
53 | ```
|
54 |
|
55 | ---
|
56 |
|
57 | ### Testing
|
58 | ```bash
|
59 | npm test
|
60 | ``` |
\ | No newline at end of file |