Spaces:
Running on Zero

word-problem-reader / tools /test_mixer.py
Bigbearbo's picture
Model layer: #348 per-sentence mix (取代守門 keep, 31 allowed constructions, spaCy en_core_web_sm)
eef10ae verified
Raw History Blame Contribute Delete
1.21 kB
# -*- coding: utf-8 -*-
"""The Space's mixer.py (hs/ copy + pickled reader) must give the same mixed replies as tools/mix_replies.py on the
team folder. Also lists any file opened outside the Space folder (should be none besides Python / spaCy).
python -B tools/test_mixer.py fixture.json mixed_ref.json"""
import json
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
OPENED = set()
def hook(ev, args):
if ev == "open" and isinstance(args[0], str):
OPENED.add(args[0])
sys.addaudithook(hook)
sys.path.insert(0, str(ROOT))
import pipeline # noqa: E402
import mixer # noqa: E402
pipeline.init()
fx = json.load(open(sys.argv[1], encoding="utf-8"))
ref = {r["id"]: r for r in json.load(open(sys.argv[2], encoding="utf-8"))}
diff, nrep = [], 0
for t in fx:
text, per = mixer.mix(t["q"], t["reply"])
nrep += sum(p["來源"] == "程式" for p in per)
if text != ref[t["id"]]["mixed_reply"]:
diff.append(t["id"])
outside = sorted(p for p in OPENED if p.startswith(("H:", "h:")) and not p.startswith(str(ROOT)))
print("題", len(fx), "程式取代句", nrep, "與團隊版不同", diff)
print("開到 Space 資料夾外的檔:", outside[:20])