"""Task-suite table (tab:tasks) and the task-card appendix, generated from tasks/registry.csv and tasks/task_cards/*.md.""" import os, csv, re, glob, sys sys.path.insert(0, os.path.dirname(__file__)) REPO = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) from texutil import tex def card_field(txt, name): m = re.search(r"\*\*" + re.escape(name) + r"\*\*\s*:\s*(.+)", txt) return m.group(1).strip() if m else "" def main(): reg = sorted(csv.DictReader(open(os.path.join(REPO, "tasks", "registry.csv"))), key=lambda r: (r["split"] != "conf", r["task_id"])) rows = [] for r in reg: card = open(os.path.join(REPO, "tasks", "task_cards", r["task_id"] + ".md")).read() if os.path.exists(os.path.join(REPO, "tasks", "task_cards", r["task_id"] + ".md")) else "" q = card_field(card, "Question") or card_field(card, "Scientific question") q = re.sub(r"\s+", " ", q)[:150] rows.append((r["task_id"], r["split"], r["data_type"], "yes" if r["real_data"] == "yes" else "no", "yes" if r["source_documents"] == "yes" else "no", r["oracle_provenance"].replace("_", " "), r["infeasible_or_null_truth"], q)) L = [r"\begin{longtable}{@{}p{0.72in}p{0.4in}p{0.5in}p{0.3in}p{0.3in}p{0.75in}p{0.3in}p{2.6in}@{}}", r"\caption{Task suite: identifiers, split, data type, observed public data, source documents, reference-answer provenance, null/infeasible truth, and question (abridged from the task cards).}\label{tab:tasks}\\", r"\toprule", r"Task & Split & Data & Real & Src & Oracle & Null & Question (abridged) \\", r"\midrule", r"\endfirsthead", r"\toprule", r"Task & Split & Data & Real & Src & Oracle & Null & Question (abridged) \\", r"\midrule", r"\endhead"] for t in rows: L.append(" & ".join(tex(x) for x in t) + r" \\") L += [r"\bottomrule", r"\end{longtable}"] os.makedirs(os.path.join(REPO, "paper", "tables"), exist_ok=True) open(os.path.join(REPO, "paper", "tables", "tab_tasks.tex"), "w").write("\\footnotesize\n" + "\n".join(L) + "\n\\normalsize\n") # appendix: task cards verbatim-ish (markdown bullets → itemize) A = [] for r in reg: p = os.path.join(REPO, "tasks", "task_cards", r["task_id"] + ".md") if not os.path.exists(p): continue txt = open(p).read() A.append(f"\\subsection*{{{tex(r['task_id'])}}}") items = re.findall(r"^- \*\*(.+?)\*\*\s*:?\s*(.*)$", txt, re.M) if items: A.append(r"\begin{itemize}\setlength\itemsep{0pt}") for k, v in items: v = re.sub(r"`([^`]*)`", r"\\texttt{\1}", tex(v)); A.append(f"\\item \\textbf{{{tex(k)}}}: {v}") A.append(r"\end{itemize}") open(os.path.join(REPO, "paper", "appendices", "task_cards.tex"), "w").write("\\small\n" + "\n".join(A) + "\n\\normalsize\n") print(len(rows), "tasks tabled;", len(A), "appendix lines") if __name__ == "__main__": main()