"""Citation-level labels from LePhantomCite (ai-law-society-lab/Legal_Phantom_Citation). phantom = citation tagged non_existent_citation genuine = citation with no hallucination tag at all other = tagged case_name_mismatch / wrong_pincite / misquote / content_misrepresentation (needs a case-law lookup; out of scope for a string-only model, reported separately) 'optional' tags (typos in the source brief) are dropped. """ import json, os, sys sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from citenet.text import normalize ROOT = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "data") def load(split): rows = [json.loads(l) for l in open(os.path.join(ROOT, split + ".jsonl"))] out = [] for r in rows: tags = r.get("list_hallucination_types") or {} opt = {k for k, v in (r.get("list_hallucinations") or {}).items() if v == "optional"} cites = list(dict.fromkeys(list(r["citations_in_segment"]) + list(tags))) seen = set() for c in cites: key = normalize(c) if key in seen or c in opt: continue seen.add(key) ts = tags.get(c, []) if "optional" in ts: continue label = "phantom" if "non_existent_citation" in ts else ("other" if ts else "genuine") out.append(dict(cite=c, label=label, types=ts, file=r["filename"])) return out