#!/usr/bin/env python3 """Generate bench/gold/poj-104.json from the fetched POJ-104 directory tree. POJ-104's gold standard is structural: every pair of submissions inside the same numbered folder solves the same algorithm and is therefore Type-4 equivalent. We materialize this as one gold entry per folder, with `files` listing every submission's basename in that folder. The scorer in bench/score.py treats a fold finding as covering a gold entry if the finding's `kind` is `equiv` (or matches `kind` prefix) and the finding's location files are a superset of the gold entry's files. This is generous for fold (it doesn't need to find all C(n,2) pairs — one proof per cluster is enough) which matches Zubkov 2022's clustering evaluation methodology. """ from __future__ import annotations import json import sys from pathlib import Path ROOT = Path(__file__).resolve().parent.parent / "corpora" / "poj-104" / "dataset" OUT = Path(__file__).resolve().parent / "poj-104.json" def main() -> int: if not ROOT.is_dir(): print(f"dataset not found at {ROOT}; run bench/corpora/poj-104/fetch.sh", file=sys.stderr) return 2 expected = [] for algo_dir in sorted(ROOT.iterdir()): if not algo_dir.is_dir(): continue cpps = sorted(p.name for p in algo_dir.glob("*.cpp")) if len(cpps) < 2: continue # Gold entry: at least one cross-pair from this algorithm folder # must be reported by the tool as equiv. expected.append({ "kind": "equiv", "files": [str(algo_dir.name + "/" + p) for p in cpps[:2]], "id": f"poj-104-algo-{algo_dir.name}", "description": f"Algorithm {algo_dir.name} cluster (~{len(cpps)} submissions)", }) OUT.write_text(json.dumps({ "name": "poj-104", "description": "POJ-104 C++ clone-detection benchmark. " "Each gold entry is 'at least one cross-pair within " "an algorithm folder must be flagged equivalent'.", "expected": expected, }, indent=2)) print(f"wrote {len(expected)} gold entries → {OUT}") return 0 if __name__ == "__main__": raise SystemExit(main())