thisandagain / sentiment

AFINN-based sentiment analysis for Node.js.
MIT License
2.64k stars 311 forks source link

Comparative and Score are coming out the same #111

Closed sseetal closed 7 years ago

sseetal commented 7 years ago

I have version 2.1.0 on both my computer and on a server. On my computer it works, on my server, I get the following

{ score: 3, comparative: 3, tokens: [ 'happy' ], words: [ 'happy' ], positive: [ 'happy' ], negative: [] }

{ score: -2, comparative: -2, tokens: [ 'sad' ], words: [ 'sad' ], positive: [], negative: [ 'sad' ] }

{ score: 0, comparative: 0, tokens: [ 'ok' ], words: [], positive: [], negative: [] }

Any thoughts?

thisandagain commented 7 years ago

@sseetal Can you provide a little more info?

sseetal commented 7 years ago

Thanks for getting back to me.

  1. We're using nvm everywhere. node 4.1.1 locally (MAC), v6.9.4 on Server (Ubuntu)
  2. The input streams are in the results I posted above (happy, sad, ok) to try and get the three desired results (positive, negative and neutral results)
  3. I tried getting the local results (the server results are above). I can now further understand the problem. It's because they are one word.

INPUT sentiment

For input "happy" (both locally and on server)

{ score: 3, comparative: 3, tokens: [ 'happy' ], words: [ 'happy' ], positive: [ 'happy' ], negative: [] }

For input "happy cat"

{ score: 3, comparative: 1.5, tokens: [ 'happy', 'cat' ], words: [ 'happy' ], positive: [ 'happy' ], negative: [] }

For Input "I am happy today"

{ score: 3, comparative: 0.75, tokens: [ 'i', 'am', 'happy', 'today' ], words: [ 'happy' ], positive: [ 'happy' ], negative: [] }

It was hard to find in the docs but all i really need is the range of values (Min and Max) for score and comparative. I thought comparative was between -1 and 1, but now I can't tell.

sseetal commented 7 years ago

Just to add more context. We're using this to analyze comments left by people in a survey. The whole point is to have a score and an overall score. Ideally a score out of 100. But can't seem to figure out how to calculate a comparable score.

thisandagain commented 7 years ago

This issue includes a thread that covers some of the areas you are asking about including how "comparative score" works and how to scale / offset it.

TL;DR: Tokens are scored between -5 (highly negative) and 5 (highly positive) with 0 being "neutral". Comparative scores are simply SUM(tokens) / number of tokens. Details can be found in the AFINN whitepaper: http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6010

Sorry that the docs don't make this more clear. I'll file an issue now to make sure I don't forget to improve them. 😄