rulechef-live / pyref.py
adaamko's picture
Restore the static page (no cpu-basic quota for Gradio)
27e064c verified
Raw History Blame Contribute Delete
823 Bytes
"""Python reference for the browser port: per version, RuleChef executor output (trusted rules and all rules) + gate verdict."""
import json, sys
import cascade as C
R = json.load(open(sys.argv[1])); reqs = [json.loads(l) for l in open(sys.argv[2])]
out = []
for v in R["versions"][1:]:
tr = C.rules_from_dicts([r["dict"] for r in v["rules"] if r["trusted"]])
al = C.rules_from_dicts([r["dict"] for r in v["rules"]])
g = C.Gate(v["gate"]["trigger_words"], v["gate"]["skip"])
rows = {}
for r in reqs:
a = C.run_rules(tr, r["text"]); b = C.run_rules(al, r["text"])
rows[r["id"]] = [[[s["start"], s["end"], s["type"], s["text"]] for s in a], [[s["start"], s["end"], s["type"], s["text"]] for s in b], g.unexplained(r["text"], a)]
out.append(rows)
json.dump(out, open(sys.argv[3], "w"))