-
Notifications
You must be signed in to change notification settings - Fork 54
/
run_calcite_examples.py
41 lines (34 loc) · 1.26 KB
/
run_calcite_examples.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
"""
run calcite examples in batch
"""
import solver
import os.path
import json
import gen_cos_files
def run_calcite_examples(write=False):
""" run calcite examples """
calcite_path = "./examples/calcite/"
# get already generated rules, since some of them may be edited
generated_rules = {}
for filename in os.listdir(calcite_path):
if filename.endswith(".cos"):
case_name = filename[:-4]
with open(calcite_path+filename, 'r') as source_file:
cos = source_file.read()
generated_rules[case_name] = cos
# run all the rule from the json file
with open(calcite_path+'calcite_tests.json') as input_file:
calcite_rules = json.load(input_file)
for rule in calcite_rules:
rname = rule["name"]
if rname in generated_rules:
cos = generated_rules[rname]
else:
cos = gen_cos_files.gen_cos_source(rule["q1"], rule["q2"])
if write: # generate .cos file
with open("{}{}.cos".format(calcite_path, rname), 'w') as ofile:
ofile.write(cos)
result = json.loads(solver.solve(cos))
print "{},{}".format(rname, result["result"])
if __name__ == '__main__':
run_calcite_examples(write=True)