Guy DuGan II commited on
Commit
84afdaa
·
verified ·
1 Parent(s): 251af1d

Upload validators.py

Browse files
Files changed (1) hide show
  1. eval/validators.py +16 -0
eval/validators.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+ import re, json
3
+ CIT = re.compile(r"\[(E_[A-Z0-9._-]+)\]")
4
+ def citation_coverage(text:str)->float:
5
+ # sentence-level coverage
6
+ s=[x.strip() for x in re.split(r"(?<=[.!?])\s+", text.strip()) if x.strip()]
7
+ if not s: return 0.0
8
+ ok=sum(1 for x in s if CIT.search(x))
9
+ return ok/len(s)
10
+ def is_json_only(text:str)->bool:
11
+ t=text.strip()
12
+ if not (t.startswith("{") and t.endswith("}")): return False
13
+ try:
14
+ json.loads(t); return True
15
+ except Exception:
16
+ return False