code stringlengths 17 6.64M |
|---|
def expand_snippets(sequence, snippets):
' Given a sequence and a list of snippets, expand the snippets in the sequence.\n\n Inputs:\n sequence (list of str): Query containing snippet references.\n snippets (list of Snippet): List of available snippets.\n\n return list of str representing the ... |
def snippet_index(token):
' Returns the index of a snippet.\n\n Inputs:\n token (str): The snippet to check.\n\n Returns:\n integer, the index of the snippet.\n '
assert is_snippet(token)
return int(token.split('_')[(- 1)])
|
class Snippet():
' Contains a snippet. '
def __init__(self, sequence, startpos, sql, age=0):
self.sequence = sequence
self.startpos = startpos
self.sql = sql
self.age = age
self.index = 0
self.name = ''
self.embedding = None
self.endpos = (self.... |
def strip_whitespace_front(token_list):
new_token_list = []
found_valid = False
for token in token_list:
if ((not (token.is_whitespace or (token.ttype == token_types.Punctuation))) or found_valid):
found_valid = True
new_token_list.append(token)
return new_token_list
|
def strip_whitespace(token_list):
subtokens = strip_whitespace_front(token_list)
subtokens = strip_whitespace_front(subtokens[::(- 1)])[::(- 1)]
return subtokens
|
def token_list_to_seq(token_list):
subtokens = strip_whitespace(token_list)
seq = []
flat = sqlparse.sql.TokenList(subtokens).flatten()
for (i, token) in enumerate(flat):
strip_token = str(token).strip()
if (len(strip_token) > 0):
seq.append(strip_token)
if (len(seq) > ... |
def find_subtrees(sequence, current_subtrees, where_parent=False, keep_conj_subtrees=False):
if where_parent:
seq = token_list_to_seq(sequence.tokens[1:])
if ((len(seq) > 0) and (seq not in current_subtrees)):
current_subtrees.append(seq)
if sequence.is_group:
if keep_conj_... |
def get_subtrees(sql, oldsnippets=[]):
parsed = sqlparse.parse(' '.join(sql))[0]
subtrees = []
find_subtrees(parsed, subtrees)
final_subtrees = []
for subtree in subtrees:
if (subtree not in ignored_subtrees):
final_version = []
keep = True
parens_counts... |
def get_subtrees_simple(sql, oldsnippets=[]):
sql_string = ' '.join(sql)
format_sql = sqlparse.format(sql_string, reindent=True)
subtrees = []
for sub_sql in format_sql.split('\n'):
sub_sql = sub_sql.replace('(', ' ( ').replace(')', ' ) ').replace(',', ' , ')
subtree = sub_sql.strip().... |
def get_all_in_parens(sequence):
if (sequence[(- 1)] == ';'):
sequence = sequence[:(- 1)]
if (not ('(' in sequence)):
return []
if ((sequence[0] == '(') and (sequence[(- 1)] == ')')):
in_parens = sequence[1:(- 1)]
return ([in_parens] + get_all_in_parens(in_parens))
else... |
def split_by_conj(sequence):
num_parens = 0
current_seq = []
subsequences = []
for token in sequence:
if (num_parens == 0):
if (token in conjunctions):
subsequences.append(current_seq)
current_seq = []
break
current_seq.append... |
def get_sql_snippets(sequence):
all_in_parens = get_all_in_parens(sequence)
all_subseq = []
for seq in all_in_parens:
subsequences = split_by_conj(seq)
all_subseq.append(seq)
all_subseq.extend(subsequences)
for (i, seq) in enumerate(all_subseq):
print(((str(i) + '\t') +... |
def add_snippets_to_query(snippets, ignored_entities, query, prob_align=1.0):
query_copy = copy.copy(query)
sorted_snippets = sorted(snippets, key=(lambda s: len(s.sequence)))[::(- 1)]
for snippet in sorted_snippets:
ignore = False
snippet_seq = snippet.sequence
for entity in ignor... |
def execution_results(query, username, password, timeout=3):
connection = pymysql.connect(user=username, password=password)
class TimeoutException(Exception):
pass
def timeout_handler(signum, frame):
raise TimeoutException
signal.signal(signal.SIGALRM, timeout_handler)
syntactic ... |
def executable(query, username, password, timeout=2):
return execution_results(query, username, password, timeout)[1]
|
def fix_parentheses(sequence):
num_left = sequence.count('(')
num_right = sequence.count(')')
if (num_right < num_left):
fixed_sequence = ((sequence[:(- 1)] + [')' for _ in range((num_left - num_right))]) + [sequence[(- 1)]])
return fixed_sequence
return sequence
|
def nl_tokenize(string):
'Tokenizes a natural language string into tokens.\n\n Inputs:\n string: the string to tokenize.\n Outputs:\n a list of tokens.\n\n Assumes data is space-separated (this is true of ZC07 data in ATIS2/3).\n '
return nltk.word_tokenize(string)
|
def sql_tokenize(string):
' Tokenizes a SQL statement into tokens.\n\n Inputs:\n string: string to tokenize.\n\n Outputs:\n a list of tokens.\n '
tokens = []
statements = sqlparse.parse(string)
for statement in statements:
flat_tokens = sqlparse.sql.TokenList(statement.tok... |
def lambda_tokenize(string):
' Tokenizes a lambda-calculus statement into tokens.\n\n Inputs:\n string: a lambda-calculus string\n\n Outputs:\n a list of tokens.\n '
space_separated = string.split(' ')
new_tokens = []
for token in space_separated:
tokens = []
curre... |
def subsequence(first_sequence, second_sequence):
'\n Returns whether the first sequence is a subsequence of the second sequence.\n\n Inputs:\n first_sequence (list): A sequence.\n second_sequence (list): Another sequence.\n\n Returns:\n Boolean indicating whether first_sequence is a... |
class Utterance():
' Utterance class. '
def process_input_seq(self, anonymize, anonymizer, anon_tok_to_ent):
assert ((not anon_tok_to_ent) or anonymize)
assert ((not anonymize) or anonymizer)
if anonymize:
assert anonymizer
self.input_seq_to_use = anonymizer.an... |
class Vocabulary():
'Vocabulary class: stores information about words in a corpus.\n\n Members:\n functional_types (list of str): Functional vocabulary words, such as EOS.\n max_size (int): The maximum size of vocabulary to keep.\n min_occur (int): The minimum number of times a word should... |
def condition_has_or(conds):
return ('or' in conds[1::2])
|
def condition_has_like(conds):
return (WHERE_OPS.index('like') in [cond_unit[1] for cond_unit in conds[::2]])
|
def condition_has_sql(conds):
for cond_unit in conds[::2]:
(val1, val2) = (cond_unit[3], cond_unit[4])
if ((val1 is not None) and (type(val1) is dict)):
return True
if ((val2 is not None) and (type(val2) is dict)):
return True
return False
|
def val_has_op(val_unit):
return (val_unit[0] != UNIT_OPS.index('none'))
|
def has_agg(unit):
return (unit[0] != AGG_OPS.index('none'))
|
def accuracy(count, total):
if (count == total):
return 1
return 0
|
def recall(count, total):
if (count == total):
return 1
return 0
|
def F1(acc, rec):
if ((acc + rec) == 0):
return 0
return (((2.0 * acc) * rec) / (acc + rec))
|
def get_scores(count, pred_total, label_total):
if (pred_total != label_total):
return (0, 0, 0)
elif (count == pred_total):
return (1, 1, 1)
return (0, 0, 0)
|
def eval_sel(pred, label):
pred_sel = pred['select'][1]
label_sel = label['select'][1]
label_wo_agg = [unit[1] for unit in label_sel]
pred_total = len(pred_sel)
label_total = len(label_sel)
cnt = 0
cnt_wo_agg = 0
for unit in pred_sel:
if (unit in label_sel):
cnt += ... |
def eval_where(pred, label):
pred_conds = [unit for unit in pred['where'][::2]]
label_conds = [unit for unit in label['where'][::2]]
label_wo_agg = [unit[2] for unit in label_conds]
pred_total = len(pred_conds)
label_total = len(label_conds)
cnt = 0
cnt_wo_agg = 0
for unit in pred_cond... |
def eval_group(pred, label):
pred_cols = [unit[1] for unit in pred['groupBy']]
label_cols = [unit[1] for unit in label['groupBy']]
pred_total = len(pred_cols)
label_total = len(label_cols)
cnt = 0
pred_cols = [(pred.split('.')[1] if ('.' in pred) else pred) for pred in pred_cols]
label_col... |
def eval_having(pred, label):
pred_total = label_total = cnt = 0
if (len(pred['groupBy']) > 0):
pred_total = 1
if (len(label['groupBy']) > 0):
label_total = 1
pred_cols = [unit[1] for unit in pred['groupBy']]
label_cols = [unit[1] for unit in label['groupBy']]
if ((pred_total =... |
def eval_order(pred, label):
pred_total = label_total = cnt = 0
if (len(pred['orderBy']) > 0):
pred_total = 1
if (len(label['orderBy']) > 0):
label_total = 1
if ((len(label['orderBy']) > 0) and (pred['orderBy'] == label['orderBy']) and (((pred['limit'] is None) and (label['limit'] is N... |
def eval_and_or(pred, label):
pred_ao = pred['where'][1::2]
label_ao = label['where'][1::2]
pred_ao = set(pred_ao)
label_ao = set(label_ao)
if (pred_ao == label_ao):
return (1, 1, 1)
return (len(pred_ao), len(label_ao), 0)
|
def get_nestedSQL(sql):
nested = []
for cond_unit in ((sql['from']['conds'][::2] + sql['where'][::2]) + sql['having'][::2]):
if (type(cond_unit[3]) is dict):
nested.append(cond_unit[3])
if (type(cond_unit[4]) is dict):
nested.append(cond_unit[4])
if (sql['intersect'... |
def eval_nested(pred, label):
label_total = 0
pred_total = 0
cnt = 0
if (pred is not None):
pred_total += 1
if (label is not None):
label_total += 1
if ((pred is not None) and (label is not None)):
cnt += Evaluator().eval_exact_match(pred, label)
return (label_total... |
def eval_IUEN(pred, label):
(lt1, pt1, cnt1) = eval_nested(pred['intersect'], label['intersect'])
(lt2, pt2, cnt2) = eval_nested(pred['except'], label['except'])
(lt3, pt3, cnt3) = eval_nested(pred['union'], label['union'])
label_total = ((lt1 + lt2) + lt3)
pred_total = ((pt1 + pt2) + pt3)
cnt... |
def get_keywords(sql):
res = set()
if (len(sql['where']) > 0):
res.add('where')
if (len(sql['groupBy']) > 0):
res.add('group')
if (len(sql['having']) > 0):
res.add('having')
if (len(sql['orderBy']) > 0):
res.add(sql['orderBy'][0])
res.add('order')
if (sq... |
def eval_keywords(pred, label):
pred_keywords = get_keywords(pred)
label_keywords = get_keywords(label)
pred_total = len(pred_keywords)
label_total = len(label_keywords)
cnt = 0
for k in pred_keywords:
if (k in label_keywords):
cnt += 1
return (label_total, pred_total, ... |
def count_agg(units):
return len([unit for unit in units if has_agg(unit)])
|
def count_component1(sql):
count = 0
if (len(sql['where']) > 0):
count += 1
if (len(sql['groupBy']) > 0):
count += 1
if (len(sql['orderBy']) > 0):
count += 1
if (sql['limit'] is not None):
count += 1
if (len(sql['from']['table_units']) > 0):
count += (le... |
def count_component2(sql):
nested = get_nestedSQL(sql)
return len(nested)
|
def count_others(sql):
count = 0
agg_count = count_agg(sql['select'][1])
agg_count += count_agg(sql['where'][::2])
agg_count += count_agg(sql['groupBy'])
if (len(sql['orderBy']) > 0):
agg_count += count_agg(([unit[1] for unit in sql['orderBy'][1] if unit[1]] + [unit[2] for unit in sql['ord... |
class Evaluator():
'A simple evaluator'
def __init__(self):
self.partial_scores = None
def eval_hardness(self, sql):
count_comp1_ = count_component1(sql)
count_comp2_ = count_component2(sql)
count_others_ = count_others(sql)
if ((count_comp1_ <= 1) and (count_othe... |
def isValidSQL(sql, db):
conn = sqlite3.connect(db)
cursor = conn.cursor()
try:
cursor.execute(sql)
except:
return False
return True
|
def print_scores(scores, etype):
levels = ['easy', 'medium', 'hard', 'extra', 'all']
partial_types = ['select', 'select(no AGG)', 'where', 'where(no OP)', 'group(no Having)', 'group', 'order', 'and/or', 'IUEN', 'keywords']
print('{:20} {:20} {:20} {:20} {:20} {:20}'.format('', *levels))
counts = [scor... |
def evaluate(gold, predict, db_dir, etype, kmaps):
with open(gold) as f:
glist = [l.strip().split('\t') for l in f.readlines() if (len(l.strip()) > 0)]
with open(predict) as f:
plist = [l.strip().split('\t') for l in f.readlines() if (len(l.strip()) > 0)]
evaluator = Evaluator()
levels... |
def eval_exec_match(db, p_str, g_str, pred, gold):
'\n return 1 if the values between prediction and gold are matching\n in the corresponding index. Currently not support multiple col_unit(pairs).\n '
conn = sqlite3.connect(db)
cursor = conn.cursor()
try:
cursor.execute(p_str)
... |
def rebuild_cond_unit_val(cond_unit):
if ((cond_unit is None) or (not DISABLE_VALUE)):
return cond_unit
(not_op, op_id, val_unit, val1, val2) = cond_unit
if (type(val1) is not dict):
val1 = None
else:
val1 = rebuild_sql_val(val1)
if (type(val2) is not dict):
val2 = ... |
def rebuild_condition_val(condition):
if ((condition is None) or (not DISABLE_VALUE)):
return condition
res = []
for (idx, it) in enumerate(condition):
if ((idx % 2) == 0):
res.append(rebuild_cond_unit_val(it))
else:
res.append(it)
return res
|
def rebuild_sql_val(sql):
if ((sql is None) or (not DISABLE_VALUE)):
return sql
sql['from']['conds'] = rebuild_condition_val(sql['from']['conds'])
sql['having'] = rebuild_condition_val(sql['having'])
sql['where'] = rebuild_condition_val(sql['where'])
sql['intersect'] = rebuild_sql_val(sql[... |
def build_valid_col_units(table_units, schema):
col_ids = [table_unit[1] for table_unit in table_units if (table_unit[0] == TABLE_TYPE['table_unit'])]
prefixs = [col_id[:(- 2)] for col_id in col_ids]
valid_col_units = []
for value in schema.idMap.values():
if (('.' in value) and (value[:value.... |
def rebuild_col_unit_col(valid_col_units, col_unit, kmap):
if (col_unit is None):
return col_unit
(agg_id, col_id, distinct) = col_unit
if ((col_id in kmap) and (col_id in valid_col_units)):
col_id = kmap[col_id]
if DISABLE_DISTINCT:
distinct = None
return (agg_id, col_id, ... |
def rebuild_val_unit_col(valid_col_units, val_unit, kmap):
if (val_unit is None):
return val_unit
(unit_op, col_unit1, col_unit2) = val_unit
col_unit1 = rebuild_col_unit_col(valid_col_units, col_unit1, kmap)
col_unit2 = rebuild_col_unit_col(valid_col_units, col_unit2, kmap)
return (unit_op... |
def rebuild_table_unit_col(valid_col_units, table_unit, kmap):
if (table_unit is None):
return table_unit
(table_type, col_unit_or_sql) = table_unit
if isinstance(col_unit_or_sql, tuple):
col_unit_or_sql = rebuild_col_unit_col(valid_col_units, col_unit_or_sql, kmap)
return (table_type,... |
def rebuild_cond_unit_col(valid_col_units, cond_unit, kmap):
if (cond_unit is None):
return cond_unit
(not_op, op_id, val_unit, val1, val2) = cond_unit
val_unit = rebuild_val_unit_col(valid_col_units, val_unit, kmap)
return (not_op, op_id, val_unit, val1, val2)
|
def rebuild_condition_col(valid_col_units, condition, kmap):
for idx in range(len(condition)):
if ((idx % 2) == 0):
condition[idx] = rebuild_cond_unit_col(valid_col_units, condition[idx], kmap)
return condition
|
def rebuild_select_col(valid_col_units, sel, kmap):
if (sel is None):
return sel
(distinct, _list) = sel
new_list = []
for it in _list:
(agg_id, val_unit) = it
new_list.append((agg_id, rebuild_val_unit_col(valid_col_units, val_unit, kmap)))
if DISABLE_DISTINCT:
dist... |
def rebuild_from_col(valid_col_units, from_, kmap):
if (from_ is None):
return from_
from_['table_units'] = [rebuild_table_unit_col(valid_col_units, table_unit, kmap) for table_unit in from_['table_units']]
from_['conds'] = rebuild_condition_col(valid_col_units, from_['conds'], kmap)
return fr... |
def rebuild_group_by_col(valid_col_units, group_by, kmap):
if (group_by is None):
return group_by
return [rebuild_col_unit_col(valid_col_units, col_unit, kmap) for col_unit in group_by]
|
def rebuild_order_by_col(valid_col_units, order_by, kmap):
if ((order_by is None) or (len(order_by) == 0)):
return order_by
(direction, val_units) = order_by
new_val_units = [rebuild_val_unit_col(valid_col_units, val_unit, kmap) for val_unit in val_units]
return (direction, new_val_units)
|
def rebuild_sql_col(valid_col_units, sql, kmap):
if (sql is None):
return sql
sql['select'] = rebuild_select_col(valid_col_units, sql['select'], kmap)
sql['from'] = rebuild_from_col(valid_col_units, sql['from'], kmap)
sql['where'] = rebuild_condition_col(valid_col_units, sql['where'], kmap)
... |
def build_foreign_key_map(entry):
cols_orig = entry['column_names_original']
tables_orig = entry['table_names_original']
cols = []
for col_orig in cols_orig:
if (col_orig[0] >= 0):
t = tables_orig[col_orig[0]]
c = col_orig[1]
cols.append((((('__' + t.lower()... |
def build_foreign_key_map_from_json(table):
with open(table) as f:
data = json.load(f)
tables = {}
for entry in data:
tables[entry['db_id']] = build_foreign_key_map(entry)
return tables
|
def condition_has_or(conds):
return ('or' in conds[1::2])
|
def condition_has_like(conds):
return (WHERE_OPS.index('like') in [cond_unit[1] for cond_unit in conds[::2]])
|
def condition_has_sql(conds):
for cond_unit in conds[::2]:
(val1, val2) = (cond_unit[3], cond_unit[4])
if ((val1 is not None) and (type(val1) is dict)):
return True
if ((val2 is not None) and (type(val2) is dict)):
return True
return False
|
def val_has_op(val_unit):
return (val_unit[0] != UNIT_OPS.index('none'))
|
def has_agg(unit):
return (unit[0] != AGG_OPS.index('none'))
|
def accuracy(count, total):
if (count == total):
return 1
return 0
|
def recall(count, total):
if (count == total):
return 1
return 0
|
def F1(acc, rec):
if ((acc + rec) == 0):
return 0
return (((2.0 * acc) * rec) / (acc + rec))
|
def get_scores(count, pred_total, label_total):
if (pred_total != label_total):
return (0, 0, 0)
elif (count == pred_total):
return (1, 1, 1)
return (0, 0, 0)
|
def eval_sel(pred, label):
pred_sel = pred['select'][1]
label_sel = label['select'][1]
label_wo_agg = [unit[1] for unit in label_sel]
pred_total = len(pred_sel)
label_total = len(label_sel)
cnt = 0
cnt_wo_agg = 0
for unit in pred_sel:
if (unit in label_sel):
cnt += ... |
def eval_where(pred, label):
pred_conds = [unit for unit in pred['where'][::2]]
label_conds = [unit for unit in label['where'][::2]]
label_wo_agg = [unit[2] for unit in label_conds]
pred_total = len(pred_conds)
label_total = len(label_conds)
cnt = 0
cnt_wo_agg = 0
for unit in pred_cond... |
def eval_group(pred, label):
pred_cols = [unit[1] for unit in pred['groupBy']]
label_cols = [unit[1] for unit in label['groupBy']]
pred_total = len(pred_cols)
label_total = len(label_cols)
cnt = 0
pred_cols = [(pred.split('.')[1] if ('.' in pred) else pred) for pred in pred_cols]
label_col... |
def eval_having(pred, label):
pred_total = label_total = cnt = 0
if (len(pred['groupBy']) > 0):
pred_total = 1
if (len(label['groupBy']) > 0):
label_total = 1
pred_cols = [unit[1] for unit in pred['groupBy']]
label_cols = [unit[1] for unit in label['groupBy']]
if ((pred_total =... |
def eval_order(pred, label):
pred_total = label_total = cnt = 0
if (len(pred['orderBy']) > 0):
pred_total = 1
if (len(label['orderBy']) > 0):
label_total = 1
if ((len(label['orderBy']) > 0) and (pred['orderBy'] == label['orderBy']) and (((pred['limit'] is None) and (label['limit'] is N... |
def eval_and_or(pred, label):
pred_ao = pred['where'][1::2]
label_ao = label['where'][1::2]
pred_ao = set(pred_ao)
label_ao = set(label_ao)
if (pred_ao == label_ao):
return (1, 1, 1)
return (len(pred_ao), len(label_ao), 0)
|
def get_nestedSQL(sql):
nested = []
for cond_unit in ((sql['from']['conds'][::2] + sql['where'][::2]) + sql['having'][::2]):
if (type(cond_unit[3]) is dict):
nested.append(cond_unit[3])
if (type(cond_unit[4]) is dict):
nested.append(cond_unit[4])
if (sql['intersect'... |
def eval_nested(pred, label):
label_total = 0
pred_total = 0
cnt = 0
if (pred is not None):
pred_total += 1
if (label is not None):
label_total += 1
if ((pred is not None) and (label is not None)):
cnt += Evaluator().eval_exact_match(pred, label)
return (label_total... |
def eval_IUEN(pred, label):
(lt1, pt1, cnt1) = eval_nested(pred['intersect'], label['intersect'])
(lt2, pt2, cnt2) = eval_nested(pred['except'], label['except'])
(lt3, pt3, cnt3) = eval_nested(pred['union'], label['union'])
label_total = ((lt1 + lt2) + lt3)
pred_total = ((pt1 + pt2) + pt3)
cnt... |
def get_keywords(sql):
res = set()
if (len(sql['where']) > 0):
res.add('where')
if (len(sql['groupBy']) > 0):
res.add('group')
if (len(sql['having']) > 0):
res.add('having')
if (len(sql['orderBy']) > 0):
res.add(sql['orderBy'][0])
res.add('order')
if (sq... |
def eval_keywords(pred, label):
pred_keywords = get_keywords(pred)
label_keywords = get_keywords(label)
pred_total = len(pred_keywords)
label_total = len(label_keywords)
cnt = 0
for k in pred_keywords:
if (k in label_keywords):
cnt += 1
return (label_total, pred_total, ... |
def count_agg(units):
return len([unit for unit in units if has_agg(unit)])
|
def count_component1(sql):
count = 0
if (len(sql['where']) > 0):
count += 1
if (len(sql['groupBy']) > 0):
count += 1
if (len(sql['orderBy']) > 0):
count += 1
if (sql['limit'] is not None):
count += 1
if (len(sql['from']['table_units']) > 0):
count += (le... |
def count_component2(sql):
nested = get_nestedSQL(sql)
return len(nested)
|
def count_others(sql):
count = 0
agg_count = count_agg(sql['select'][1])
agg_count += count_agg(sql['where'][::2])
agg_count += count_agg(sql['groupBy'])
if (len(sql['orderBy']) > 0):
agg_count += count_agg(([unit[1] for unit in sql['orderBy'][1] if unit[1]] + [unit[2] for unit in sql['ord... |
class Evaluator():
'A simple evaluator'
def __init__(self):
self.partial_scores = None
def eval_hardness(self, sql):
count_comp1_ = count_component1(sql)
count_comp2_ = count_component2(sql)
count_others_ = count_others(sql)
if ((count_comp1_ <= 1) and (count_othe... |
def isValidSQL(sql, db):
conn = sqlite3.connect(db)
cursor = conn.cursor()
try:
cursor.execute(sql)
except:
return False
return True
|
def print_scores(scores, etype):
turns = ['turn 1', 'turn 2', 'turn 3', 'turn 4', 'turn >4']
levels = ['easy', 'medium', 'hard', 'extra', 'all', 'joint_all']
partial_types = ['select', 'select(no AGG)', 'where', 'where(no OP)', 'group(no Having)', 'group', 'order', 'and/or', 'IUEN', 'keywords']
print(... |
def evaluate(gold, predict, db_dir, etype, kmaps):
with open(gold) as f:
glist = []
gseq_one = []
for l in f.readlines():
if (len(l.strip()) == 0):
glist.append(gseq_one)
gseq_one = []
else:
lstrip = l.strip().split('\... |
def eval_exec_match(db, p_str, g_str, pred, gold):
'\n return 1 if the values between prediction and gold are matching\n in the corresponding index. Currently not support multiple col_unit(pairs).\n '
conn = sqlite3.connect(db)
cursor = conn.cursor()
try:
cursor.execute(p_str)
... |
def rebuild_cond_unit_val(cond_unit):
if ((cond_unit is None) or (not DISABLE_VALUE)):
return cond_unit
(not_op, op_id, val_unit, val1, val2) = cond_unit
if (type(val1) is not dict):
val1 = None
else:
val1 = rebuild_sql_val(val1)
if (type(val2) is not dict):
val2 = ... |
def rebuild_condition_val(condition):
if ((condition is None) or (not DISABLE_VALUE)):
return condition
res = []
for (idx, it) in enumerate(condition):
if ((idx % 2) == 0):
res.append(rebuild_cond_unit_val(it))
else:
res.append(it)
return res
|
def rebuild_sql_val(sql):
if ((sql is None) or (not DISABLE_VALUE)):
return sql
sql['from']['conds'] = rebuild_condition_val(sql['from']['conds'])
sql['having'] = rebuild_condition_val(sql['having'])
sql['where'] = rebuild_condition_val(sql['where'])
sql['intersect'] = rebuild_sql_val(sql[... |
def build_valid_col_units(table_units, schema):
col_ids = [table_unit[1] for table_unit in table_units if (table_unit[0] == TABLE_TYPE['table_unit'])]
prefixs = [col_id[:(- 2)] for col_id in col_ids]
valid_col_units = []
for value in schema.idMap.values():
if (('.' in value) and (value[:value.... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.