import { isDuplicateProbe } from "./duplicate-probes.ts"; import { HIGH_INFORMATION_GAIN, type ConflictProbe, type ProbeAnswer } from "./types.ts"; export function selectHighestGainProbe( probes: readonly ConflictProbe[], asked: readonly ProbeAnswer[], options: { minGain?: number } = {}, ): ConflictProbe | null { const minGain = options.minGain ?? 0; const ranked = [...probes] .filter((probe) => probe.information_gain >= minGain && !isDuplicateProbe(probe, asked)) .sort((left, right) => { if (right.information_gain !== left.information_gain) { return right.information_gain - left.information_gain; } return left.semantic_key.localeCompare(right.semantic_key); }); return ranked[0] ?? null; } export function remainingHighValueProbes( probes: readonly ConflictProbe[], asked: readonly ProbeAnswer[], ): ConflictProbe[] { return probes.filter((probe) => ( probe.information_gain >= HIGH_INFORMATION_GAIN && !isDuplicateProbe(probe, asked) )); }