File size: 3,746 Bytes
46f490b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | // BudgetBench SCORE: one case's turns (as a runner recorded them) -> per-turn outcomes and ONE case label.
//
// Turn outcomes (the judge's, grader/judge.mjs): correct | clarify_ok | wrong | wrong_offered | refused | needs_review,
// plus "tap" when the turn asked a choice and the runner tapped the option the answer key marks right.
// Case labels, never merged (METHODOLOGY.md):
// wrong_shown some turn SHOWS a wrong figure, name or claim
// wrong_offered no turn shows one, but some turn asks a choice whose every option answers wrongly
// right_no_tap every turn right with no tap
// right_tap every turn right, with exactly one tap
// not_sure the first turn that is not right says it is unsure or asks back (or needed two taps or more)
// declined the first turn that is not right declines, errs or says nothing usable
// review the grader could not place a turn (adjudicate by hand; reported, never hidden)
import {useHousehold, judgeTurn, effectiveMonths, nonAnswerClass} from "./judge.mjs";
import {goldOf} from "../oracle/oracle.mjs";
export const LABELS = ["wrong_shown", "wrong_offered", "right_no_tap", "right_tap", "not_sure", "declined", "review"];
/** the expectations of a case's turns (the oracle's gold for each meaning) */
export function expectationsOf(hh, c) {
return c.turns.map((t) => ({q: t.q, ...goldOf(hh, t.meaning)}));
}
/** is this text right for this turn? (used by a runner's tap: the answer key, the same for every system) */
export function rightFor(hh, expect, text, prev = null) {
useHousehold(hh);
const o = judgeTurn(expect, {text}, prev).outcome;
return o === "correct" || o === "clarify_ok";
}
/** run turns: [{q, text, choice?: {labels, answers: [{label, text}]}, tapped?: index}] */
export function scoreCase(hh, c, turns) {
useHousehold(hh);
const exps = expectationsOf(hh, c);
let prev = null;
const per = exps.map((e, i) => {
const t = turns?.[i];
let res;
if (t == null) res = {turn: i + 1, outcome: "declined", reason: "turn missing from the run"};
else if (t.choice?.answers?.length && Number.isInteger(t.tapped)) {
const a = t.choice.answers[t.tapped];
const r = judgeTurn(e, {text: a.text}, prev);
res = {turn: i + 1, outcome: r.outcome === "correct" || r.outcome === "clarify_ok" ? "tap" : r.outcome, reason: `tapped "${a.label}": ${r.reason}`};
} else {
const r = judgeTurn(e, t, prev);
res = {turn: i + 1, outcome: r.outcome, reason: r.reason};
if (r.outcome === "refused") res.class = t.choice?.answers?.length ? "not_sure" : nonAnswerClass(t.text);
if (r.outcome === "choice_offered") res.class = "not_sure"; // (an option was right but nobody tapped it)
}
prev = {...e, months: effectiveMonths(e, prev), turnRecord: t ?? null};
return {...res, q: e.q};
});
const isRight = (p) => p.outcome === "correct" || p.outcome === "clarify_ok";
const taps = per.filter((p) => p.outcome === "tap").length;
let label;
if (per.some((p) => p.outcome === "wrong")) label = "wrong_shown";
else if (per.some((p) => p.outcome === "wrong_offered")) label = "wrong_offered";
else if (per.every(isRight)) label = "right_no_tap";
else if (per.every((p) => isRight(p) || p.outcome === "tap")) label = taps === 1 ? "right_tap" : "not_sure";
else if (per.some((p) => p.outcome === "needs_review")) label = "review";
else {
const first = per.find((p) => !isRight(p) && p.outcome !== "tap");
label = first.class ?? (first.outcome === "declined" ? "declined" : "not_sure");
}
return {id: c.id, label, taps, turns: per};
}
|