more docs and start of knn with python mysql

This commit is contained in:
Dan Ballard 2013-01-11 22:41:48 -05:00
parent 0eea55bcad
commit 580dafac54
2 changed files with 12 additions and 1 deletions

View File

@ -50,7 +50,7 @@ class NGramSet:
def print_mysql(self):
table_name = re.sub('[^A-Za-z0-9]', '_', "%s_%d" % (self.filename, self.gram_size))
print "DROP TABLE IF EXISTS %s;" % (table_name)
print "CREATE TABLE %s (gram VARCHAR(255), count INT, percent FLOAT, PRIMARY KEY(gram));" % (table_name)
print "CREATE TABLE %s (gram VARCHAR(255), count INT DEFAULT 0, percent FLOAT DEFAULT 0.0, PRIMARY KEY(gram));" % (table_name)
for key in self.gram_set:
print "INSERT INTO %s VALUES (\"%s\", %d, %f);" % (table_name, key, self.gram_set[key]['count'], self.gram_set[key]['percent'])

11
knn.py Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/python
import sys
import re
import _mysql
# http://mysql-python.sourceforge.net/MySQLdb.html
db = _mysql.connect('localhost', 'gramificate', 'asdfasdf', 'grams')
db.query('SHOW TABLES')
r = db.store_result()