UNPKG

2.06 kBMarkdownView Raw
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
6Sentiment 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
14npm install sentiment
15```
16
17### Usage
18```javascript
19var sentiment = require('sentiment');
20
21var r1 = sentiment('Cats are stupid.');
22console.dir(r1); // Score: -2, Comparative: -0.666
23
24var r2 = sentiment('Cats are totally amazing!');
25console.dir(r2); // Score: 4, Comparative: 1
26```
27
28### Adding / overwriting words
29You can append and/or overwrite values from AFINN by simply injecting key/value pairs into a sentiment method call:
30```javascript
31var sentiment = require('sentiment');
32
33var result = sentiment('Cats are totally amazing!', {
34 'cats': 5,
35 'amazing': 2
36});
37console.dir(result); // Score: 7, Comparative: 1.75
38```
39
40---
41
42### Benchmarks
43The 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
46sentiment (Latest) x 244,901 ops/sec ±0.49% (100 runs sampled)
47Sentimental (1.0.1) x 94,135 ops/sec ±0.50% (100 runs sampled)
48```
49
50To run the benchmarks yourself, simply:
51```bash
52make benchmark
53```
54
55---
56
57### Testing
58```bash
59npm test
60```
\No newline at end of file