forked from UCSD-PL/proverbot9001
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort_explored_states.py
49 lines (40 loc) · 1.43 KB
/
sort_explored_states.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
#!/usr/bin/env python3
import json
import argparse
import sys
from typing import Dict
from pathlib import Path
from tqdm import tqdm
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("-o", "--outfile", default="-")
parser.add_argument("input_file", type=Path)
parser.add_argument("-v", "--verbose", dest="verbosity", action='count', default=0)
args = parser.parse_args()
entries: Dict[str, Dict[str, List[List[str]]]] = {}
with args.input_file.open("r") as f:
for idx, line in enumerate(tqdm(f)):
try:
entry = json.loads(line)
except json.decoder.JSONDecodeError:
if args.verbosity > 0:
print(f"Ignoring incomplete entry {repr(line)} at line {idx+1}")
continue
if not entry["Module/Section"] in entries:
entries[entry["Module/Section"]] = {}
if not entry["Proof"] in entries[entry["Module/Section"]]:
entries[entry["Module/Section"]][entry["Proof"]] = []
entries[entry["Module/Section"]][entry["Proof"]].append(entry["Tactics"])
if args.outfile == "-":
f = sys.stdout
else:
f = open(args.outfile, 'w')
for sm_prefix, proofs in entries.items():
for proof, tactics in proofs.items():
print(json.dumps({"Module/Section": sm_prefix,
"Proof": proof,
"Tactic Traces": tactics}), file=f)
if args.outfile != "-":
f.close()
if __name__ == "__main__":
main()