from __future__ import annotations import re, json CIT = re.compile(r"\[(E_[A-Z0-9._-]+)\]") def citation_coverage(text:str)->float: # sentence-level coverage s=[x.strip() for x in re.split(r"(?<=[.!?])\s+", text.strip()) if x.strip()] if not s: return 0.0 ok=sum(1 for x in s if CIT.search(x)) return ok/len(s) def is_json_only(text:str)->bool: t=text.strip() if not (t.startswith("{") and t.endswith("}")): return False try: json.loads(t); return True except Exception: return False