Datasets:
Download scripts/duplicate_candidates.py from ulamai/UnsolvedAstronomy: direct link, hf CLI and curl.
- Browser
- Download file 2 kB
-
https://huggingface.co/datasets/ulamai/UnsolvedAstronomy/resolve/main/scripts/duplicate_candidates.py
- Command line
-
hf download hf://datasets/ulamai/UnsolvedAstronomy/scripts/duplicate_candidates.py
-
curl -L -o duplicate_candidates.py https://huggingface.co/datasets/ulamai/UnsolvedAstronomy/resolve/main/scripts/duplicate_candidates.py
2 kB
| #!/usr/bin/env python3 | |
| """ | |
| Duplicate and relation auditor for UnsolvedAstronomy v1.1.0. | |
| Verifies 0 duplicate canonical problem statements among published records and validates merged_duplicate links. | |
| """ | |
| import json | |
| import re | |
| import sys | |
| from collections import Counter | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parent.parent | |
| PROBLEMS_FILE = ROOT / "problems.json" | |
| ARCHIVED_FILE = ROOT / "archived_problems.json" | |
| def norm_text(s: str) -> str: | |
| return re.sub(r"[^a-z0-9]+", " ", (s or "").lower()).strip() | |
| def main(): | |
| if not PROBLEMS_FILE.exists(): | |
| print(f"Missing {PROBLEMS_FILE}") | |
| sys.exit(1) | |
| published = json.loads(PROBLEMS_FILE.read_text(encoding="utf-8")) | |
| archived = json.loads(ARCHIVED_FILE.read_text(encoding="utf-8")) if ARCHIVED_FILE.exists() else [] | |
| dups = [r for r in archived if r["status"] == "merged_duplicate"] | |
| stmt_norms = Counter(norm_text(r["statement"]) for r in published) | |
| collisions = {k: v for k, v in stmt_norms.items() if v > 1} | |
| title_norms = Counter(norm_text(r["title"]) for r in published) | |
| title_collisions = {k: v for k, v in title_norms.items() if v > 1} | |
| pub_ids = {r["id"] for r in published} | |
| bad_dup_targets = [r["id"] for r in dups if r.get("duplicate_of") not in pub_ids] | |
| low_src_records = [ | |
| r["id"] | |
| for r in published | |
| if len({s.get("source_id") for s in r.get("sources", []) if s.get("source_id")}) < 4 | |
| ] | |
| print(f"Checked {len(published)} published records and {len(dups)} merged_duplicate records.") | |
| print(f" Statement collisions among published: {len(collisions)}") | |
| print(f" Title collisions among published: {len(title_collisions)}") | |
| print(f" Published records with < 4 distinct literature sources: {len(low_src_records)}") | |
| print(f" Invalid duplicate_of targets: {len(bad_dup_targets)}") | |
| if collisions or title_collisions or low_src_records or bad_dup_targets: | |
| sys.exit(1) | |
| if __name__ == "__main__": | |
| main() | |