"""Deterministic grading for binary-reasoning-v1 items. Pure functions, no framework deps."""
import json
import re
JUDGE_FAMILIES = {"func_summary", "arch_semantics_qa", "isa_semantics_qa", "pe_import_reasoning", "pe_structure_qa"}
def norm_symbol(s: str) -> str:
s = s.strip().lower()
s = re.sub(r"^[*&]+", "", s)
s = re.sub(r"\(.*\)$", "", s).strip()
s = re.sub(r"\.+$", "", s) # sentence-final dot captured by token regex
return s
def _answer_symbol(answer) -> str:
if isinstance(answer, dict):
return answer.get("symbol", "")
return str(answer)
def grade_func_id_exact(reply: str, answer) -> float:
sym = norm_symbol(_answer_symbol(answer))
if not sym:
return 0.0
accepted = {sym}
if isinstance(answer, dict):
accepted |= {norm_symbol(a) for a in answer.get("aliases", []) if a}
toks = [norm_symbol(t) for t in re.findall(r"[A-Za-z_][A-Za-z0-9_.]+", reply)]
return 1.0 if accepted & set(toks) else 0.0
def gra…