forked from iamprerit/TwitterSentimentAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extBlkFeat.py
25 lines (25 loc) · 844 Bytes
/
extBlkFeat.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
import extarctFeatures
import preprocessTweets
import nltk
def extBlk(filename):
whole=extarctFeatures.extFeat("traindata1.csv")
tweets=whole[1]
training_set=nltk.classify.util.apply_features(extract_features,tweets)
NBClassifier=nltk.NaiveBayesClassifier.train(training_set)
f1=open(filename)
f2=open('finalResults.txt','w')
for x in f1.readlines():
testTweet = x
processedTestTweet=preprocessTweets.processTweet(testTweet)
res=NBClassifier.classify(extract_features(extarctFeatures.getFeatures(processedTestTweet)))
f2.write(x+' '+res+'\n')
f1.close()
f2.close()
def extract_features(tweet):
tot=extarctFeatures.extFeat("traindata1.csv")
featureList=tot[0]
tweet_words = set(tweet)
features = {}
for word in featureList:
features['contains(%s)' % word] = (word in tweet_words)
return features