"""F4-conf-02: verdicts on six assertions against cited source extracts. Reads data/ only; writes out/results.json deterministically. No randomness.""" import json, math, os, re ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) D = os.path.join(ROOT, "data") DCR, RES = "arxiv-2609.27732v1", "arxiv-2606.14621v1" def lines(path): with open(path, encoding="utf-8") as f: return f.read().split("\n") def wc_l(path): with open(path, "rb") as f: return f.read().count(b"\n") assertions = json.load(open(os.path.join(D, "assertions.json"), encoding="utf-8")) src = {s: lines(os.path.join(D, "sources", s + ".txt")) for s in (DCR, RES)} def find(s, pattern, start=0): """Return (index, text) of first line at/after `start` matching regex; print it.""" for i, l in enumerate(src[s][start:], start): if re.search(pattern, l): print(f" [{s} L{i+1}] {l.strip()}") return i, l raise ValueError(f"pattern {pattern!r} not found in {s}") def cells(l): return [c.strip() for c in l.split("|")] def num(c): return float(re.sub(r"[^\d\.\-]", "", c.replace("−", "-"))) def stars(c): return c.count("*") pct = lambda b: 100 * (math.exp(b) - 1) cols = {"1 km": 1, "3 km": 2, "5 km": 3} # ---------- DCR Table 6 ---------- print("Table 6 (DCR):") t6, _ = find(DCR, r"^Table 6:") i, att = find(DCR, r"^ATT \|", t6); att = cells(att) _, se = find(DCR, r"^\| \(", i); se = cells(se) _, pc = find(DCR, r"^% change \|", i); pc = cells(pc) find(DCR, r"statistically significant at the 5% level", i) t6v = {k: dict(b=num(att[c]), st=stars(att[c]), se=num(se[c]), pct=num(pc[c])) for k, c in cols.items()} # ---------- DCR Table 7 ---------- print("Table 7 (DCR):") t7, _ = find(DCR, r"^Table 7:") t7v = {} for row in ("Hepatitis", "HIV"): i, l = find(DCR, rf"^{row} \|", t7); l = cells(l) _, s = find(DCR, r"^\| \(", i); s = cells(s) t7v[row] = {k: dict(b=num(l[c]), st=stars(l[c]), se=num(s[c])) for k, c in cols.items()} # ---------- DCR A19 (consistency check only) ---------- print("Table A19 (DCR, consistency check):") a19, _ = find(DCR, r"^Table A19:") i, l = find(DCR, r"^ATT \|", a19) _, s = find(DCR, r"^\| \(", i) a19_se_csdr = num(cells(s)[1]) _, a19note = find(DCR, r"never-treated comparison regions \(\d+ regions\)", a19) a19_controls = int(re.search(r"\((\d+) regions\)", a19note).group(1)) # ---------- Sex/gender search (A5) ---------- print("Search for sex/gender breakdown in DCR extract:") sex_hits = [k + 1 for k, l in enumerate(src[DCR]) if re.search(r"\b(men|women|male|female|males|females|sex|gender)\b", l, re.I)] print(f" lines mentioning men/women/male/female/sex/gender: {sex_hits}") # ---------- RESEA Table 2 ---------- print("Table 2 (RESEA):") _, w = find(RES, r"^Weeks on UI \|") w = cells(w) ctrl_mean = num(w[2].split("weeks")[0]) ate = w[4] ate_b = float(re.search(r"(-?\d+\.\d+) weeks", ate).group(1)) ate_ci = [float(x) for x in re.search(r"CI: \[(-?[\d\.]+), (-?[\d\.]+)\]", ate).groups()] find(RES, r"11\.5% decrease") # ---------- Verdict logic ---------- V, L, R, calc = {}, {}, {}, {} a = {x["id"]: x for x in assertions} assert all(a[k]["cites"] == DCR for k in ("A1", "A2", "A3", "A4", "A5")) and a["A6"]["cites"] == RES # A1: 5 km overall ATT -0.431 (SE 0.210), significant at 5%, 35.0% reduction x = t6v["5 km"] ok1 = (x["b"] == -0.431 and x["se"] == 0.210 and x["st"] >= 2 and x["pct"] == -35.0 and round(pct(x["b"]), 1) == -35.0) calc["A1"] = dict(b=x["b"], se=x["se"], stars=x["st"], pct_printed=x["pct"], pct_implied=round(pct(x["b"]), 2), z=round(x["b"] / x["se"], 3)) V["A1"] = "supported" if ok1 else "not_supported" L["A1"] = f'{DCR} | Table 6 | row "ATT" | column "5 km"' R["A1"] = ("Table 6 prints ATT -0.431** (SE 0.210) and % change -35.0% at 5 km, and the text states significance at the 5% level, " "matching every element of the assertion." if ok1 else "Table 6 5 km values do not match the assertion.") # A2: HIV 1 km ATT negative (-0.063) x = t7v["HIV"]["1 km"] calc["A2"] = dict(b=x["b"], se=x["se"], stars=x["st"]) V["A2"] = "not_supported" if x["b"] > 0 else "supported" L["A2"] = f'{DCR} | Table 7 | row "HIV" | column "1 km"' R["A2"] = (f"Table 7 prints the 1 km HIV ATT as +{x['b']:.3f} (SE {x['se']:.3f}), positive and insignificant, so the claimed negative " "sign and the claimed fall in HIV hospitalisations are contradicted.") # A3: 3 km ATT -0.283 implies 28.3% reduction x = t6v["3 km"] calc["A3"] = dict(b=x["b"], pct_printed=x["pct"], pct_implied=round(pct(x["b"]), 2)) ok3 = abs(pct(x["b"]) - (-28.3)) < 0.05 V["A3"] = "supported" if ok3 else "not_supported" L["A3"] = f'{DCR} | Table 6 | row "% change" | column "3 km"' R["A3"] = (f"The ATT of {x['b']:.3f} log points corresponds to a {x['pct']:.1f}% change (printed in Table 6; " f"100(exp({x['b']:.3f})-1) = {pct(x['b']):.2f}%), not a 28.3% reduction, which wrongly reads log points as percent.") # A4: hepatitis 5 km 95% CI approx [-0.66, -0.16], excludes zero x = t7v["Hepatitis"]["5 km"] ci196 = [round(x["b"] - 1.96 * x["se"], 3), round(x["b"] + 1.96 * x["se"], 3)] ci200 = [round(x["b"] - 2.0 * x["se"], 3), round(x["b"] + 2.0 * x["se"], 3)] ci100 = [round(x["b"] - x["se"], 3), round(x["b"] + x["se"], 3)] calc["A4"] = dict(b=x["b"], se=x["se"], stars=x["st"], ci95_1p96=ci196, ci95_2p00=ci200, ci_pm_1se=ci100) excl = ci196[1] < 0 or ci196[0] > 0 V["A4"] = "supported" if excl else "not_supported" L["A4"] = f'{DCR} | Table 7 | row "Hepatitis" | column "5 km"' R["A4"] = (f"With ATT {x['b']:.3f} and SE {x['se']:.3f} the 95% CI is [{ci196[0]:.3f}, {ci196[1]:.3f}] (±1.96·SE), which includes zero " "(the estimate carries no star); the asserted interval is only ±1 SE.") # A5: larger reduction for men than women calc["A5"] = dict(sex_lines=sex_hits) V["A5"] = "not_assessable" if not sex_hits else "REVIEW" L["A5"] = f"not reported in {DCR}" R["A5"] = ("The extract reports ATTs only by buffer (Table 6), outcome category (Table 7) and estimator (Table A19) and never " "by sex, so the men-versus-women comparison can be neither confirmed nor refuted.") # A6: ATE -1.99 weeks, CI [-2.24,-1.75], 11.5% of control mean 17.3 rel = 100 * abs(ate_b) / ctrl_mean calc["A6"] = dict(ate=ate_b, ci=ate_ci, control_mean=ctrl_mean, rel_pct=round(rel, 2)) ok6 = ate_b == -1.99 and ate_ci == [-2.24, -1.75] and ctrl_mean == 17.3 and round(rel, 1) == 11.5 V["A6"] = "supported" if ok6 else "not_supported" L["A6"] = f'{RES} | Table 2 | row "Weeks on UI" | column "Average treatment effect estimate"' R["A6"] = (f"Table 2 prints the ATE as -1.99 weeks (95% CI [-2.24, -1.75]) with a control mean of 17.3 weeks, and " f"1.99/17.3 = {rel:.2f}% matches the 11.5% decrease stated in the results text.") # ---------- Data issues ---------- issues = [] if a19_se_csdr != t6v["5 km"]["se"]: issues.append(dict(issue=f"{DCR}: the same CS-DR 5 km ATT (-0.431**) has SE {t6v['5 km']['se']:.3f} in Table 6 but " f"{a19_se_csdr:.3f} in Table A19 (internal inconsistency).", handling="A1 cites Table 6, whose SE (0.210) matches the assertion; verdict uses Table 6. With SE 0.218, " f"|z| = {0.431/a19_se_csdr:.3f}: still significant at 5% under 1.96, borderline under 2.0; A1 verdict unchanged because the printed ** appears in both tables.")) if a19_controls != 608: issues.append(dict(issue=f"{DCR}: Table A19 note says {a19_controls} never-treated comparison regions while the Table 6/A19 rows and the Figure 6 note say 608.", handling="Not decisive for any assertion; recorded only.")) issues.append(dict(issue=f"{DCR}: narrative percentages for sub-outcomes are inconsistent: abstract says fatal hospitalisations fall by 35% while Section 6.1 says ~30% at 5 km " f"(100(exp(-0.354)-1) = {pct(-0.354):.1f}%); Section 6.1 says narcotics +47% at 5 km (implied {pct(0.390):.1f}%); text calls HIV estimates 'close to zero' although the 5 km HIV ATT is -0.340.", handling="Verdicts rely on the printed table coefficients, not the narrative; none of these is decisive for A1-A6.")) issues.append(dict(issue=f"{RES}: results text reports the weeks-on-UI CIs as positive magnitudes ([1.75 weeks, 2.24 weeks]) for a 'reduction', while Table 2 prints signed [-2.24, -1.75]; also a rendering defect 'p ¡ 0.001' for p < 0.001.", handling="Treated as equivalent sign conventions; A6 judged against the signed Table 2 values.")) issues.append(dict(issue="Both extracts are partial (sections omitted), and RESEA Tables 2-3 were re-set by the extract editor.", handling="Verdicts rely only on the extract content as instructed; values in re-set tables are taken as verbatim per the editorial note.")) ids = [x["id"] for x in assertions] # ---------- Naive baseline (P2): verbatim number matching ---------- # 'supported' if every number in the assertion (sign dropped) occurs verbatim in the cited extract, else 'not_supported'. baseline = {} for x in assertions: nums = re.findall(r"\d+\.\d+|\d+", x["text"].replace("−", "-")) nums = [n for n in nums if n not in ("1", "3", "5", "95")] # buffer sizes / CI level are labels body = "\n".join(src[x["cites"]]) baseline[x["id"]] = "supported" if all(n in body for n in nums) else "not_supported" print("Naive verbatim-number baseline:", json.dumps(baseline)) res = dict( task_id="F4-conf-02", verdicts={k: V[k] for k in ids}, locators={k: L[k] for k in ids}, reasons={k: R[k] for k in ids}, n_supported=sum(V[k] == "supported" for k in ids), n_not_supported=sum(V[k] == "not_supported" for k in ids), n_not_assessable=sum(V[k] == "not_assessable" for k in ids), feasibility="complete", feasibility_reason=None, data_issues=issues, n_input_rows={"assertions.json": len(assertions), "README.md": wc_l(os.path.join(D, "README.md")), f"{DCR}.txt": wc_l(os.path.join(D, "sources", DCR + ".txt")), f"{RES}.txt": wc_l(os.path.join(D, "sources", RES + ".txt"))}, n_analysed=len(ids), random_seed=None, supporting_calculations=calc, baseline_verdicts_verbatim_number_match=baseline, baseline_agreement_with_verdicts=sum(baseline[k] == V[k] for k in ids), ) os.makedirs(os.path.join(ROOT, "out"), exist_ok=True) with open(os.path.join(ROOT, "out", "results.json"), "w", encoding="utf-8") as f: json.dump(res, f, indent=2, ensure_ascii=False) print("\nVerdicts:", json.dumps(res["verdicts"])) print("Counts: supported", res["n_supported"], "| not_supported", res["n_not_supported"], "| not_assessable", res["n_not_assessable"])