UNPKG

agentfootprint

Version:

The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.

33 lines • 1.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.numericRangesOf = exports.splitNumericRange = void 0; /** Pure answer-side recognition: exactly two plain numeric endpoints. */ const normalize_js_1 = require("../../../lib/normalize.js"); const figureUnits_js_1 = require("./figureUnits.js"); // Anchored endpoints exclude dates, clocks, dotted versions and multipart IDs. const RANGE = /^([-+]?\d+(?:\.\d+)?)[-–]([-+]?\d+(?:\.\d+)?)([%a-z]+(?:\/s)?)?$/; const UNITS = new Set(figureUnits_js_1.FIGURE_UNITS.flatMap((unit) => [unit, `${unit}/s`])); function splitNumericRange(token, following) { const matched = RANGE.exec(token); if (matched?.[1] === undefined || matched[2] === undefined) return undefined; const suffix = matched[3]; if (suffix !== undefined && !UNITS.has(suffix)) return undefined; const unit = suffix ?? (following !== undefined && UNITS.has(following) ? following : undefined); return { first: matched[1], last: matched[2], ...(unit !== undefined && { unit }) }; } exports.splitNumericRange = splitNumericRange; /** Measurement ranges augment the existing figure vocabulary on the answer side only. */ function numericRangesOf(answer) { const tokens = (0, normalize_js_1.answerTokenSpellings)(answer); const ranges = []; for (let index = 0; index < Math.min(tokens.length, 20_000); index += 1) { const range = splitNumericRange(tokens[index] ?? '', tokens[index + 1]); if (range !== undefined) ranges.push(range); } return ranges; } exports.numericRangesOf = numericRangesOf; //# sourceMappingURL=numericRanges.js.map