Esempio n. 1
0
def clear():
    connection = db_tools.connect()
    tables = ['Users', 'Forums', 'Threads', 'Posts', 'Follow', 'Subscribe']
    db_tools.execute(connection, "SET global foreign_key_checks = 1;")
    for table in tables:
        query = "TRUNCATE TABLE %s;" % table
        db_tools.execute(connection, query)
    db_tools.execute(connection, "SET global foreign_key_checks = 1;")
    connection.close()
    return jsonify({"code": STATUS_CODE['OK'], "response": 'OK'})
Esempio n. 2
0
def clear():
    connection = db_tools.connect()
    tables = ['Users', 'Forums', 'Threads', 'Posts', 'Follow', 'Subscribe']
    db_tools.execute(connection, "SET global foreign_key_checks = 1;")
    for table in tables:
        query = "TRUNCATE TABLE %s;" % table
        db_tools.execute(connection, query)
    db_tools.execute(connection, "SET global foreign_key_checks = 1;")
    connection.close()
    return jsonify({"code": STATUS_CODE['OK'], "response": 'OK'})
def get_data():
    x_feats = 7
    y_feats = 1

    connection = db_tools.connect()
    cur = connection.cursor()

    # get number of rows so training array can be built
    cur.execute("SELECT count(id) FROM answers")

    data = cur.fetchone()
    num_rows = data[0]

    build_X = np.ndarray(shape=(num_rows,x_feats), dtype=float, order='C')
    build_y = np.ndarray(shape=(num_rows,), dtype=float, order='C')

    # get all data necessary to train
    cur.execute("SELECT body,score,commcount,bodysentipolarity,bodysentisubjectivity, links, promptness, acceptedanswer FROM answers")

    x_indx = 0
    y_indx = 0
    while True:
        data = cur.fetchone()
        if data == None:
            break

        body = data[0]
        bodylen = len(body)
        score = data[1]
        commcount = data[2]
        sentipolarity = data[3]
        sentisubjectivity = data[4]
        links = data[5]
        promptness = data[6]
        acceptedanswer = data[7]
        if acceptedanswer == None:
            aa = 0
        else:
            aa = 1

        np.put(build_X, [range(x_indx,x_indx + x_feats)], [bodylen,score,commcount,sentipolarity,sentisubjectivity,links,promptness]) #bodylen,score,commcount,sentipolarity,sentisubjectivity,links,promptness
        np.put(build_y, [range(y_indx,y_indx + y_feats)], [aa])

        x_indx += x_feats
        y_indx += y_feats

    return build_X, build_y
def get_data():
    connection = db_tools.connect()
    cur = connection.cursor()

    q_group = question_group()
    master_map = defaultdict(int)

    # get all data necessary to train
    cur.execute("SELECT body,score,commcount,bodysentipolarity,bodysentisubjectivity,links,promptness,acceptedanswer,pid,id FROM answers")

    while True:
        data = cur.fetchone()
        if data == None:
            break

        q_id = data[8]
        if master_map[q_id] == 0:
            master_map[q_id] = [q_group.build_object(data)]
        else:
            master_map[q_id].append(q_group.build_object(data))

    #print master_map
    #print "\n\n\n\n\n\n"
    return master_map
Esempio n. 5
0
        elem.clear()

        while elem.getprevious() is not None:
            del elem.getparent()[0]

if __name__=='__main__':
    # DATASET MUST BE IN SOURCE FOLDER WITHIN A FOLDER CALLED 'datasets'
    static_path = os.getcwd()
    users = static_path+'/../datasets/Users.xml'
    posts = static_path+'/../datasets/Posts.xml'

    # connect to the dataset
    context = etree.iterparse(posts)


    # connect to the database
    print("Connecting to DB")
    connection = db_tools.connect()
    print("Setting up DB (if necessary)")
    db_tools.setup_db(connection)




    print("Populating DB")
    fast_iter(context, connection, limit=10000)

    connection.close()
    del context
Esempio n. 6
0
#coding:utf-8
import sys
import string
import db_tools
from bson.son import SON

mydb=db_tools.connect()
items=mydb.service.find({})
for item in items:
    print item['rating'].encode('utf-8')
'''
r=mydb.command(SON([('geoNear', 'service'), ('near', [116.34, 39.99]), ('spherical', True), ('num', 1000), ('distanceMultiplier', 6378137), ('maxDistance', 5000.0/6378137), ('query', {'category': '搬家'})]))
for item in r['results']:
    obj=item['obj']
    print obj['telephone']
'''