def tweet_connotation(tweet):
""" Decide whether a tweet is generally positive or negative """
anlyzr = SentimentIntensityAnalyzer()
# break tweet up into sentences and analyze each seperately
twtcontent = sent_tokenize(tweet)
overall = {'compound': 0, 'neg': 0, 'neu': 0, 'pos': 0}
for s in twtcontent:
scores = anlyzr.polarity_scores(s)
# tally up each sentence's overall tone
for i, z in enumerate(scores):
overall[z] += scores[z]
# average it all together for the tweet as a whole
for v in overall:
overall[v] = round(overall[v] / len(twtcontent), 3)
return overall
评论列表
文章目录