def run(self): config = { 'user': '******', 'passwd': 'RDKC1VlNyLSg', 'host': '127.7.115.1', 'db': 'backup' } self.cnx = MySQLdb.connect(**config) logging.info("Classifying For %s." % self.Company) neg_count = 0 pos_count = 0 try: if (self.cnx == None): self.cnx = MySQLdb.connect(**config) d = datetime.datetime.today() america = timezone('America/New_York') india = timezone('Asia/Kolkata') dd = america.localize(d) dd = dd.astimezone(india) get_tweet = "select * from tweets_" + self.Company + " where sentiment!=1" cur = self.cnx.cursor() cur.execute(get_tweet) db_tweets = cur.fetchall() for line in db_tweets: value = PyClassi.classify(line[1], self.Company) if value == 0: neg_count += 1 elif value == 2: pos_count += 1 update = "update tweets_" + self.Company + " set classified=" + str( value) + " where id=" + str(line[0]) cur.execute(update) sen_value = float(pos_count) / neg_count add_Stock = "INSERT ignore INTO bay_%s VALUES (%s,%s)" cur.execute(add_Stock % (self.Company, "'" + str(sen_value) + "'", "'" + dd.strftime('%Y-%m-%d') + "'")) self.cnx.commit() except Exception as e: logging.info(self.Company + "Error : " + str(type(e)) + str(e)) else: logging.info(self.Company + "Bayesian value Added To Database For %s." % self.Company) self.cnx.close()
def run(self): config = {'user': '******','passwd': 'RDKC1VlNyLSg','host': '127.7.115.1','db': 'backup'} self.cnx = MySQLdb.connect(**config) logging.info("Classifying For %s."%self.Company) neg_count=0 pos_count=0 try: if(self.cnx==None): self.cnx = MySQLdb.connect(**config) d = datetime.datetime.today() america=timezone('America/New_York') india=timezone('Asia/Kolkata') dd=america.localize(d) dd=dd.astimezone(india) get_tweet = "select * from tweets_"+self.Company+" where sentiment!=1" cur=self.cnx.cursor() cur.execute(get_tweet) db_tweets = cur.fetchall() for line in db_tweets: value=PyClassi.classify(line[1],self.Company) if value==0: neg_count+=1 elif value==2: pos_count+=1 update="update tweets_"+self.Company+" set classified="+str(value)+" where id="+str(line[0]) cur.execute(update) sen_value=float(pos_count)/neg_count add_Stock = "INSERT ignore INTO bay_%s VALUES (%s,%s)" cur.execute(add_Stock%(self.Company,"'"+str(sen_value)+"'","'"+dd.strftime('%Y-%m-%d')+"'")) self.cnx.commit() except Exception as e : logging.info(self.Company+"Error : "+str(type(e))+str(e)) else : logging.info(self.Company+"Bayesian value Added To Database For %s."%self.Company) self.cnx.close()
#! /usr/bin/python import PyClassi as Classifier from re import sub import PyNegator test=open("test.txt") correct=0 wrong=0 falsepositive=0 falsenegative=0 for line in test.readlines(): status=line[0] lne=sub(r"[!]|[.]|[#][^ ]+|[&]|[-]|[?]|[_]|((http|https)://)[^ ]+|\w*[@][^ ]+|\b[\S0-9]\b",'',line.lower()) classi=Classifier.classify(lne) if status=='0': #polarity representation reversed for database representation sake :-/ if classi==status: correct+=1 else: falsepositive+=1 wrong+=1 elif status=='1': if classi==status: correct+=1 else: falsenegative+=1 wrong+=1 print "Correct : ",correct,"\n Wrong : ",wrong,"\n falsenegative : ",falsenegative,"\n falsepositive",falsepositive print "\n ratio : ",(float(correct)/(correct+wrong))*100