Comments (6)
The comparative score is simply: sum of each token / number of tokens
. So for example let's take the following:
I love cats, but I am allergic to them.
That string results in the following:
{
score: 1,
comparative: 0.1111111111111111,
tokens: [
'i',
'love',
'cats',
'but',
'i',
'am',
'allergic',
'to',
'them'
],
words: [
'allergic',
'love'
],
positive: [
'love'
],
negative: [
'allergic'
]
}
Each token has a range between 5
(positive) and -5
(negative). In this case, love
has a value of 3
, allergic
has a value of -2
, and the remaining tokens are neutral with a value of 0
. Because the string has 9
tokens the resulting comparative score looks like:
(3 + -2) / 9 = 0.111111111
This approach leaves you with a mid-point of 0
and the upper and lower bounds are constrained to positive and negative 5
respectively (the same as each token! 😸). For example, let's imagine an incredibly "positive" string with 200 tokens and where each token has an AFINN score of 5
. Our resulting comparative score would look like this:
(max positive score * number of tokens) / number of tokens
(5 * 200) / 200 = 5
So – to answer your question – you can scale and offset the comparative score (x
) however you like using simple arithmetic. For example:
Scale from 0 to 100
(x + 5) * 10
from sentiment.
Thank you very much! That was both fast and precisely detailed 👍.
And just so that I am clear. Taking the example you gave "I love cats, but I am allergic to them." would be:
Scale from 0 to 100
(x + max AFINN value) * 10
(0.1111111111111111+5)*10
And the value I am after would be 51.11%.
Where 5 would be the maximum AFINN value. Or is there a way to compute this value (max AFINN value) for all comparative scores?
from sentiment.
(0.1111111111111111+5)*10
Yes. That's correct. The maximum AFINN value is always 5
. To compute this you could do something like:
function scale (score) {
return (score + 5) * 100;
}
var result = scale(sentiment('I like cats').comparative);
but I would recommend diving into JS to get a better sense of the possibilities:
http://jsforcats.com/
https://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742
from sentiment.
Ahh yes, Mr Crockford (read that one already :)). Your awesome thanks! I will be able to build out the functionality, I'm not to shabby at Javascript.
And that function will work for all possibilities, including negatives, and neutral values?
from sentiment.
And that function will work for all possibilities, including negatives, and neutral values?
Yup. You can give it a try yourself to see how it works in all scenarios.
from sentiment.
Cool – thanks again!
from sentiment.
Related Issues (20)
- Bundle for browser usage? HOT 4
- Support smileys HOT 1
- Replace makefile with npm scripts
- Update code formatting HOT 2
- Please document the max range of each value HOT 9
- Support overwriting emoji HOT 2
- Code Coverage Badge HOT 1
- Provide calculation used to calculate score HOT 2
- Feature Request: DefinitelyTyped typescript definitions HOT 2
- Can this run in the browser? HOT 2
- inflected words and adjectives in other languages.
- want compiled score for array of phrases
- Support for 2-grams HOT 1
- Improvements inspired by VADER
- Escape question marks along with other forms of punctuations HOT 1
- All the messages are getting logged HOT 3
- Inverse words if not HOT 6
- Can someone recommend any learning resources? HOT 2
- is the comparitive number between -1 and 1? HOT 2
- Why didn't you use the full range of emotions in the original NRC dictionary?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sentiment.