-
Notifications
You must be signed in to change notification settings - Fork 3
/
sent.py
45 lines (41 loc) · 1.1 KB
/
sent.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
import nltk
from nltk import *
import trainWords
from trainWords import negwords
from trainWords import poswords
from textblob import TextBlob
from textblob.classifiers import NaiveBayesClassifier
import getCompList
from getCompList import *
from nltk.corpus import stopwords
import re
#cl = NaiveBayesClassifier(trainwords)
fg=open('AllSents','w')
for cname in compDict.keys():
name = compDict[cname]
compfile = 'NewsData/'+name+'.txt'
sentfile = 'SentData/'+name+'_sent.txt'
fh=open(compfile,'r')
lines = fh.readlines()
sum=0
for line in lines:
#fg.write(cl.classify(line)+'\n')
line = re.sub('\n','', line.rstrip())
line = re.sub('\.','', line.rstrip())
line = re.sub(',','', line.rstrip())
line = re.sub(':','', line.rstrip())
line = re.sub('\'','', line.rstrip())
words = line.split(' ')
for word in words:
word = word.upper()
print word
if word in negwords:
sum = sum - 1;
if word in poswords:
sum = sum + 1;
fg.write(name+','+str(sum)+';')
#blob = TextBlob(line,
# classifier=cl)
#for sentence in blob.sentences:
# print(sentence)
# print(sentence.classify())