From bea259da7cf4219c5b81b081a5d45fb6664eef0d Mon Sep 17 00:00:00 2001 From: jmreddy2106 Date: Sat, 25 Dec 2021 15:07:36 -0500 Subject: Added sentiment analyser --- SentimentAnalyser.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 SentimentAnalyser.py diff --git a/SentimentAnalyser.py b/SentimentAnalyser.py new file mode 100644 index 0000000..ba415dc --- /dev/null +++ b/SentimentAnalyser.py @@ -0,0 +1,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) \ No newline at end of file -- cgit v1.2.3