-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsentAnalysisManual.py
39 lines (30 loc) · 1.02 KB
/
sentAnalysisManual.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
from textblob import TextBlob
from textblob.classifiers import NaiveBayesClassifier
import glob
import json
files = glob.glob('./SearchEngine/*.txt')
classification = open("classificationManual.json", "w")
games = []
with open('test.csv', 'r') as fp:
cl = NaiveBayesClassifier(fp, format="csv")
for file in files:
with open(file) as f:
lines = [line.rstrip('\n') for line in f]
polarity = 0
subjectivity = 0
counter = 0
for line in lines:
tb = TextBlob(line, classifier=cl)
prob_dist = cl.prob_classify(tb)
posProb = round(prob_dist.prob("pos"), 2)
polarity = polarity + posProb
counter = counter + 1
gameName = file.replace("./SearchEngine/", "")
gameName = gameName.replace(".txt", "")
newLine = {
'name': gameName,
'count': counter,
'polarity': polarity/counter
}
games.append(newLine)
classification.write(json.dumps(games))