示例#1
0
 def test_weirdness(self):
     """avg. sentiment issues with this approach"""
     afinn = Afinn("AFINN-111.txt")
     ratings = afinn.get_ratings_map()
     ssc = Ssc(ratings)
     ssc_values = ssc.compute("catastrophic frauds are funny lmao")
     self.assertTrue(ssc_values.positive_avg == 4)
     self.assertTrue(ssc_values.negative_avg == -4)
     self.assertTrue(ssc_values.overall_sentiment == "neutral")
示例#2
0
 def test_compute(self):
     """compute avg. sentiment for some text"""
     afinn = Afinn("AFINN-111.txt")
     ratings = afinn.get_ratings_map()
     ssc = Ssc(ratings)
     ssc_values = ssc.compute("Rainy day but still in a good mood")
     self.assertTrue(ssc_values.positive_pct == 12.5)
     self.assertTrue(ssc_values.negative_pct == 12.5)
     self.assertTrue(ssc_values.positive_avg == 3)
     self.assertTrue(ssc_values.negative_avg == -1)
     self.assertTrue(ssc_values.overall_sentiment == "positive")
示例#3
0
from main.afinn import Afinn
from main.ssc import Ssc
from main.util import Util

if __name__ == '__main__':
    util = Util()

    user_text = util.get_input()
    all_words = util.get_tokens(user_text)
    lc_words = map(str.lower, all_words)
    filtered_words = util.filter_alnum(lc_words)

    print "Number of words: %s" % len(filtered_words)

    freq = util.get_word_frequencies(filtered_words)

    print "Count of unique words: %s" % len(freq)
    print "Word frequencies:"
    for k, v in freq.iteritems():
        print k, v

    lang, conf = langid.classify(user_text)
    print "Detected language: %s" % lang

    afinn = Afinn("AFINN-111.txt")
    ratings = afinn.get_ratings_map()
    ssc = Ssc(ratings)
    ssc_values = ssc.compute(user_text)
    print "average sentiment is " + ssc_values.overall_sentiment