-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
52 lines (38 loc) · 1.04 KB
/
Copy pathmain.py
File metadata and controls
52 lines (38 loc) · 1.04 KB
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
import string
import matplotlib.pyplot as plt
# reading text file
text = open("read.txt", encoding="utf-8").read()
# converting to lowercase
lower_case = text.lower()
# remove punctuations
cleaned_text = lower_case.translate(str.maketrans('', '', string.punctuation))
# tokenize words
tokenized_words = cleaned_text.split()
# get stopwords
stopwords = set(open("stopwords.txt", 'r').read().split('\n'))
# get pos words
positive = set(open("positive.txt", 'r').read().split('\n'))
# get pos words
negative = set(open("negative.txt", 'r').read().split('\n'))
# remove stopwords
final_words = []
for word in tokenized_words:
if word not in stopwords:
final_words.append(word)
# get score
POS = NEG = 0
for i in tokenized_words:
if(i in positive):
POS += 1
elif(i in negative):
NEG += 1
fig, ax1 = plt.subplots()
ax1.bar(['Positive', 'Negative'], [POS, NEG])
fig.autofmt_xdate()
if(POS > NEG):
print("Positive Sentiment")
elif(POS < NEG):
print("Negative Sentiment")
else:
print("Neutral Sentiment")
plt.show()