private SentimentAnalysisResults ScoreValence(List <double> sentiments, SentiText text) { if (sentiments.Count == 0) { return(new SentimentAnalysisResults()); //will return with all 0 } var sum = sentiments.Sum(); var puncAmplifier = PunctuationEmphasis(text.Text); sum += Math.Sign(sum) * puncAmplifier; var compound = SentimentUtils.Normalize(sum); var sifted = SiftSentimentScores(sentiments); if (sifted.PosSum > Math.Abs(sifted.NegSum)) { sifted.PosSum += puncAmplifier; } else if (sifted.PosSum < Math.Abs(sifted.NegSum)) { sifted.NegSum -= puncAmplifier; } var 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) }); }
private double NeverCheck(double valence, List <string> lowerCaseWordsAndEmoticons, int startI, int i) { if (startI == 0) { if (SentimentUtils.Negated(new List <string> { lowerCaseWordsAndEmoticons[i - 1] })) { valence = valence * SentimentUtils.NScalar; } } if (startI == 1) { if (lowerCaseWordsAndEmoticons[i - 2] == "never" && (lowerCaseWordsAndEmoticons[i - 1] == "so" || lowerCaseWordsAndEmoticons[i - 1] == "this")) { valence = valence * 1.5; } else if (SentimentUtils.Negated(new List <string> { lowerCaseWordsAndEmoticons[i - (startI + 1)] })) { valence = valence * SentimentUtils.NScalar; } } if (startI == 2) { if (lowerCaseWordsAndEmoticons[i - 3] == "never" && (lowerCaseWordsAndEmoticons[i - 2] == "so" || lowerCaseWordsAndEmoticons[i - 2] == "this") || lowerCaseWordsAndEmoticons[i - 1] == "so" || lowerCaseWordsAndEmoticons[i - 1] == "this") { valence = valence * 1.25; } else if (SentimentUtils.Negated(new List <string> { lowerCaseWordsAndEmoticons[i - (startI + 1)] })) { valence = valence * SentimentUtils.NScalar; } } return(valence); }
private List <double> SentimentValence(double valence, SentiText sentiText, string word, string lowerCaseWord, int i, List <double> sentiments) { if (!Lexicon.ContainsKey(lowerCaseWord)) { sentiments.Add(valence); return(sentiments); } var isCapDiff = sentiText.IsCapDifferential; // adjust if shouting valence = Lexicon[lowerCaseWord]; if (isCapDiff && word.IsUpper()) { if (valence > 0) { valence += SentimentUtils.CIncr; } else { valence -= SentimentUtils.CIncr; } } for (var startI = 0; startI < 3 && i > startI; startI++) { var offset = i - (startI + 1); var lcWord = sentiText.WordsAndEmoticonsLowerCase[offset]; if (Lexicon.ContainsKey(lcWord)) { continue; } var s = SentimentUtils.ScalarIncDec(lcWord, sentiText.WordsAndEmoticons[offset], valence, isCapDiff); if (startI == 1 && !s.Equals(0)) { s = s * 0.95; } if (startI == 2 && !s.Equals(0)) { s = s * 0.9; } valence = valence + s; valence = NeverCheck(valence, sentiText.WordsAndEmoticonsLowerCase, startI, i); if (startI == 2) { valence = IdiomsCheck(valence, sentiText.WordsAndEmoticonsLowerCase, i); } } valence = LeastCheck(valence, sentiText.WordsAndEmoticonsLowerCase, i); sentiments.Add(valence); return(sentiments); }