def updateSentiment(dbLoc, tableName):
sid = SentimentIntensityAnalyzer()
conn = sqlite3.connect(dbLoc)
cursor = conn.execute("SELECT * from %s" % tableName)
# Go through every sentence
for row in cursor:
text = cleanTweet(row[TWEET_INDEX])
#blob = TextBlob(text)
sent = 0.0
count = 0
sentList = tokenize.sent_tokenize(text)
# Go through each sentence in tweet
for sentence in sentList:
count += 1
ss = sid.polarity_scores(sentence)
sent += ss['compound'] # Tally up the overall sentiment
if count != 0:
sent = float(sent / count)
# Update into DB
conn.execute("UPDATE " + tableName + " set SENTIMENT = ? where ID = ?", \
(sent, row[ID_INDEX]))
conn.commit()
conn.close()
评论列表
文章目录