def main(dic, keyword2): #print dic keyword1 = u"\u6881\u535a" dic[keyword2.decode("utf-8")] = dic[keyword1] dic.pop(keyword1) keylist1 = kuworank.main(keyword1.encode("utf-8")) keylist2 = kuworank.main(keyword2) pr = trans(dic, keylist1, keylist2) return pr
def main(): keyword = "梁博" songlist = kuworank.main(keyword) editDict(songlist) P_HT, P_MT, P_H, P_M, hsum, msum, store = init(keyword, songlist) # Store the probability calculated. xmlOperation.create_xml(P_HT, "music_HT_dict.xml"); xmlOperation.create_xml({'hits':P_H}, "music_H_dict.xml"); xmlOperation.create_xml(P_MT, "music_MT_dict.xml"); xmlOperation.create_xml({'miss':P_M}, "music_M_dict.xml"); xmlOperation.create_xml(store, "store.xml"); ''' con = dbconf.dbconfig() conn = MySQLdb.connect(host=con[0], user=con[1], passwd=con[2]) conn.select_db("ai_hw") cursor = conn.cursor() P_HT = get_xml_data("music_HT_dict.xml") P_H = get_xml_data("music_H_dict.xml") P_MT = get_xml_data("music_MT_dict.xml") P_M = get_xml_data("music_M_dict.xml") ''' ''' lines = readFile("testFile.txt") resList = [] hl = [] ml = [] for line in lines: tokens = segword(line) hitP = hitProbability(tokens, P_HT) * P_H missP = missProbability(tokens, P_MT) * P_M print hitP, missP if missP < hitP: resList.append(line) hl.append(line) else: ml.append(line) writeFile([str(len(lines))+"\n", len(resList)], "result.txt") writeFile(hl, "result_hits.txt") writeFile(ml, "result_miss.txt") ''' '''
def main(): f = open("names.txt", 'r') lines = f.readlines() for line in lines: kuworank.main(line.strip())