Fact gate: raw wei/6-decimal sums written as coin amounts, unit words before '=', and an allowed percent written as a fraction (0.30 for 30%)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -157,20 +157,22 @@ function factcheck(report, evidenceText, keyNums) {
|
||||
};
|
||||
const proveSentence = se => {
|
||||
const ok = new Set();
|
||||
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%
|
||||
for (let pass = 0; pass < 3; pass++) {
|
||||
// (1) explicit expressions
|
||||
const parts = se.split('=');
|
||||
for (let k = 1; k < parts.length; k++) {
|
||||
const rm = /^\s*\$?\s*(\d{1,3}(?:,\d{3})+(?:\.\d+)?|\d+(?:\.\d+)?)/.exec(parts[k]);
|
||||
const em = /[\d.,\s+\-x\u00d7*/()%$]*$/i.exec(parts[k - 1]); if (!em) continue;
|
||||
const em = /[\d.,\s+\-x\u00d7*/()%$]*$/i.exec(parts[k - 1].replace(/\s*\b(wei|pol|usdt|usdc|bnb|usd|cents|raw units|units)\s*$/i, ' ')); if (!em) continue; // a unit word before '=' is not part of the sum
|
||||
let expr = em[0].replace(/^[\s,.)]+/, ''); // trim to a balanced start
|
||||
while ((expr.match(/\)/g) || []).length > (expr.match(/\(/g) || []).length && expr.includes(')')) expr = expr.slice(expr.indexOf(')') + 1);
|
||||
while ((expr.match(/\(/g) || []).length > (expr.match(/\)/g) || []).length) expr = expr.slice(expr.indexOf('(') + 1);
|
||||
const ins = (expr.match(/\d{1,3}(?:,\d{3})+(?:\.\d+)?|\d+(?:\.\d+)?/g) || []).map(r => ({ raw: r, v: Number(r.replace(/,/g, '')) })); // '4x25' holds two inputs
|
||||
if (!ins.length || !ins.every(isOk)) continue;
|
||||
for (const q of ins) if (q.v > 0 && q.v < 1) ok.add(q.raw); // an allowed percent written as a fraction
|
||||
const v = evalExpr(expr); const r = rm ? Number(rm[1].replace(/,/g, '')) : NaN;
|
||||
if (rm && v != null && Math.abs(v - r) <= tol(rm[1])) ok.add(rm[1]);
|
||||
if (rm && v != null && [1, 1e18, 1e6].some(u => Math.abs(v / u - r) <= tol(rm[1]))) ok.add(rm[1]); // raw on-chain units written as coin amounts
|
||||
else if (v != null) { // the right side is itself an expression ("... = 355 / 10 = 35.5"): equal values prove its numbers
|
||||
const rx = /^[\d.,\s+\-x×*/()%$]*/i.exec(parts[k])[0].replace(/[\s,.]+$/, ''); const rv = evalExpr(rx);
|
||||
if (rv != null && Math.abs(rv - v) <= Math.max(1e-9, Math.abs(v) * 1e-9)) for (const q of numbersIn(rx)) ok.add(q.raw);
|
||||
|
||||
Reference in New Issue
Block a user