def get_precision(topicid, docs): j = Judge() rels = [] for docno in docs: rel = j.check(topicid, docno) rels.append(rel) ndcg = get_ndcg(rels) return (sum(rels[:5]) / 5., sum(rels) /10., ndcg, rels)
#!/usr/bin/python import sys; sys.path.append("./common") from dbconfig import * from tdt4rel import Judge import MySQLdb, sys con = MySQLdb.connect(HOST, USER, PASS, DB) cur = con.cursor() N = cur.execute("select userid, action, info from history where action = 'reset_visualization' and userid like 'vs%-%'") j = Judge() recs = [] old_userid = "" for i, row in enumerate(cur): userid, action, info = row dim, pois, docs = info.split("\t") system, userno, topicid = userid.split("-") dimx, dimy = dim.split(":")[1].split(" ")[0].split(",") docs = docs.strip().split(":")[1].split(" ") isum = 0 for poi in pois.split(): try: label, value = poi.split(",") if int(value) > 0: isum = 1 break
#!/usr/bin/python import sys; sys.path.append("../common") from tdt4rel import Judge import MySQLdb j = Judge() con = MySQLdb.connect('localhost', 'root', '!!berkeley', 'yournews-tdt4') cur = con.cursor() cur.execute("select userid, object from history where action like 'open_doc%' and userid like 'vs%' and userid != 'vst'") for row in cur: userid, docid = row system, user, topic = userid.split("-") print system, user, topic, docid, j.check(topic, docid)
import MySQLdb, sys from tdt4rel import Judge con = MySQLdb.connect("localhost", "root", "!!berkeley", "yournews-tdt4") cur = con.cursor() def get_note(system, userno, topicid, note_no): cur.execute( "select nid, docid, note from notes where userid = '%s-%s-%s' order by nid asc" % (system, userno, topicid) ) nid, docid, note = cur.fetchall()[int(note_no) - 1] return (nid, docid, note) j = Judge() # f = open("user_notes_cleaned.txt") f = open("../../data/user_notes_cleaned.txt") counter = 1 print "sys userno topicid qno noteno noteid docno prec" for s in f: s = s.strip() system, userno, topicid, q, note_no = s.split() ## remove qustion mark if note_no[-1] == "?" or note_no[-1] == "!": note_no = note_no[:-1] if note_no == "":
#!/usr/bin/python from tdt4rel import Judge import MySQLdb, sys system = 'training' user = '******' topic = '40004' j = Judge() f = open("master_notes.txt", "a") con = MySQLdb.connect('localhost', 'root', '!!berkeley', 'yournews-tdt4') cur = con.cursor() n = cur.execute("select nid, userid, docid, note from notes where userid = 'vst' order by nid desc" ) counter = 1 res = [] for row in cur: nid, userid, docid, note = row note = note.replace("\r\n", " ") note = note.lower() precision = j.check_annotation('40004', docid, note) try: sys.stdout.write("%s %s %s %s %s %s\n" % (nid, system, user, topic, docid, precision[1])) #, note except: sys.stdout.write("%s %s %s %s %s error\n" % (nid, system, user, topic, docid))
#!/usr/bin/python from tdt4rel import Judge import MySQLdb import sys j = Judge() con = MySQLdb.connect('localhost', 'root', '!!berkeley', 'yournews-tdt4') cur = con.cursor() N=cur.execute("select datetime, userid, action, object, info from history where ((action like 'open_doc%' and info = 'from_VIBE') or action like 'reset_visualization%') and userid like 'vs%' and userid != 'vst' order by datetime") for row in cur: datetime, userid, action, docno, info = row system, user, topic = userid.split("-") if action.startswith('reset_visualization') : vis = {} visx = [] dim = info.split("\t")[0] docs = info.split("\t")[2] if len(docs) == 5: continue for doc in docs.split(): temp = doc.split(",") docid = temp[0]
#!/usr/bin/python import sys; sys.path.append("../common") from tdt4rel import Judge import MySQLdb def get_next_action(data, i): step = 1 while 1: action = data[i + step][2] if action not in ['focus_doc', 'select_doc']: return (data[i + step][0], action) step += 1 j = Judge() con = MySQLdb.connect('localhost', 'root', '!!berkeley', 'yournews-tdt4') cur = con.cursor() cur.execute("select unix_timestamp(datetime), userid, action, object from history where userid like 'vs%' and userid != 'vst' order by userid, datetime asc") data = cur.fetchall() um_on = 0 um_vis = 0 for i in range(len(data)): time, userid, action, docid = data[i] if action == 'open_doc':
#!/usr/bin/python import sys; sys.path.append("../common") from tdt4rel import Judge import MySQLdb j = Judge() con = MySQLdb.connect('localhost', 'root', '!!berkeley', 'yournews-tdt4') cur = con.cursor() q = """ select userid, action, object, info from history where action in ('open_doc', 'reset_visualization', 'response', 'save_note') and userid like 'vs%' and userid != 'vst' order by datetime asc """ cur.execute(q) page = 1 for row in cur: userid, action, obj, info = row system, userno, topicid = userid.split("-") if action == 'nav_page': page = int(info.split("=")[1]) if action == 'search': # reset page <= check again page = 1 if system == 'vsb' and action == 'response': docinfo = {} docs = info.split()[2:]