def read_specific_question_from_post(id):
    con = mdb.connect('localhost', 'root', '123456', 'answerbot')
    cur = con.cursor()
    sql = "SELECT * FROM posts WHERE Id=" + str(id)
    try:
        cur.execute(sql)
        results = cur.fetchall()
        for row in results:
            # id,title,body,tag
            q_tmp = SO_Que()
    except Exception as e:
        print e
    cur.close()
    con.close()
    return q_tmp
def read_questions_from_repo(num):
    sql = 'SELECT * FROM answerbot.repo WHERE PostTypeId=1 limit 0,' + str(num)
    SO_datalist = []
    con = mdb.connect('localhost', 'root', '123456', 'answerbot')
    cur = con.cursor()
    try:
        cur.execute(sql)
        results = cur.fetchall()
        count = 0
        for row in results:
            count += 1
            # id,type,title,title_NO_SW,title_NO_SW_Stem,tag
            q_tmp = SO_Que(row[0], row[1], row[2], row[3], row[4], row[5])
            SO_datalist.append(q_tmp)
    except Exception as e:
        print e
    cur.close()
    con.close()
    return SO_datalist
def read_all_questions_from_repo():
    sql = 'SELECT * FROM repo_qs'
    SO_datalist = []
    con = mdb.connect('localhost', 'root', '123456', 'answerbot')
    cur = con.cursor()
    try:
        cur.execute(sql)
        results = cur.fetchall()
        count = 0
        for row in results:
            count += 1
            # id,title,body,tag
            q_tmp = SO_Que(row[0], row[1], row[2], row[3])
            SO_datalist.append(q_tmp)
    except Exception as e:
        print e
    cur.close()
    con.close()
    return SO_datalist
def read_all_questions_from_post():
    sql = 'SELECT * FROM posts where Tags like \'%<java>%\' and AnswerCount > 0'
    SO_datalist = []
    con = mdb.connect('localhost', 'root', '123456', 'answerbot')
    cur = con.cursor()
    try:
        cur.execute(sql)
        results = cur.fetchall()
        count = 0
        for row in results:
            count += 1
            # id,type,title,title_NO_SW,title_NO_SW_Stem,tag
            q_tmp = SO_Que(row[0], row[1], row[2], row[3], row[4], row[5])
            SO_datalist.append(q_tmp)
    except Exception as e:
        print e
    cur.close()
    con.close()
    return SO_datalist
Beispiel #5
0
def read_questions_from_java():
    sql = 'SELECT * FROM answerbot.java_qs;'
    con = mdb.connect('localhost', 'root', '123456', 'answerbot')
    cur = con.cursor()
    qlist = []
    cur.execute(sql)
    results = cur.fetchall()
    count = 0
    for row in results:
        count += 1
        # id,title,body,tag
        q_tmp = SO_Que(row[0], row[11], row[6], row[12])
        q_tmp = preprocessing_for_que(q_tmp)
        qlist.append(q_tmp)
        if len(qlist) % 10000 == 0:
            print 'Load %s questions...' % len(qlist)
    cur.close()
    con.close()
    return qlist
def read_q_list_from_java(id_list):
    qlist = []
    con = mdb.connect('localhost', 'root', '123456', 'answerbot')
    cur = con.cursor()
    count = 1
    for qid in id_list:
        sql = "SELECT * FROM java_qs WHERE Id = %s" % qid[0]
        try:
            cur.execute(sql)
            results = cur.fetchall()
            row = results[0]
            # id,title,body,tags
            qlist.append(SO_Que(row[0], row[11], row[6], row[12]))
            count += 1
            if count % 1000 == 0:
                print 'reading ' + str(count) + ' question from Table java_qs'
        except Exception as e:
            print e
    cur.close()
    con.close()
    return qlist