MeningiomaBench / code /frame_choice_syntax_projection.py
dfdu233's picture
Silver research draft; expert review pending
a496c92 verified
Raw History Blame Contribute Delete
899 Bytes
"""Post-hoc narrow frame-ID syntax projection; no prose interpretation or gold."""
import json
import re
def project(raw, allowed):
try:parsed=json.loads(raw)
except (ValueError,TypeError):parsed=None
state=None;choice=None
if isinstance(parsed,dict) and set(parsed)=={'frame_id'} and isinstance(parsed['frame_id'],str):
choice=parsed['frame_id'];state='strict_object'
elif isinstance(parsed,str):choice=parsed;state='json_string'
elif isinstance(raw,str):
match=re.fullmatch(r'\s*"frame_id"\s*:\s*"(F[1-9]\d*)"\s*',raw)
if match:choice=match[1];state='single_field_fragment'
elif re.fullmatch(r'\s*F[1-9]\d*\s*',raw):choice=raw.strip();state='bare_frame_id'
if choice not in allowed:return {'frame_id':None,'state':'unknown_or_invalid_syntax','strict':False}
return {'frame_id':choice,'state':state,'strict':state=='strict_object'}