Fact gate: a number proven in one sentence carries to the next sentences of the same text field (worked calculations)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-16 13:00:47 -06:00
parent a2932fd928
commit 7feeb22fb2
+5 -4
View File
@@ -155,8 +155,8 @@ function factcheck(report, evidenceText, keyNums) {
const sum = () => { let v = prod(); while (S[i] === '+' || S[i] === '-') { const o = S[i++]; const w = prod(); v = o === '+' ? v + w : v - w; } return v; };
try { const v = sum(); return i === S.length && isFinite(v) ? v : null; } catch (x) { return null; }
};
const proveSentence = se => {
const ok = new Set();
const proveSentence = (se, carry) => {
const ok = new Set(carry || []);
const isOk = n => okNum(n.v) || ok.has(n.raw) || (!n.raw.includes('.') && !n.raw.includes(',') && n.v < 10)
|| (n.v > 0 && n.v < 1 && okNum(Math.round(n.v * 10000) / 100)); // 0.30 for an allowed 30%
for (let pass = 0; pass < 3; pass++) {
@@ -195,8 +195,9 @@ function factcheck(report, evidenceText, keyNums) {
}
return ok;
};
const sentences = texts.flatMap(t => strip(t).split(/(?<=[.;!?])\s+/));
const provenIn = sentences.map(se => ({ se, ok: proveSentence(se) }));
// a number proven in one sentence can be used in the next sentences of the SAME text field (a worked calculation)
const provenIn = [];
for (const t of texts) { let carry = new Set(); for (const se of strip(t).split(/(?<=[.;!?])\s+/)) { const ok = proveSentence(se, carry); provenIn.push({ se, ok }); carry = ok; } }
for (const n of numbersIn(stripped)) {
const v = n.v;
if (!n.raw.includes('.') && !n.raw.includes(',') && v < 10) continue; // small counts and scores