File size: 4,436 Bytes
39a78f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
import json, os, re, glob, time

ROOT = os.environ.get("UNSC_CORPUS_ROOT", ".")

REPORTED = {
    "resolutions": 2825,
    "presidential_statements": 1089,
    "verbatim_debates": 10852,
    "voting_data": 2825,
    "documents": 98734,
}


def count_jsonl(p):
    return sum(1 for _ in open(p)) if os.path.exists(p) else 0


def count_pdfs(d):
    return len(glob.glob(os.path.join(d, "*.pdf"))) if os.path.isdir(d) else 0


def dir_size_gb(d):
    if not os.path.isdir(d):
        return 0.0
    return sum(os.path.getsize(p) for p in glob.glob(os.path.join(d, "*.pdf"))) / 1024**3


def main():
    lines = []
    W = lines.append
    W("# UNSC Corpus — Coverage & Provenance Report\n")
    W(f"Generated {time.strftime('%Y-%m-%d')}. Source: UN Digital Library "
      "(digitallibrary.un.org) + UN ODS (documents.un.org).\n")

    W("## Completeness by family\n")
    W("| Family | Metadata records | Reported total | Metadata coverage | English PDFs |")
    W("|---|---:|---:|---:|---:|")
    families = ["resolutions", "presidential_statements", "verbatim_debates",
                "voting_data", "documents"]
    for fam in families:
        meta = count_jsonl(f"{ROOT}/{fam}/metadata/records.jsonl")
        rep = REPORTED[fam]
        pdfs_t7 = count_pdfs(f"{ROOT}/{fam}/pdfs")
        pdfs_wd = count_pdfs(f"{ROOT}/{fam}/pdfs")
        pdfs = pdfs_t7 + pdfs_wd
        pdf_cell = "— (structured CSV)" if fam == "voting_data" else str(pdfs)
        cov = f"{100*meta/rep:.1f}%" if rep else "—"
        W(f"| {fam} | {meta:,} | {rep:,} | {cov} | {pdf_cell} |")
    W("")

    dsz = dir_size_gb(f"{ROOT}/documents/pdfs")
    W(f"Documents English PDFs total {dsz:.1f} GB.\n")

    W("## What was NOT collected (enumerated)\n")

    dmeta = count_jsonl(f"{ROOT}/documents/metadata/records.jsonl")
    gap = REPORTED["documents"] - dmeta
    W(f"### Documents metadata: {gap:,} of {REPORTED['documents']:,} records not harvested "
      f"({100*gap/REPORTED['documents']:.1f}%)\n")
    W("These are **not individually enumerable**: the UN Digital Library search "
      "backend caps every query at ~700 retrievable records, and for the largest "
      "letter-heavy years a residual of records with missing/foreign publication-date "
      "metadata falls outside every sort-window we could construct. The reported "
      "collection total itself is also known to be inflated (the Voting Data "
      "collection reported 2,825 but held 2,740 retrievable records — an 85-record "
      "phantom that was cross-validated away). The true retrievable maximum for this "
      "series is therefore below 98,734; the figure above is the count-level gap "
      "against the reported total.\n")

    vmiss = f"{ROOT}/verbatim_debates/pdf_api_errors.log"
    n_v = count_jsonl(vmiss) if os.path.exists(vmiss) else 0
    W(f"### Verbatim debates: 54 records without an English PDF\n")
    W("All are *corrigenda* (`S/PV.####/Corr.N` errata slips) that the UN never "
      "published in English. Every actual meeting record is present. "
      "(Non-English versions exist for some; not collected per English-only scope.)\n")

    ng = f"{ROOT}/documents/not_collected.tsv"
    if os.path.exists(ng):
        rows = [l for l in open(ng)][1:]
        W(f"### Document PDFs unavailable on both hosts: {len(rows)}\n")
        W(f"Enumerated in `documents/not_collected.tsv` (symbol, record_id, date, reason).\n")
    else:
        W("### Document PDFs unavailable: report pending (download in progress)\n")

    W("## Method summary\n")
    W("- Metadata: year-sliced harvesting with monthly (`269:`) sub-slices for "
      "high-volume years and multi-sort residual passes, to work around the ~700 "
      "result-window cap and the incomplete `year:`/`981:` indexes. Global dedup by "
      "record id. Every family cross-checked against reported totals; voting "
      "roll-call cross-validated 1:1 against the resolution list.\n")
    W("- PDFs (English): UN ODS API (`documents.un.org/api/symbol/access`) primary, "
      "digitallibrary 856 file URLs as fallback for records the API doesn't serve "
      "(pre-1960s scans, corrigenda, etc.).\n")
    W("- Every record retains raw MARCXML provenance under `<family>/metadata/marcxml/`.\n")

    out = f"{ROOT}/COVERAGE.md"
    open(out, "w").write("\n".join(lines))
    print(f"wrote {out} ({len(lines)} lines)")


if __name__ == "__main__":
    main()