"""Precise batch defect report.""" import re import sys from pathlib import Path sys.path.insert(0, r"D:\L\Med\Research\99_System\LiteraturePipeline\github-release") VAULT = Path(r"D:\L\Med\Research_LitControl_Sandbox") OCR_DIR = VAULT / "System" / "PaperForge" / "ocr" papers = sorted([d.name for d in OCR_DIR.iterdir() if (d / "json" / "result.json").exists()]) print(f"=== BIG BATCH REPORT === ({len(papers)} papers)\n") for key in papers: md = OCR_DIR / key / "fulltext.md" text = md.read_text(encoding="utf-8") lines = text.splitlines() issues = [] # Image count vs caption count images = [l for l in lines if l.startswith("![[")] fig_caps = [(i, l) for i, l in enumerate(lines) if re.match(r'^Figure \d+', l)] img_num = len(images) cap_num = len(fig_caps) # Captions without preceding image (REAL issue) orphan = 0 for idx, _ in fig_caps: prev = None for j in range(idx-1, -1, -1): s = lines[j].strip() if s and not s.startswith("