def dbwrite(p,x1,x2): try : connection = MySQLdb.connect('localhost', 'root', 'kgggdkp2692', 'mining') except Exception as e : connection =None print "Unable to connect :" + str(e) x = connection.cursor() try: q= "INSERT INTO `data_new` (`path`,`topic`,`data`) VALUES ('"+str(p)+"','"+json.dumps(x1).replace('\'', '\\\'')+"','"+json.dumps(x2).replace('\'', '\\\'')+"')" x.execute(q) connection.commit() except Exception as e : print e connection.rollback() connection.close()
'education' : [], 'religion' : [], 'health' : [], } data_counts= { 'entertain' :0, 'politics' :0, 'econonics' :0, 'sports' :0, 'education' :0, 'religion' :0, 'health' :0, } cursor = connection.cursor() query = "SELECT * FROM `data_new` WHERE `dp` <> 'Null' " cursor.execute(query) data = cursor.fetchall () count = 0 #Divide data assuming each belongs to single category for row in data : cat = json.loads(row[2])[0] data_set[cat].append(row) #Append data_counts[cat] += 1 for type in TYPES: for t in TYPES: for i in range(3, 11): true_cases = 0.0
import os, json from lib.mysql import connection MODEL_DIR = "models/" cursor = connection.cursor() data_model = json.load(open(MODEL_DIR + "words.json", 'r')) md_model = json.load(open(MODEL_DIR + "meta.json", 'r')) query = "SELECT * from `data_mail` limit 3000,1000" cursor.execute(query) rows = cursor.fetchall() for row in rows: data = json.loads(row[2]) meta = json.loads(row[3]) weight = 0 for word in data: try: weight += data_model[word] except: pass for md in meta: try: weight += 10 * md_model[md] except: pass print weight