File size: 537 Bytes
84afdaa | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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
|