- spikes/:Word 转 PDF(Gotenberg)、格式识别、原句坐标、DeepSeek 抽取四项验证代码与两版提示词;样本派生产物和 .env 不进 git - tech-validation.md:完整结论。四项都可行:WPS 字体字符集要修正并改用行高调整过的字体;格式识别不需要 Docling;表格内切句待改进;抽取需第三道依据校验与规则兜底 - architecture.md:§3.5 加预处理与字体包,§3.6 证据校验改为三道,§10 回填结论 - 03 功能需求与 decisions.md(TV1):召回 ≥ 99%、采纳准确率 ≥ 95%、页码 100%、高亮正文 ≥ 98% / 表格 ≥ 95% Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
31 lines
1.4 KiB
Python
31 lines
1.4 KiB
Python
"""S1:用 Gotenberg 把 10 份样本转成 PDF,记录页数、耗时、是否失败。
|
||
用法:python -I convert.py <配置名> <Gotenberg 地址> [预处理后的 DOCX 目录]
|
||
"""
|
||
import json, sys, time, pathlib
|
||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent.parent))
|
||
import httpx, pypdfium2 as pdfium
|
||
from common import IDS, sample_file, sniff
|
||
|
||
cfg, base = sys.argv[1], sys.argv[2]
|
||
src_dir = pathlib.Path(sys.argv[3]) if len(sys.argv) > 3 else None # 预处理后的 DOCX 目录
|
||
out = pathlib.Path(__file__).parent / "out" / cfg
|
||
out.mkdir(parents=True, exist_ok=True)
|
||
rows = {}
|
||
with httpx.Client(timeout=600) as c:
|
||
for sid in IDS:
|
||
f = (src_dir / f"{sid}.docx") if src_dir else sample_file(sid)
|
||
ext = sniff(f) # 按真实格式给扩展名,LibreOffice 据此选过滤器
|
||
t = time.monotonic()
|
||
r = c.post(f"{base}/forms/libreoffice/convert",
|
||
files={"files": (f"{sid}.{ext}", f.read_bytes())})
|
||
dt = round(time.monotonic() - t, 1)
|
||
if r.status_code != 200:
|
||
rows[sid] = {"ok": False, "status": r.status_code, "err": r.text[:200], "sec": dt}
|
||
else:
|
||
pdf = out / f"{sid}.pdf"
|
||
pdf.write_bytes(r.content)
|
||
n = len(pdfium.PdfDocument(str(pdf)))
|
||
rows[sid] = {"ok": True, "pages": n, "sec": dt}
|
||
print(cfg, sid, rows[sid], flush=True)
|
||
(out / "result.json").write_text(json.dumps(rows, ensure_ascii=False, indent=1))
|