Beispiel #1
0
    path_wikisql0 = os.path.join(path_h, 'data/WikiSQL-1.1/data')
    path_source = os.path.join(path_wikisql0, f'{mode}.jsonl')
    path_db = os.path.join(path_wikisql0, f'{mode}.db')
    path_pred = os.path.join(path_save_analysis, f'results_{mode}.jsonl')

    # For the case when use "argument"
    parser = ArgumentParser()
    parser.add_argument('--source_file', help='source file for the prediction', default=path_source)
    parser.add_argument('--db_file', help='source database for the prediction', default=path_db)
    parser.add_argument('--pred_file', help='predictions by the model', default=path_pred)
    parser.add_argument('--ordered', action='store_true',
                        help='whether the exact match should consider the order of conditions')
    args = parser.parse_args()
    args.ordered = ordered

    engine = DBEngine(args.db_file)
    exact_match = []
    with open(args.source_file) as fs, open(args.pred_file) as fp:
        grades = []
        for ls, lp in tqdm(zip(fs, fp), total=count_lines(args.source_file)):
            eg = json.loads(ls)
            ep = json.loads(lp)
            qg = Query.from_dict(eg['sql'], ordered=args.ordered)
            gold = engine.execute_query(eg['table_id'], qg, lower=True)
            pred = ep.get('error', None)
            qp = None
            if not ep.get('error', None):
                try:
                    qp = Query.from_dict(ep['query'], ordered=args.ordered)
                    pred = engine.execute_query(eg['table_id'], qp, lower=True)
                except Exception as e:
Beispiel #2
0
import extract
from tqdm import tqdm
import json
import sys, os
from wikisql.lib.dbengine import DBEngine
from wikisql.lib.query import Query
from sqlnet.dbengine import DBEngine as DBEngine_s
from copy import deepcopy
import eventlet
from IPython import embed

root = '/mnt/sda/qhz/sqlova'
query_path = os.path.join(root, 'data_and_model', 'train_tok_origin.jsonl')
table_path = os.path.join(root, 'data_and_model', 'train.tables.jsonl')
queries = extract.read_queries(query_path)
engine = DBEngine_s('./data_and_model/train.db')
engine1 = DBEngine('./data_and_model/train.db')
sql = {"sel": 9, "conds": [[3, 1, 8793], [5, 2, 1030]], "agg": 2}
qg = Query.from_dict(sql, ordered=True)
res = engine.execute_query(queries[15841]['table_id'], qg, lower=True)
print(res)