aboutsummaryrefslogtreecommitdiff
path: root/SentimentAnalyser.py
blob: ba415dc972e1bb72d28d33281c1a3ccfd200649c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from nltk.sentiment.vader import SentimentIntensityAnalyzer
from cassandra.cluster import Cluster
import re


compound = []
pos = []
neu = []
neg = []

def sentence_score(rs):
    review_score = SentimentIntensityAnalyzer()
    compound.append(review_score.polarity_scores(rs)['compound'])
    neg.append(review_score.polarity_scores(rs)['neg'])
    neu.append(review_score.polarity_scores(rs)['neu'])
    pos.append(review_score.polarity_scores(rs)['pos'])


cluster = Cluster()
session = cluster.connect('twitter')
rows = session.execute('SELECT tweet FROM twitterdata')
for tweet in rows:
    try:
        sentence_score(tweet)
    except re.error:
        print(tweet)