-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsentiment.py
31 lines (24 loc) · 869 Bytes
/
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
# This file is used to experiment with different sentiment analysis models and qualitatively evaluate them.
sentences = [
"I really do enjoy a good wine",
"I like to hate Michael Bay films, but I couldn't fault this one",
"This is at least as yummy as the cheese",
"This is the least yummy cheese"
]
import time
from textblob import TextBlob
from textblob.sentiments import NaiveBayesAnalyzer
from pattern.en import sentiment
for sentence in sentences:
print sentence + "\n****************"
# TextBlob
start = time.time()
blob = TextBlob(sentence, analyzer=NaiveBayesAnalyzer())
end = time.time()
print "TextBlob: " + str(blob.sentiment.p_pos) + "% positive (" + str(end - start) + ")"
# pattern.en
start = time.time()
s = sentiment(sentence)
end = time.time()
print "pattern.en: " + str(s[0]) + "% positive (" + str(end - start) + ")"
print "\n"