// Field comparison for the cases verified by the older method (summary and sequence done, // record fields never compared with the articles). Prepares batches of ten: // batches/compare-NN.in.json summary, sequence, attempted, gaps, rationale as they stand // batches/batch-lists.json gains the new batch numbers // The writer adds flags, contradictions, facts and notes and writes batches/batch-NN.json. // bun compare_prepare.ts prepare bun compare_prepare.ts check import { existsSync, readFileSync, readdirSync, writeFileSync } from "fs"; const J = (p: string) => JSON.parse(readFileSync(p, "utf8")); const FIRST = 36; const KEEP = ["summary", "sequence", "attempted", "gaps", "v1_label_supported", "rationale"]; const cmd = process.argv[2]; if (cmd === "prepare") { const seqs = J("scenario-sequences.json"), summaries = J("summary-overrides.json"); const lists = J("batches/batch-lists.json"); const ids = Object.keys(seqs).filter((k) => !("facts" in seqs[k])).map(Number).sort((a, b) => a - b); for (let i = 0; i * 10 < ids.length; i++) { const nn = String(FIRST + i); const part = ids.slice(i * 10, (i + 1) * 10); lists[nn] = part; writeFileSync(`batches/compare-${nn}.in.json`, JSON.stringify(part.map((id) => ({ id, dossier: `sources/${readdirSync("sources").find((f) => f.startsWith(String(id).padStart(3, "0") + "_"))}`, summary: summaries[id], sequence: seqs[id].sequence, attempted: seqs[id].attempted, gaps: seqs[id].gaps, v1_label_supported: seqs[id].v1_label_supported, rationale: seqs[id].rationale, })), null, 1)); } writeFileSync("batches/batch-lists.json", JSON.stringify(lists, null, 1)); console.log(`${ids.length} cases in batches ${FIRST} to ${FIRST + Math.ceil(ids.length / 10) - 1}`); } else if (cmd === "check") { // the fields that were already verified must come back unchanged let bad = 0, done = 0; for (const f of readdirSync("batches").filter((f) => /^compare-\d+\.in\.json$/.test(f)).sort()) { const nn = f.slice(8, 10); if (!existsSync(`batches/batch-${nn}.json`)) { console.log(`batch-${nn}.json missing`); bad++; continue; } const out = new Map(J(`batches/batch-${nn}.json`).map((c: any) => [c.id, c])); for (const c of J(`batches/${f}`)) { const o = out.get(c.id); if (!o) { console.log(`batch-${nn} case ${c.id}: missing`); bad++; continue; } done++; for (const k of KEEP) if (JSON.stringify(o[k]) !== JSON.stringify(c[k])) { console.log(`batch-${nn} case ${c.id}: ${k} was changed`); bad++; } } } console.log(`${done} cases checked, ${bad} problems`); if (bad) process.exit(1); } else throw new Error("usage: bun compare_prepare.ts prepare | check");