Giter Club home page Giter Club logo

Comments (6)

thisandagain avatar thisandagain commented on May 20, 2024 4

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.

rickyplc avatar rickyplc commented on May 20, 2024

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.

thisandagain avatar thisandagain commented on May 20, 2024

(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.

rickyplc avatar rickyplc commented on May 20, 2024

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.

thisandagain avatar thisandagain commented on May 20, 2024

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.

rickyplc avatar rickyplc commented on May 20, 2024

Cool – thanks again!

from sentiment.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.