OSDN Git Service

implement bayeskey.
authorgn64_jp <gn64_jp@4e526526-5e11-4fc0-8910-f8fd03428081>
Tue, 10 Nov 2009 10:11:00 +0000 (10:11 +0000)
committergn64_jp <gn64_jp@4e526526-5e11-4fc0-8910-f8fd03428081>
Tue, 10 Nov 2009 10:11:00 +0000 (10:11 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/rec10@217 4e526526-5e11-4fc0-8910-f8fd03428081

rec10/trunk/src/dbMySQL.py
rec10/trunk/src/tester.py

index 7b4128f..4bb0871 100644 (file)
@@ -526,54 +526,56 @@ class DB_MySQL:
     def new_bayeskey(self):
         db = self.connect_db()
         try:
-            db[1].execute('\
-            CREATE TABLE bayeskey \
+            db[1].execute('CREATE TABLE bayeskey \
             (\
-            key VARCHAR(10),\
+            keychar VARCHAR(10),\
             chtxt VARCHAR(20),\
-            ratio_rec DECIMAL(24,8),\
-            ratio_all DECIMAL(24,8),\
+            ratio_rec DECIMAL(32,8),\
+            ratio_all DECIMAL(32,8)\
             )')
         except:
             ""
         self.close_db(db)
     def add_bayeskey(self,key,chtxt,ratio_rec,ratio_all):
         db = self.connect_db()
-        db[1].executemany('\
+        ratio_rec=str(ratio_rec)
+        ratio_all=str(ratio_all)
+        print (key,chtxt,ratio_rec,ratio_all)
+        db[1].execute('\
         INSERT IGNORE INTO bayeskey \
-        (key,chtxt,ratio_rec,ratio_all) \
-        values(%s,%s,%s,%s)',\
-                          (key,chtxt,ratio_rec,ratio_all))
+        (keychar,chtxt,ratio_rec,ratio_all) \
+        values (%s,%s,%s,%s)',\
+        (key,chtxt,ratio_rec,ratio_all))
         self.close_db(db)
     def change_bayeskey(self,key,chtxt,new_ratio_rec,new_ratio_all):
         """
-        statuをiだけ増減する
-        iはint
         """
         db = self.connect_db()
         db[1].execute("\
-        UPDATE bayeskey SET ratio_rec=%s,ratio_all=%s WHERE key=%s AND chtxt=%s",(new_ratio_rec,new_ratio_all,key,chtxt)\
+        UPDATE bayeskey SET ratio_rec=%s,ratio_all=%s WHERE keychar=%s AND chtxt=%s",(str(new_ratio_rec),str(new_ratio_all),key,chtxt)\
         )
         self.close_db(db)
     def change_ratio_all_bayeskey(self,chtxt,beforenum,newnum):
         db = self.connect_db()
         db[1].execute("\
-        UPDATE bayeskey SET ratio_all=ratio_all*%s/(%s+%s) WHERE chtxt=%s",(beforenum,newnum,beforenum,chtxt)\
+        UPDATE bayeskey SET ratio_all=ratio_all*%s/(%s+%s) WHERE chtxt=%s",(str(beforenum),str(newnum),str(beforenum),chtxt)\
         )
         self.close_db(db)
     def change_ratio_rec_bayeskey(self,key,chtxt,beforenum,addnum):
         db = self.connect_db()
+        beforenum=str(beforenum)
+        addnum=str(addnum)
         db[1].execute("\
-        UPDATE bayeskey SET ratio_rec=(ratio_rec*%s+%s)/%s WHERE chtxt=%s AND key=%s",\
+        UPDATE bayeskey SET ratio_rec=(ratio_rec*%s+%s)/%s WHERE chtxt=%s AND keychar=%s",\
         (beforenum,addnum,beforenum,chtxt,key)\
         )
         self.close_db(db)
     def select_by_key_bayeskey(self,chtxt,key):
         db = self.connect_db()
         dbexe = db[1].execute("\
-        SELECT key,chtxt,ratio_rec,ratio_all \
+        SELECT keychar,chtxt,ratio_rec,ratio_all \
         FROM bayeskey \
-        WHERE key = %s AND chtxt = %s", \
+        WHERE keychar = %s AND chtxt = %s", \
                               (key,chtxt))
         dls = []
         if dbexe > 0:
index c308d8a..90b53b0 100644 (file)
@@ -5,6 +5,7 @@
 #import sys
 #import os
 #import datetime
+import rec10d
 import os
 #import time
 import n_gram
@@ -60,4 +61,4 @@ if __name__ == "__main__":
     #doexe = configreader.getpath("tssplitter") + " \"" + "" + "\" \"" + "pout""" + "\" " + str(0)
     #doexe = "nice -n 18 " + doexe
     #print doexe
-    #print zenhan.check_Character_Type()
+    #print zenhan.check_Character_Type()
\ No newline at end of file