Spaces:
Running
Running
Download pyref.py from KRLabsOrg/rulechef-live: direct link, hf CLI and curl.
- Browser
- Download file 823 Bytes
-
https://huggingface.co/spaces/KRLabsOrg/rulechef-live/resolve/main/pyref.py
- Command line
-
hf download hf://spaces/KRLabsOrg/rulechef-live/pyref.py
-
curl -L -o pyref.py https://huggingface.co/spaces/KRLabsOrg/rulechef-live/resolve/main/pyref.py
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")) | |