Download scripts/validate.py from alejandrosalastexido/ModuleMap-Bench: direct link, hf CLI and curl.
- Browser
- Download file 2.66 kB
-
https://huggingface.co/datasets/alejandrosalastexido/ModuleMap-Bench/resolve/main/scripts/validate.py
- Command line
-
hf download hf://datasets/alejandrosalastexido/ModuleMap-Bench/scripts/validate.py
-
curl -L -o validate.py https://huggingface.co/datasets/alejandrosalastexido/ModuleMap-Bench/resolve/main/scripts/validate.py
2.66 kB
| #!/usr/bin/env python3 | |
| """Check the dataset's files against their documented shape. Exit 1 on the first kind of problem found. | |
| python3 scripts/validate.py | |
| """ | |
| import csv | |
| import sys | |
| from common import ROLES, data, read_jsonl | |
| problems = [] | |
| def check(cond, msg): | |
| if not cond: | |
| problems.append(msg) | |
| labels = read_jsonl(data("roles", "labels.jsonl")) | |
| ids = set() | |
| projects = {r["project"]: r for r in csv.DictReader(open(data("projects.csv"), encoding="utf-8"))} | |
| for l in labels: | |
| for k in ("id", "project", "commit", "module", "path", "url", "qualified_name", "name", "kind", "role", "structure"): | |
| check(k in l, f"{l.get('id')}: missing {k}") | |
| check(l["id"] not in ids, f"{l['id']}: duplicate id") | |
| ids.add(l["id"]) | |
| check(l["id"] == f"{l['project']}/{l['qualified_name']}", f"{l['id']}: id is not project/qualified_name") | |
| check(l["role"] in ROLES, f"{l['id']}: unknown role {l['role']}") | |
| check(l["project"] in projects, f"{l['id']}: project not in projects.csv") | |
| check(l["commit"] == projects.get(l["project"], {}).get("commit"), f"{l['id']}: commit differs from projects.csv") | |
| check(l["path"].endswith(".java") and "src/main/java/" in l["path"], f"{l['id']}: path is not main Java") | |
| check(l["kind"] in ("class", "abstract class", "interface", "enum", "record", "annotation"), f"{l['id']}: kind {l['kind']}") | |
| check(set(l["structure"]["derived_marks"]) <= {"api", "ext"}, f"{l['id']}: unknown mark") | |
| for p, r in projects.items(): | |
| n = sum(1 for l in labels if l["project"] == p) | |
| check(n == int(r["labelled"]), f"{p}: {n} labels, projects.csv says {r['labelled']}") | |
| csv_rows = list(csv.DictReader(open(data("roles", "labels.csv"), encoding="utf-8"))) | |
| check(len(csv_rows) == len(labels), "labels.csv and labels.jsonl differ in length") | |
| features = read_jsonl(data("features", "features.jsonl")) | |
| check({f["id"] for f in features} == ids, "features.jsonl does not cover exactly the labelled types") | |
| try: | |
| commits = read_jsonl(data("history", "commits.jsonl")) | |
| except FileNotFoundError: | |
| commits = [] | |
| problems.append("data/history/commits.jsonl missing") | |
| for c in commits: | |
| modified = {m["qualified_name"] for m in c["modified"]} | |
| for k, shown in c["shown_before"].items(): | |
| check(set(shown) <= modified, f"{c['project']} {c['commit'][:10]}: {k} shows a type not modified") | |
| check(c["project"] in projects, f"{c['commit']}: unknown project") | |
| if problems: | |
| print("\n".join(problems[:50])) | |
| print(f"{len(problems)} problem(s)") | |
| sys.exit(1) | |
| print(f"ok: {len(labels)} labels, {len(features)} feature rows, {len(commits)} commits, {len(projects)} projects") | |