This repository has been archived on 2026-10-19. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
DB-cleanup/merge-output/compare_apply.ts
StellarCrow 41766c68a2 chore: final state before the move to gart/gart-databases
Commits the work done since 2026-10-01 that was still local: the four-step
label and flag passes, the triage and recheck files, the v1 exports of
2026-10-06 and 2026-10-07, the split dossiers, and the Lopp PR 234 batch
(scripts, agent prompts, reader and checker files, the flag re-read of
2026-10-17, the review workbook and the import set of the 57 cases added
to stats2 as 506 to 562). Raw HTML and node_modules stay out (.gitignore).

The stats2 material in use was copied to gart/gart-databases (stats2/) on
2026-10-17; README-START-HERE.md now says so. This repo is closed.
2026-10-17 10:47:37 +02:00

38 lines
2.2 KiB
TypeScript

// 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}`);