-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyze_sentiment.py
53 lines (48 loc) · 1.09 KB
/
analyze_sentiment.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# -*- coding: utf-8 -*-
import json
import codecs
import sentiment_value
from sentiment_value import *
positive_count = 0
negative_count = 0
neutral_count = 0
def update(val) :
global positive_count
global negative_count
global neutral_count
if val == "negative" :
negative_count += 1
elif val == "positive" :
positive_count += 1
else :
neutral_count += 1
with codecs.open("/home/marta/Desktop/ED-projekt/refugges.json", "r", encoding='utf-8-sig') as tweets :
tweetes = tweets.readlines()
for tweet in tweetes :
tweet = json.loads(tweet)
text = tweet["text"]
if(tweet["lang"]=="en") :
words = sentiment_value.splitter(text)
sentiment = sentiment_value.count_sentiment(words)
update(sentiment)
print "positive: " + str(positive_count)
print "negative: " + str(negative_count)
print "neutral: " + str(neutral_count)
i = 0
lol = ""
while i <= positive_count :
lol += "|"
i += 1
print lol + " positive"
i = 0
lol = ""
while i <= negative_count :
lol += "|"
i += 1
print lol + " negative"
i = 0
lol = ""
while i <= neutral_count :
lol += "|"
i += 1
print lol + " neutral"