"""Final ground-truth verdicts (corrected bound) + reviewer-paper score matrix for GT papers.""" import json, re from itertools import combinations from collections import defaultdict def johnson_bound(n, d, w): lam = w - d // 2 delta = d // 2 if lam < 0: return 1 val = (n - lam) // delta for j in range(lam, 0, -1): val = ((n - j + 1) * val) // (w - j + 1) return val full = json.load(open("run3/papers_full.json")) gt = json.load(open("run3/gt_paper_ids.json")) def parse_code_block(body): m = re.search(r"```\s*\r?\n(.*?)```", body, re.S) if not m: return None words = [] for line in m.group(1).strip().splitlines(): line = line.strip() if line: try: words.append([int(x) for x in re.split(r"\s+", line)]) except ValueError: return None return words verdicts = {} for pid in gt: p = full[pid] t = p["title"] body = p.get("body") or "" mt = re.search(r"n\s*=\s*(\d+)\D+d\s*=\s*(\d+)\D+w\s*=\s*(\d+)", t) mt2 = re.search(r"\((\d+)\s*,\s*(\d+)\s*,\s*(\d+)\)", t) if not (mt or mt2): verdicts[pid] = {"title": t, "type": "ramsey-exhaustion", "witness": None} continue n, d, w = map(int, (mt or mt2).groups()) ms = re.search(r"size\s+(\d+)", t) claimed = int(ms.group(1)) if ms else None v = {"title": t, "type": "constant-weight-code", "n": n, "d": d, "w": w, "claimed_size": claimed, "claims_optimal_in_title": "optimal" in t.lower()} words = parse_code_block(body) if not words: v["witness"] = "MISSING" verdicts[pid] = v continue lam = w - d // 2 bad = sum(1 for a, b in combinations(words, 2) if len(set(a) & set(b)) > lam) ok_form = all(len(x) == w and all(0 <= e < n for e in x) for x in words) ok_dist = len({tuple(sorted(x)) for x in words}) == len(words) v["witness_size"] = len(words) v["witness_valid"] = bool(ok_form and ok_dist and bad == 0) v["bad_pairs"] = bad jb = johnson_bound(n, d, w) v["johnson_bound"] = jb v["attains_bound"] = (len(words) == jb) # ground truth of the central claim if v["witness_valid"] and claimed is not None and claimed != len(words): v["central_claim"] = "FALSE (size mismatch)" elif v["witness_valid"] and "optimal" in t.lower() and not v["attains_bound"]: v["central_claim"] = "FALSE (optimality not established)" elif v["witness_valid"]: v["central_claim"] = "TRUE" + (" + OPTIMAL (attains Schoenheim)" if v["attains_bound"] else " (existence verified)") else: v["central_claim"] = "FALSE (witness invalid)" verdicts[pid] = v json.dump(verdicts, open("run3/gt_verdicts.json", "w"), indent=1) n_true = sum(1 for v in verdicts.values() if str(v.get("central_claim", "")).startswith("TRUE")) print(f"witness papers: {sum(1 for v in verdicts.values() if v.get('witness_valid') is not None)}, " f"valid: {sum(1 for v in verdicts.values() if v.get('witness_valid'))}, central TRUE: {n_true}") for pid, v in verdicts.items(): if v.get("witness_valid") is not None: print(f" ({v['n']},{v['d']},{v['w']}) size={v['witness_size']} bound={v['johnson_bound']} " f"attain={v['attains_bound']} -> {v['central_claim']}") # ---- reviewer x paper score matrix for the 12 witness papers ---- rows = json.load(open("run3/review_rows.json")) witness_pids = [pid for pid, v in verdicts.items() if v.get("witness_valid") is not None] mat = defaultdict(dict) meta = {} for r in rows: if r["paper"] in witness_pids and r["novelty"] is not None: mat[r["paper"]][r["reviewer"]] = (r["novelty"], r["rigour"], r["clarity"], r["significance"]) meta[r["reviewer"]] = r["reviewer_name"] out = {pid: {"reviews": dict(mat[pid]), **{k: v for k, v in verdicts[pid].items() if k != "title"}} for pid in witness_pids} json.dump({"matrix": out, "reviewer_names": meta}, open("run3/gt_score_matrix.json", "w"), indent=1) tot = sum(len(m["reviews"]) for m in out.values()) pairs = sum(len(m["reviews"]) * (len(m["reviews"]) - 1) // 2 for m in out.values()) print(f"\nscored reviews on witness papers: {tot}, reviewer-pairs within paper: {pairs}") revcount = defaultdict(int) for m in out.values(): for rv in m["reviews"]: revcount[meta[rv]] += 1 print("distinct reviewers:", len(revcount), "| multi-paper reviewers:", sum(1 for c in revcount.values() if c > 1))