-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyntax_compare.py
59 lines (53 loc) · 2.12 KB
/
syntax_compare.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import db_connector
import get_all_codex_queries_from_sqlite_db as get_codex
import pandas as pd
codex_df = get_codex.as_dataframe(include_translated=True)
spider_root = "//192.168.1.17/data/nl_benchmarks/spider/"
codex_db_con = db_connector.sqlite_connector('./codex_queries.sqlite')
try:
codex_db_con.do_query("drop table syntactic_evaluation")
except:
pass
codex_db_con.do_query("""
create table if not exists syntactic_evaluation(
query_id INT,
comparison_type VARCHAR(64),
is_match VARCHAR(64),
result_reason VARCHAR(256),
primary key(query_id, comparison_type)
);
""")
def record_evaluation(
db_con,
query_id,
comparison_type,
is_match,
result_reason
):
db_con.do_query("""
insert into syntactic_evaluation(query_id, comparison_type, is_match, result_reason)
values ({}, '{}', '{}', '{}')
""".format(str(query_id), comparison_type, is_match, result_reason))
codex_df = codex_df.replace({None : ''})
for row in codex_df.itertuples():
print(len(row.gold_translated), len(row.codex_translated))
if row.gold_translated == row.codex_translated:
record_evaluation(
codex_db_con, row.query_id, 'db2_translate', 'TRUE', 'translated query match'
)
elif len(row.gold_translated) == 0 and len(row.codex_translated) > 0:
record_evaluation(
codex_db_con, row.query_id, 'db2_translate', 'UNDETERMINED', 'failed db2 gold translation'
)
elif len(row.codex_translated) == 0 and len(row.gold_translated) > 0:
record_evaluation(
codex_db_con, row.query_id, 'db2_translate', 'UNDETERMINED', 'failed db2 codex translation'
)
elif len(row.codex_translated) == 0 and len(row.gold_translated) == 0:
record_evaluation(
codex_db_con, row.query_id, 'db2_translate', 'UNDETERMINED', 'failed db2 codex and gold translations'
)
elif (len(row.gold_translated) > 0 and len(row.codex_translated) > 0) and row.gold_translated != row.codex_translated:
record_evaluation(
codex_db_con, row.query_id, 'db2_translate', 'FALSE', 'translated queries do not match'
)