-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBayesTwitter.py
54 lines (44 loc) · 1.26 KB
/
BayesTwitter.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
46
47
48
49
50
51
52
53
54
from OpenGL.GLUT import *
from OpenGL.GLU import *
from OpenGL.GL import *
from face import Face
from calculation import *
from BayesSentiment import *
class BayesFace(Face):
def __init__(self, choose):
self.stream = tweetFilter('SentimentTest', 'passwd')
self.tweet = None
self.bayes = BayesSentiment()
if choose == "raw":
self.classifier = self.bayes.getRawClassifier()
else:
self.classifier = self.bayes.getClassifer()
def idleFunc(self):
try:
newTweet = self.stream.next()
self.tweet = self.bayes.rawClassify(newTweet)
if self.tweet != None:
glutPostRedisplay()
except Exception as e:
print(e)
return
def drawScene(self):
glMatrixMode(GL_MODELVIEW)
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
glPushMatrix()
#glScalef(.2, .2, .2)
#glRotatef(90, 0, 0, 1)
glRasterPos2f(-0.5,1)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, ord(':'))
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, ord('-'))
if self.tweet[0] == "positive":
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, ord(')'))
else:
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, ord('('))
glPopMatrix()
if self.tweet != None:
self.printText(self.tweet[1])
glFlush()
glutSwapBuffers()
if __name__ == "__main__":
BayesFace().main()