Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support smileys #132

Open
elyas-bhy opened this issue Feb 5, 2018 · 1 comment
Open

Support smileys #132

elyas-bhy opened this issue Feb 5, 2018 · 1 comment

Comments

@elyas-bhy
Copy link
Collaborator

elyas-bhy commented Feb 5, 2018

Currently we have no way of processing smileys since they are stripped away before analysis (in tokenize.js).
Such a feature serves the same purpose as supporting emojis.

For example, here is a non-exhaustive list of smileys:

  • :)
  • :(
  • :D
  • :-D
  • ;)
  • :p
@mathildebuenerd
Copy link

I did a function that does that

function getSmileys(sPhrase) {

    let inlineSmileys = new RegExp(/(<[\/\\]?3|[()/|*$][-^]?[:;=]|x[d()]|\^[a-z._-]{0,1}\^['"]{0,1}|[:;=B8][\-^]?[3DOPp@$*\\)(\/|])(?=\s|[!.?]|$)/, 'gim'); // detect smileys like :) ;) :p :/ =/ :-) :( :D xD :-) ^^

    const smileyValues = {
        ':)': 5,
        ';)': 5,
        ':(': -5,
        'x)': 5,
        ':p': 4,
        ':o': -2,
        ':3': -3,
        ':|': -4,
        ':/': -4,
        ':\\': -4,
        ':$': -3,
        ':*': 5,
        ':@': -3,
        ':-)': 5,
        ';-)': 5,
        ':-(': -5,
        ':-p': 4,
        ':-o': -2,
        ':-3': -3,
        ':-|': -4,
        ':-/': -4,
        ':-\\': -4,
        ':-$': -3,
        ':-*': 4,
        ':-@': -2,
        '(:': 5,
        '):': -5,
        '(x': 5,
        '$:': -3,
        '*:': 5,
        '/:': -4,
        '\\:': -4,
        '(-:': 5,
        ')-:': -5,
        '$-:': -3,
        '*-:': 5,
        '/-:': -4,
        '\\-:': -4,
        '<3': 5,
        '</3': -5,
        '<\\3': -5,
        '^^': 3,
        '^.^': 3,
        '^o^': 5,
        '^-^': 3,
        '^_^': 3,
        '^^"': -3,
        "^^'": -3,
        'xd': 4
    };

    let smileyArray;
    while ((smileyArray = inlineSmileys.exec(sentence.toLocaleLowerCase())) !== null) { // convert to lowercase for smileys like :s :S

        const smileyScore = smileyValues[smileyArray[0]]; // get the smiley score
        iGlobalScore += Number(smileyScore); // add the score to the global score

        // add the smiley into the positive/negative arrays
        if (smileyScore > 0) {
            aPositive.push(String(smileyArray[0]));
        } else {
            aNegative.push(String(smileyArray[0]));
        }
    }
}

It's better to call that function after the negation detection, because even in a sentence with a negation, a smiley like :) is still positive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants