Skip to content

Record a country on ctgov-officials and add ctgov-contacts - #1454

Merged
derek73 merged 3 commits into
masterfrom
claude/issue-1451-ctgov-country-c7c841
Nov 18, 2026
Merged

derek73 merged 3 commits into
masterfrom
claude/issue-1451-ctgov-country-c7c841

Conversation

@derek73

@derek73 derek73 commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Closes #1451

What changed

  • ctgov-officials records gain country: an ISO 3166-1 alpha-2 code. An official gets one only where every site of its study is in the same country. It is empty where the study lists no site, a site states no country, or the sites are in several countries. The affiliation text is not read. Source.group = "country", so config_diff.py diff --local ctgov-officials --group KR keeps one country. snapshot.py --local still reads the whole corpus, since it has no --group.

  • New sibling corpus ctgov-contacts (fetch_ctgov_contacts): the named contacts under each study's sites, each record holding name, role, study and the site's country, grouped the same way. It is a corpus of its own, so every count already quoted from ctgov-officials stays true.

  • CTGOV_COUNTRIES maps all 226 country names the registry writes (/api/v2/stats/field/values?fields=LocationCountry, 2026-11-18) to codes. A name the map does not hold fails the fetch, naming the name and the study.

  • Stale cache: a corpus fetched before this change, or read by another CTGOV_READ_VERSION, is refused on load with fetch <source> --refresh. It is never read as "no country". The check is _pinned on read_version, as jrc-names does it.

  • Gates against a moved key. Both fetches refuse a result where no record holds a country. They also refuse one past a measured share:

    • officials whose study lists no site, past CTGOV_MAX_NO_SITE = 0.25;
    • records at a site stating no country, past CTGOV_MAX_COUNTRYLESS = 0.01.

    A country or role that is not text fails the fetch, naming the study.

  • Docs: the module docstring, meta.json's detail counts, tools/differential/README.md's "Local corpora" (both rows, the read-version paragraph and the --group sentence), and the docstrings of config_diff.py, local_corpora.py, local_core.py and name_usage.py.

Choices the issue did not settle (please check)

  1. Central contacts are left out of ctgov-contacts. They belong to no site, so they have no country of their own.
  2. Repeats among contacts. ctgov-contacts keeps one record per name, role, study and country. A name listed again with the same role at another site of the same study in the same country is kept once and counted (repeated_in_study_and_country). Without this, multi-site studies would weight the counts.
  3. A study with any site stating no country gives its officials no country, following "every site" literally. In the real fetch this affects 83 officials.
  4. Four registry names have no current ISO code.
    • Kosovo → XK (user-assigned, in common use).
    • Serbia and Montenegro → CS, Federal Republic of Yugoslavia → YU, Netherlands Antilles → AN (former codes, ISO 3166-3).
    • Territories the registry names apart keep their own codes (PR, GU, RE, ...). Virgin Islands → VI: its sites are in Charlotte Amalie and Christiansted.
  5. Each corpus pages the registry on its own (two passes). Each pass is checked against its own data date.

Real re-fetch, 2026-11-18 (data as of 2026-11-18T10:00:05, 612,549 studies)

ctgov-officials: 539,368 officials (536,981 on 2026-10-21), 353,747 distinct names.

  • 453,060 records carry a country (84.0%), across 202 countries.
  • Empty: 47,075 in studies across several countries, 39,150 in studies listing no site, 83 in studies with a site stating no country.

Top 20 countries: US 163,648, CN 35,562, FR 25,140, CA 19,033, TR 18,690, GB 14,178, EG 13,073, DE 12,536, ES 11,681, IT 11,049, KR 9,556, DK 8,523, BR 7,462, NL 7,024, TW 6,610, CH 6,010, BE 5,667, PK 5,119, SE 5,080, IL 5,018.

ctgov-contacts: 522,688 contacts, 359,428 distinct names.

  • 522,686 carry a country (2 at a site stating none), across 194 countries.
  • 119,997 repeats dropped; 14,479 contacts without a name counted.

Top 20 countries: US 133,648, CN 82,379, FR 49,143, IT 26,823, ES 19,484, CA 17,703, DE 17,379, GB 15,711, KR 10,974, TR 10,325, EG 9,202, NL 8,388, TW 7,456, BE 7,447, BR 6,836, AU 6,798, IL 6,496, CH 5,814, DK 5,737, JP 5,042.

config_diff.local_names(..., ["KR", "TR"]) against the real corpora keeps 21,677 officials' names and 15,102 contacts' names.

Verification

  • uv run pytest passes: 49,920 passed. uv run mypy and uv run ruff check are clean.
  • New tests cover:
    • the single-country rule: one site, two sites in one country, two countries, no site, a site stating none, a blank country, a trailing-space name;
    • an unmapped name, for both corpora;
    • the stale-cache refusal, for both corpora, with no read version and with another one;
    • the sibling corpus: site countries, repeats, a nameless contact, central contacts left out, the officials' corpus untouched;
    • the repeat key, with any one of name, role, study or country differing;
    • the gates: no country at all, and each share at and past its bound;
    • a non-text country or role;
    • --group on both corpora.
  • Negative controls:
    • with the gates and type checks switched off, all 13 of their rows fail;
    • with the repeat key widened across studies, or with role dropped from it, the repeat test fails.
  • tools/differential/snapshot.jsonl is byte-identical. No parser code changed.

Review aspects run

pr-review-toolkit's code-reviewer, silent-failure-hunter, pr-test-analyzer and comment-analyzer ran on the first commit. Their findings are fixed in 302fc9f:

  • the gates against a renamed key;
  • the non-text role and country checks;
  • the repeat-key docs;
  • the row order in name_usage.py's docstring;
  • the missing test rows.

A second code-reviewer pass on the fix commit found no defects. It re-measured the gate shares across the whole registry (about 7.4% of studies with an official list no site), and its two nits are fixed in 00bb538.

🤖 Generated with Claude Code

derek73 and others added 3 commits November 18, 2026 13:25
An overall official takes the ISO code of the one country every site of
its study is in, and none otherwise; the study's site contacts go in a
sibling corpus, ctgov-contacts, each with its site's country. The
registry's country names are mapped to ISO 3166-1 alpha-2 codes, and an
unmapped name fails the fetch, naming it. Both corpora declare country
as their group, so config_diff.py --group keeps one country, and a
corpus fetched before the country is refused on load by a read version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of the country change: a renamed "country" or "locations" key
would have emptied every record's country without failing, since the
corpus-key guard reaches only names. Both fetches now refuse a corpus
holding no country, and one past a measured share of officials with no
site or of records at a site stating no country; a country or role that
is not text fails the fetch naming the study. The docs now give the
contacts' repeat key as name, role, study and country, the precedence of
the officials' site buckets, and where the counts are printed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@derek73 derek73 added this to the 3.2 milestone Nov 18, 2026
@derek73 derek73 self-assigned this Nov 18, 2026
@derek73

derek73 commented Nov 18, 2026

Copy link
Copy Markdown
Owner Author

The five choices listed under "Choices the issue did not settle" are accepted as made (2026-11-18): central contacts left out, repeats within a study and country kept once, no country where any site states none, the four codes for names with no current ISO code, and a pass of the registry per corpus.

@derek73
derek73 merged commit b78d5af into master Nov 18, 2026
14 checks passed
@derek73
derek73 deleted the claude/issue-1451-ctgov-country-c7c841 branch November 18, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Record a country for each name in the ctgov-officials local corpus, so its hand-typed names can be read per country

1 participant