// Apply the second reader's findings to the field-comparison batches before they are applied // to the stores: unsupported contradictions are dropped, unsupported flag proposals withdrawn, // unsupported facts set to the corrected value or null. The first reader's file is kept as // batches/batch-NN.first.json. Usage: bun compare_apply.ts import { copyFileSync, existsSync, readFileSync, readdirSync, writeFileSync } from "fs"; const J = (p: string) => JSON.parse(readFileSync(p, "utf8")); let dropped = 0, flags = 0, facts = 0, kept = 0; for (const f of readdirSync("batches").filter((f) => /^compare-\d+\.in\.json$/.test(f)).sort()) { const nn = f.slice(8, 10); const batchPath = `batches/batch-${nn}.json`, checkPath = `batches/compare-check-${nn}.json`, firstPath = `batches/batch-${nn}.first.json`; if (!existsSync(batchPath) || !existsSync(checkPath)) throw new Error(`batch ${nn}: first read or check missing`); if (!existsSync(firstPath)) copyFileSync(batchPath, firstPath); const batch: any[] = J(firstPath); const findings: any[] = J(checkPath).filter((x: any) => x.verdict === "unsupported"); for (const c of batch) { const mine = findings.filter((x) => x.id === c.id); const drop = new Set(mine.filter((x) => x.kind === "contradiction" && Number.isInteger(x.index)).map((x) => x.index)); dropped += drop.size; c.contradictions = c.contradictions.filter((_: unknown, i: number) => !drop.has(i)); kept += c.contradictions.length; for (const x of mine.filter((x) => x.kind === "flag" && c.flags[x.flag])) { // the proposal is withdrawn; the record's value stands until a person looks at it delete c.flags[x.flag].proposed; c.flags[x.flag].supported = true; c.flags[x.flag].evidence = `${c.flags[x.flag].evidence} [second reader: ${x.reason}]`; flags++; } for (const x of mine.filter((x) => x.kind === "fact" && c.facts && x.fact in c.facts)) { c.facts[x.fact] = x.correct ?? null; facts++; } c.checked = true; } writeFileSync(batchPath, JSON.stringify(batch, null, 1)); } console.log(`contradictions kept ${kept}, dropped ${dropped}; flag proposals withdrawn ${flags}; facts corrected ${facts}`);