Exemple #1
0
        private SentimentAnalysisResults ScoreValence(IList <double> sentiments, string text)
        {
            if (sentiments.Count == 0)
            {
                return(new SentimentAnalysisResults()); //will return with all 0
            }
            double sum           = sentiments.Sum();
            double puncAmplifier = PunctuationEmphasis(text);

            sum += Math.Sign(sum) * puncAmplifier;

            double         compound = SentimentUtils.Normalize(sum);
            SiftSentiments sifted   = SiftSentimentScores(sentiments);

            if (sifted.PosSum > Math.Abs(sifted.NegSum))
            {
                sifted.PosSum += puncAmplifier;
            }
            else if (sifted.PosSum < Math.Abs(sifted.NegSum))
            {
                sifted.NegSum -= puncAmplifier;
            }

            double total = sifted.PosSum + Math.Abs(sifted.NegSum) + sifted.NeuCount;

            return(new SentimentAnalysisResults
            {
                Compound = Math.Round(compound, 4),
                Positive = Math.Round(Math.Abs(sifted.PosSum / total), 3),
                Negative = Math.Round(Math.Abs(sifted.NegSum / total), 3),
                Neutral = Math.Round(Math.Abs(sifted.NeuCount / total), 3)
            });
        }
Exemple #2
0
 public SentiText(string text)
 {
     //TODO: Encode in UTF-8 ?
     Text = text;
     WordsAndEmoticons = GetWordsAndEmoticons();
     IsCapDifferential = SentimentUtils.AllCapDifferential(WordsAndEmoticons);
 }
Exemple #3
0
        private IList <double> SentimentValence(double valence, SentiText sentiText, string item, int i, IList <double> sentiments)
        {
            string itemLowerCase = item.ToLower();

            if (!Lexicon.ContainsKey(itemLowerCase))
            {
                sentiments.Add(valence);
                return(sentiments);
            }
            bool           isCapDiff         = sentiText.IsCapDifferential;
            IList <string> wordsAndEmoticons = sentiText.WordsAndEmoticons;

            valence = Lexicon[itemLowerCase];
            if (isCapDiff && item.IsUpper())
            {
                if (valence > 0)
                {
                    valence += SentimentUtils.CIncr;
                }
                else
                {
                    valence -= SentimentUtils.CIncr;
                }
            }

            for (int startI = 0; startI < 3; startI++)
            {
                if (i > startI && !Lexicon.ContainsKey(wordsAndEmoticons[i - (startI + 1)].ToLower()))
                {
                    double s = SentimentUtils.ScalarIncDec(wordsAndEmoticons[i - (startI + 1)], valence, isCapDiff);
                    if (startI == 1 && s != 0)
                    {
                        s = s * 0.95;
                    }
                    if (startI == 2 && s != 0)
                    {
                        s = s * 0.9;
                    }
                    valence = valence + s;

                    valence = NeverCheck(valence, wordsAndEmoticons, startI, i);

                    if (startI == 2)
                    {
                        valence = IdiomsCheck(valence, wordsAndEmoticons, i);
                    }
                }
            }

            valence = LeastCheck(valence, wordsAndEmoticons, i);
            sentiments.Add(valence);
            return(sentiments);
        }
Exemple #4
0
        private double NeverCheck(double valence, IList <string> wordsAndEmoticons, int startI, int i)
        {
            if (startI == 0)
            {
                if (SentimentUtils.Negated(new List <string> {
                    wordsAndEmoticons[i - 1]
                }))
                {
                    valence = valence * SentimentUtils.NScalar;
                }
            }
            if (startI == 1)
            {
                if (wordsAndEmoticons[i - 2] == "never" &&
                    (wordsAndEmoticons[i - 1] == "so" || wordsAndEmoticons[i - 1] == "this"))
                {
                    valence = valence * 1.5;
                }
                else if (SentimentUtils.Negated(new List <string> {
                    wordsAndEmoticons[i - (startI + 1)]
                }))
                {
                    valence = valence * SentimentUtils.NScalar;
                }
            }
            if (startI == 2)
            {
                if (wordsAndEmoticons[i - 3] == "never" &&
                    (wordsAndEmoticons[i - 2] == "so" || wordsAndEmoticons[i - 2] == "this") ||
                    (wordsAndEmoticons[i - 1] == "so" || wordsAndEmoticons[i - 1] == "this"))
                {
                    valence = valence * 1.25;
                }
                else if (SentimentUtils.Negated(new List <string> {
                    wordsAndEmoticons[i - (startI + 1)]
                }))
                {
                    valence = valence * SentimentUtils.NScalar;
                }
            }

            return(valence);
        }