# -*- coding: utf-8 -*-
import re,sys,os,json
sys.path.insert(0,".")
import verify_grok as vg
PAGES={int(k):v for k,v in vg.PAGES.items()} if all(str(k).isdigit() for k in vg.PAGES) else vg.PAGES
ch2="/home/zyw/Downloads/dl-hub/23-拍照OCR取字/data/books/软件项目管理与实践_第2章_软件项目启动_第15-32页/全书_纯净全文_20260923_203259.txt"
CH2=open(ch2,encoding="utf-8").read() if os.path.exists(ch2) else ""
def norm(s): return re.sub(r"[\s，。；：、？！“”「」（）()《》,.;:?!-]+","",s)
def txt(p):
    p=int(p)
    if p in PAGES: return PAGES[p]
    return CH2 if 16<=p<=32 else ""
md=open("定稿输出/潘基定稿3.1.md",encoding="utf-8").read()
res=[]
for lab,(a,b) in {"A":("# A 卷","# B 卷"),"B":("# B 卷","## 定稿")}.items():
    seg=md[md.find(a):md.find(b)] if md.find(b)>md.find(a) else md[md.find(a):]
    ans=seg[seg.find("## 参考答案"):]; sec=None
    for m in re.finditer(r"\*\*(\d+)\.\*\*(.*?)(?=\n\*\*\d+\.\*\*|\Z)",ans,re.S):
        no=m.group(1); body=m.group(2)
        pages=[int(x) for x in re.findall(r"P(\d+)",body)]
        quotes=re.findall(r"[「“]([^」”]{8,})[」”]",body)
        if not pages: res.append((lab,no,"无页码","","")); continue
        ok=False; bad=[]
        for q in quotes[:3]:
            qn=norm(q)
            if any(qn in norm(txt(p)) for p in pages): ok=True; break
            bad.append(q[:30])
        if not ok and quotes:
            found=None
            for p in list(PAGES)+["ch2"]:
                t=norm(PAGES[p]) if p!="ch2" else norm(CH2)
                if any(norm(q) in t for q in quotes[:3]): found=p; break
            res.append((lab,no,"引文不在标注页",",".join(bad)[:60],found))
print("可疑:",len(res))
for r in res: print(r)
