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:
@@ -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; };
|
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; }
|
try { const v = sum(); return i === S.length && isFinite(v) ? v : null; } catch (x) { return null; }
|
||||||
};
|
};
|
||||||
const proveSentence = se => {
|
const proveSentence = (se, carry) => {
|
||||||
const ok = new Set();
|
const ok = new Set(carry || []);
|
||||||
const isOk = n => okNum(n.v) || ok.has(n.raw) || (!n.raw.includes('.') && !n.raw.includes(',') && n.v < 10)
|
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%
|
|| (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++) {
|
for (let pass = 0; pass < 3; pass++) {
|
||||||
@@ -195,8 +195,9 @@ function factcheck(report, evidenceText, keyNums) {
|
|||||||
}
|
}
|
||||||
return ok;
|
return ok;
|
||||||
};
|
};
|
||||||
const sentences = texts.flatMap(t => strip(t).split(/(?<=[.;!?])\s+/));
|
// a number proven in one sentence can be used in the next sentences of the SAME text field (a worked calculation)
|
||||||
const provenIn = sentences.map(se => ({ se, ok: proveSentence(se) }));
|
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)) {
|
for (const n of numbersIn(stripped)) {
|
||||||
const v = n.v;
|
const v = n.v;
|
||||||
if (!n.raw.includes('.') && !n.raw.includes(',') && v < 10) continue; // small counts and scores
|
if (!n.raw.includes('.') && !n.raw.includes(',') && v < 10) continue; // small counts and scores
|
||||||
|
|||||||
Reference in New Issue
Block a user