- 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>
33 lines
1.6 KiB
Python
33 lines
1.6 KiB
Python
"""S1 真值:Word 最后保存时记录的页数。DOCX 读 docProps/app.xml 的 <Pages>,旧版 DOC 读 OLE SummaryInformation 的 PIDSI_PAGECOUNT。"""
|
||
import json, re, sys, zipfile, pathlib
|
||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent.parent))
|
||
import olefile
|
||
from common import IDS, sample_file, sniff
|
||
|
||
OUT = pathlib.Path(__file__).parent / "out"
|
||
rows = {}
|
||
for sid in IDS:
|
||
f = sample_file(sid)
|
||
kind = sniff(f)
|
||
info = {"kind": kind, "pages": None, "app": None, "ole_objects": 0}
|
||
if kind == "docx":
|
||
with zipfile.ZipFile(f) as z:
|
||
names = z.namelist()
|
||
if "docProps/app.xml" in names:
|
||
app = z.read("docProps/app.xml").decode("utf-8", "replace")
|
||
m = re.search(r"<Pages>(\d+)</Pages>", app)
|
||
info["pages"] = int(m.group(1)) if m else None
|
||
a = re.search(r"<Application>([^<]*)</Application>", app)
|
||
info["app"] = a.group(1) if a else None
|
||
info["ole_objects"] = sum(1 for n in names if n.startswith("word/embeddings/"))
|
||
info["has_ole_xml"] = b"<o:OLEObject" in z.read("word/document.xml")
|
||
elif kind == "doc":
|
||
ole = olefile.OleFileIO(str(f))
|
||
meta = ole.get_metadata()
|
||
info["pages"] = meta.num_pages
|
||
info["app"] = (meta.creating_application or b"").decode("gbk", "replace") if isinstance(meta.creating_application, bytes) else meta.creating_application
|
||
info["ole_objects"] = sum(1 for e in ole.listdir() if e and e[0] == "ObjectPool")
|
||
rows[sid] = info
|
||
print(sid, info)
|
||
(OUT / "truth.json").write_text(json.dumps(rows, ensure_ascii=False, indent=1))
|