Files
bid-doctor/evals/check/export_rewrite.py

34 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""导出风格 B 改写的输入:从风格 A 的投标文件稿里取出要改写的表格行(evals/check/prompts/style-B.md)。
cd server && ../.venv/bin/python ../evals/check/export_rewrite.py <招标文件> [...]
输出:evals/out/check/<招标文件>-B/rewrite-input.json(数组,字段 key、requirement、answer)。
"""
from __future__ import annotations
import json
import pathlib
import sys
OUT = pathlib.Path(__file__).resolve().parents[1] / "out" / "check"
for tender in sys.argv[1:]:
spec = json.loads((OUT / f"{tender}-A" / "spec.json").read_text())
rows: dict[str, dict[str, str]] = {}
for v in spec["volumes"]:
for b in v["blocks"]:
cols = b.get("columns") or []
if b.get("type") != "table" or "requirement" not in cols or "answer" not in cols:
continue
for r in [*b["rows"], *(b.get("pool") or [])]:
if r.get("key") and r["key"] not in rows:
rows[r["key"]] = {
"key": r["key"],
"requirement": r["cells"][cols.index("requirement")],
"answer": r["cells"][cols.index("answer")],
}
d = OUT / f"{tender}-B"
d.mkdir(exist_ok=True)
(d / "rewrite-input.json").write_text(json.dumps(list(rows.values()), ensure_ascii=False, indent=1))
print(tender, len(rows))