File size: 6,945 Bytes
37ae1e2 ae03c09 37ae1e2 affaa54 37ae1e2 affaa54 ae03c09 37ae1e2 ae03c09 37ae1e2 affaa54 4df4d00 affaa54 37ae1e2 ae03c09 37ae1e2 ae03c09 409cbb4 ae03c09 37ae1e2 ae03c09 37ae1e2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | #!/usr/bin/env python3
"""Validate bibliographic metadata in the generated resource dataset."""
from __future__ import annotations
import csv
import re
import sys
from datetime import datetime, timezone
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
RESOURCES = ROOT / "data" / "resources.csv"
ARXIV_PUBLICATIONS = ROOT / "data" / "arxiv_publication_audit.csv"
YEAR_RE = re.compile(r"^(19|20)\d{2}$")
PROJECT_GITHUB_REPO = "chaoyue0307/awesome-loop-engineering"
PROJECT_PUBLICATION_SURFACES = {"GitHub", "GitHub Releases", "GitHub Discussions"}
REQUIRED_COLUMNS = {
"authors",
"publication_date",
"publication_year",
"publication_venue",
"publisher",
"doi",
"publication_note",
"primary_category",
"metadata_source",
"github_repo",
"url_kind",
"canonical_url",
"evidence_class",
}
def main() -> int:
with RESOURCES.open(encoding="utf-8", newline="") as handle:
reader = csv.DictReader(handle)
missing = REQUIRED_COLUMNS - set(reader.fieldnames or [])
if missing:
print(f"Missing publication columns: {', '.join(sorted(missing))}", file=sys.stderr)
return 1
rows = list(reader)
if not ARXIV_PUBLICATIONS.exists():
print("Missing data/arxiv_publication_audit.csv", file=sys.stderr)
return 1
with ARXIV_PUBLICATIONS.open(encoding="utf-8", newline="") as handle:
publication_rows = list(csv.DictReader(handle))
publications = {row["arxiv_id"]: row for row in publication_rows}
failures: list[str] = []
maximum_year = datetime.now(timezone.utc).year + 1
for row in rows:
row_id = row["row_id"]
year = row["publication_year"]
date = row["publication_date"]
if not row["publisher"]:
failures.append(f"{row_id}: publisher/source platform is missing")
if row["publisher"].strip().lower() == "awesome loop engineering":
failures.append(f"{row_id}: project name is exposed as a publisher")
if row["url_kind"] != "external" and row["evidence_class"] == "repository-native" and (
row["publication_venue"] != "GitHub" or row["publisher"] != "GitHub"
):
failures.append(f"{row_id}: repository-native artifact must use GitHub as its publishing platform")
if row["github_repo"].lower() == PROJECT_GITHUB_REPO and (
row["publication_venue"] not in PROJECT_PUBLICATION_SURFACES or row["publisher"] != "GitHub"
):
failures.append(f"{row_id}: project surface must identify GitHub, not the repository name, as its venue")
if PROJECT_GITHUB_REPO in row["publication_venue"].lower():
failures.append(f"{row_id}: project repository slug is exposed as a publication venue")
if not row["metadata_source"]:
failures.append(f"{row_id}: metadata provenance is missing")
if year:
if not YEAR_RE.fullmatch(year) or not 1900 <= int(year) <= maximum_year:
failures.append(f"{row_id}: invalid publication year {year!r}")
if date and not date.startswith(year):
failures.append(f"{row_id}: publication date {date!r} disagrees with year {year!r}")
if row["resource_type"] == "Paper":
if not row["authors"]:
failures.append(f"{row_id}: paper authors are missing")
if not year:
failures.append(f"{row_id}: paper publication year is missing")
if row["arxiv_id"]:
decision = publications.get(row["arxiv_id"])
if not decision:
failures.append(f"{row_id}: arXiv publication decision is missing")
continue
if not row["authors"]:
failures.append(f"{row_id}: arXiv authors are missing")
if not date:
failures.append(f"{row_id}: arXiv publication date is missing")
if decision["status"] == "preprint-only":
if row["publisher"] != "arXiv":
failures.append(f"{row_id}: preprint-only row has publisher {row['publisher']!r}")
if row["metadata_source"] not in {"arxiv-api", "arxiv-html-meta"}:
failures.append(f"{row_id}: preprint metadata is not backed by a primary arXiv source")
expected_evidence = "benchmark" if row["resource_type"] == "Benchmark" else "research-preprint"
if row["evidence_class"] != expected_evidence:
failures.append(f"{row_id}: preprint-only row has evidence class {row['evidence_class']!r}")
else:
expected = {
"publication_date": decision["publication_date"],
"publication_year": decision["publication_year"],
"publication_venue": decision["publication_venue"],
"publisher": decision["publisher"],
"doi": decision["doi"],
"canonical_url": decision["published_url"],
"metadata_source": decision["metadata_source"],
}
for field, expected_value in expected.items():
if row[field] != expected_value:
failures.append(
f"{row_id}: {field} differs from the verified publication record "
f"({row[field]!r} != {expected_value!r})"
)
if row["publisher"] == "arXiv":
failures.append(f"{row_id}: resolved publication still uses arXiv as publisher")
expected_evidence = "benchmark" if row["resource_type"] == "Benchmark" else "research-paper"
if row["evidence_class"] != expected_evidence:
failures.append(f"{row_id}: resolved publication has evidence class {row['evidence_class']!r}")
doi = row["doi"].lower()
if doi.startswith(("http://", "https://", "doi:")):
failures.append(f"{row_id}: DOI is not normalized")
if failures:
print("Publication metadata check failed:", file=sys.stderr)
for failure in failures[:50]:
print(f"- {failure}", file=sys.stderr)
if len(failures) > 50:
print(f"- ... and {len(failures) - 50} more", file=sys.stderr)
return 1
resource_arxiv_ids = {row["arxiv_id"] for row in rows if row["arxiv_id"]}
if resource_arxiv_ids != set(publications):
print("Publication metadata check failed:", file=sys.stderr)
print("- arXiv decision IDs do not match exported resource IDs", file=sys.stderr)
return 1
resolved = sum(row["status"] in {"accepted", "published"} for row in publication_rows)
print(f"Validated publication metadata for {len(rows)} resources ({resolved} arXiv venue upgrades).")
return 0
if __name__ == "__main__":
raise SystemExit(main())
|