34 lines
1.4 KiB
Python
34 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Final CHECK for the arXiv cs.LG table extraction.
|
|
|
|
Usage: python3 verify_arxiv_csv.py <path-to-csv>
|
|
|
|
Exit 0 => artifact valid; nonzero => invalid.
|
|
"""
|
|
import csv
|
|
import re
|
|
import sys
|
|
|
|
EXPECTED_HEADER = ["arxiv_id", "title", "authors", "published", "abstract"]
|
|
ID_RE = re.compile(r"^[0-9]{4}\.[0-9]{4,5}$")
|
|
DATE_RE = re.compile(r"^[0-9]{4}-[0-9]{2}-[0-9]{2}$")
|
|
|
|
def main():
|
|
path = sys.argv[1] if len(sys.argv) > 1 else "/root/troupe-standup/wizard-work/ledger/arxiv-lg-recent.csv"
|
|
with open(path, newline="", encoding="utf-8") as f:
|
|
rows = list(csv.DictReader(f))
|
|
assert rows, "no data rows"
|
|
assert list(rows[0].keys()) == EXPECTED_HEADER, f"bad header {list(rows[0].keys())}"
|
|
assert len(rows) == 20, f"expected 20 rows, got {len(rows)}"
|
|
for i, r in enumerate(rows, start=1):
|
|
assert ID_RE.match(r["arxiv_id"].strip()), f"row {i} bad arxiv_id {r['arxiv_id']!r}"
|
|
assert DATE_RE.match(r["published"].strip()), f"row {i} bad date {r['published']!r}"
|
|
for col in ("title", "authors", "abstract"):
|
|
assert (r[col] or "").strip(), f"row {i} empty {col}"
|
|
dates = sorted({r["published"] for r in rows})
|
|
print(f"rows_ok=20 header_ok=1 ids_ok=1 dates_ok=1 date_range={dates[0]}..{dates[-1]}")
|
|
print("sample=" + rows[0]["arxiv_id"] + " " + rows[0]["title"][:50])
|
|
|
|
if __name__ == "__main__":
|
|
main()
|