"""Extract a loss-inclusive, selected-PDF table directly from scores.json.""" import json from pathlib import Path LAB = Path(__file__).resolve().parent SAMPLES = {"prose-single", "table-simple", "table-merged-header", "two-column", "scan-image", "mixed", "equation", "rotated-header", "columns-with-table", "wide-columns", "wide-columns-with-table"} TOOLS = ["pdfplumber", "pdfplumber-columns", "markitdown", "pymupdf4llm", "markovo"] KEYS = ["prose_recall", "reading_order", "table_rows_intact", "table_header_intact", "table_pipe_detected", "scan_text_recall", "pages_covered", "equation_recall", "elapsed_s"] scores = json.loads((LAB / "scores.json").read_text()) cells = [c for c in scores["cells"] if c["tool"] in TOOLS and c["sample"] in SAMPLES] cells.sort(key=lambda c: (TOOLS.index(c["tool"]), c["sample"])) def display(value): if value is None: return "n/a" if isinstance(value, bool): return str(value).lower() return str(value) lines = ["| Path | Fixture | P | O | R | H | Pipe | S | Pages | Math | Seconds |", "| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |"] for cell in cells: lines.append("| " + " | ".join([cell["tool"], cell["sample"], *[display(cell.get(k)) for k in KEYS]]) + " |") (LAB / "selected-scores.md").write_text("\n".join(lines) + "\n", encoding="utf-8") print(f"Selected {len(cells)} cells; errors: {sum(bool(c.get('error')) for c in cells)}")