Skip to content

Add Brazilian Portuguese familiar forms from Brazil's ballot names (#1495) - #1511

Merged
derek73 merged 9 commits into
masterfrom
feat/tse-familiar-forms
Nov 21, 2026
Merged

derek73 merged 9 commits into
masterfrom
feat/tse-familiar-forms

Conversation

@derek73

@derek73 derek73 commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Closes #1495.

Adds tools/vocab/familiar_tse.py, a generator of Brazilian Portuguese familiar-form candidates from the names Brazil's election candidates register for the ballot beside their civil names. It also ships the 1,030 familiar forms two readers agreed on, in pt-BR.toml. The 118 agreed alternate spellings are held and ship nowhere, as #1387's were.

The source and its licence

The source is the Superior Electoral Court's candidate files, consulta_cand_<year>.zip, for all 16 elections from 1994 to 2024.

Licence, confirmed 2026-11-20 from the court's own portal:

  • Each dataset's own record: package_show?id=candidatos-<year> gives license_id cc-by on every one of the 16 datasets, chosen from a licence list that also offers CC0, CC BY-SA and a non-commercial licence.
  • The FAQ: the portal's open data are published "sob licença aberta que permita sua livre utilização, consumo ou cruzamento, limitando-se a creditar a autoria ou a fonte".
  • No terms page: the portal has none of its own; the API calls are recorded in decisions/shipped-data-licences so the check can be re-taken.

Where it is credited: README.rst's License section, nameparser/vocab/pt-BR.toml, and tests/v2/test_licensing.py's _CREDITED. _CREDITED is now keyed by source, because the INE and the court are both CC BY. The data is measured, so the licence expression is unchanged.

What is kept where:

  • The requests use a generic client name.
  • The zips, the two names and a person key hashed before it is kept stay in the tools cache.
  • Nothing from the files is committed but the reviewed pairs: name against name, at 20 people or more.

The generator

The pair:

  • Ballot word: the ballot name's first word that is no title, no particle, not on the stop list (júnior, juninho, filho, neto, sobrinho, epithets) and not in the civil name.
  • Civil word: the civil given word it stands for, tried in order:
    1. the same first letter, with the form's last three letters inside it;
    2. the same first letter;
    3. the last three letters;
    4. else the first given word.
  • Given words: the civil word must be among the civil name's first two name words before its family name. The family name is the last word that is no particle, no single letter and no stop word.
  • People: a person counts once across elections, keyed by voter-registration number, else CPF, else the year's candidate number.

Answers to the issue's three questions (decided 2026-11-20):

  1. pt-BR alone. Nothing in the data contradicts it.
  2. A second filter only if a class is large and mechanical. One was, the bynames, so a filter was added.
  3. match_diff.py --base, after this change's own rows, plus the candidates' own names as the population measure.

The bar, raised from the issue's 10 to 20. The trial read 2024 alone. Sixteen elections multiplied the pairs to 7,899 at ten, eight times the trial's 990.

Two filters and a rescue, at 20+:

step pairs what it drops
neither filter 3,282
given-word filter 2,796 486 pairs whose civil word is not a given word: a surname cut short or misspelt (castr / castro), a surname's diminutive (castrinho / castro), or an occupation matched to a surname by its letters (enfermeira / pereira)
byname filter + lift rescue 1,491 a ballot word paired with 4+ civil given names at 10+ people each is a byname (365 words, among them irmão, dona, tia, saúde, sargento, enfermeira, pastora); 265 of their pairs are rescued

The rescue: a byname's pair is kept where its lift is ≥ 5 and it has ≥ 50 people. Lift is the share of the ballot word's people whose civil word is this one, over that word's share of everyone.

  • Kept: zé / josé 9.7, beto / roberto 13.7, chico / francisco 27.0, leo / leonardo 228.6.
  • Dropped: irmão / josé 1.2, tia / maria 2.4, dona / maria 3.7.
  • Why the 50-people bar, not a higher lift: lift alone rescued 678 rows. The lift that fits under 300 rows (~165) loses zé / josé. The bar lets 5 bynames through to the readers.

The review

Procedure:

  • Two readers per pair (Opus and Sonnet), in 31 chunks of 49 rows with 3 unmarked controls each, every reason the row's own.
  • Controls kept apart: 85 of 93 by Opus, 88 of 93 by Sonnet.

Rows read: the first build drew 1,505. Review then found a surname defect (below). The fixed tool no longer draws 15 of those rows, which leave the table, and draws one new pair, fernado / fernando, which two readers read as a spelling; it is held. That leaves 1,491.

Agreement: 1,369 of 1,491 (91.8%).

category rows
familiar 1,030, shipped
spelling 118, held
different-name 142
sibling 41
unclear 17
abbreviation 16
translation 5
split 122, ship nowhere

False pairs, by class (agreed different-names where both readers gave one class): epithet 50, another given name 28, occupation 24, surname 13, address 10, religious 4. No further filter was needed.

Measurements

  • Pair counts: FAMILIAR goes from 1,286 to 2,316 pairs; ALTERNATE_SPELLINGS is unchanged at 294.
  • Snapshot: tools/differential/snapshot.jsonl is byte-identical.
  • Tests: the full suite (55,525), the serial tests, the suite on Python 3.15 in its own environment, and the Sphinx doctest build all pass.
  • match_diff: tools/differential/match_diff.py --base against 3ca31c2, after Brazilian test rows in every shape the match reads:
    • Shapes covered: given name first, family comma, a second given name, capitals, and Tiao against the stored tião.
    • Result: 31,408 pairs under 22 settings. The key guarantee holds, and 18,258 of 690,976 rows move.
    • Default setting: only the table moves, in 16 given rows.
    • Verdicts: 52 become consistent, each under a setting accepting familiar-form, and none goes the other way.
  • Population, the candidates' own ballot and civil names (a fixed sample of 200,000 records, of which 173,819 differ):
    • Under familiar-form, consistent pairs go from 24,162 to 25,972 (+1,810, +1.0 point).
    • The default is unchanged at 23,817.
    • Most ballot names drop or keep the surname alone, which no familiar form reaches.

Docs

Reviews

Round 1: pr-review-toolkit code-reviewer, pr-test-analyzer, silent-failure-hunter and comment-analyzer, plus design-docs-reviewer. Fixed in b1630f3:

  • Surname pairs: the given-word filter let surname diminutives through where a civil name held one given name; three shipped as familiar forms (costinha / costa, teixeirinha / teixeira, borginho / borges).
  • The licence note: every generated reading's note said "CC0 or public-domain", false of CC BY. It now says "openly licensed", across 2,111 readings.
  • The kept reading: it was keyed by nothing and never re-checked. It is now named by the zip's digest and the reader's version, and checked whole.
  • Refusals added: a member cut inside its last field, a renamed ID column, a blank candidate number, and a year of no names.
  • Duplicate candidacies: a person's second candidacy in a year was dropped; it is now kept.
  • Drop counts: drops were not counted; they are now counted by reason.
  • Tests: about 30 of 50 mutants survived; many rows were added.
  • Docs: the recipe didn't reproduce (it compared against the whole table), and several counts were stale or mislabelled. The credit phrase now names the court alone, and the docs' "mostly ORCID's" claim and the release bullet's pt-BR claim are corrected.

Round 2, on the fix commit (code-reviewer, design-docs-reviewer). Fixed in e92286e and 5c57455:

  • A narrowing: the fix read a family name that is no name word (D'ÁVILA) as missing, which made a real second given name the family.
  • Untested checks: three of the fix's checks had no test that failed without them.
  • Stale figures: some were taken on the first build.

Round 3, on e92286e (code-reviewer). A stray single letter or a generation after the surname (DO O, JUNIOR) counted as the family name, which made the surname a given word. Fixed in e011f33: such a word ends no name. Three more surname diminutives leave the draw, and the figures were re-taken.

Flagged, not changed: santinho / santos ships. It is reached through civil names where Santos stands second of three words, and both readers agree it is a familiar form.

🤖 Generated with Claude Code

derek73 and others added 3 commits November 20, 2026 21:54
… names (#1495)

tools/vocab/familiar_tse.py fetches every election's candidate file from
the Superior Electoral Court's open-data portal (CC BY) and pairs each
candidate's ballot name with the civil given name it stands for, counting
people once across elections by a hashed key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ot names (#1495)

1,505 pairs at 20 people or more, after a given-word filter, a byname
filter and a lift rescue, read by two readers: 1,035 familiar forms ship
in pt-BR.toml, the 122 agreed spellings are held. The court's CC BY is
credited in pt-BR.toml and README.rst's License section.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he court (#1495)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@derek73 derek73 added this to the 3.2 milestone Nov 21, 2026
@derek73 derek73 added enhancement matching Name matching: Parser.matching(), check() and keys() labels Nov 21, 2026
@derek73 derek73 self-assigned this Nov 21, 2026
derek73 and others added 6 commits November 20, 2026 22:43
… and the note (#1495)

The given-word filter counts a second word only where another follows it,
dropping three shipped surname diminutives; the kept per-year reading is
named by its zip's digest and the reader's version and checked whole; a
member cut inside its last field, a renamed ID column, a blank candidate
number or a year of no names is refused; drops are counted by reason.
The note on every generated reading says openly licensed, not CC0, the
court's data being CC BY.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…est the fix's checks (#1495)

given_words took the last name word as the family name, so a surname with
an apostrophe or a hyphen made a real second given name the family; it
now reads the last word that is no particle. Tests hold a person's second
pair of names, a republished zip read again, a member of no candidate and
the drop counts. The entry's figures are re-taken on this tree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…1495)

JOÃO VIEIRA DO O read Vieira as a given word, the stray O taken as the
family; a single letter or a stop word ends no name now. Three more
surname diminutives leave the draw and the review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep both release-log bullets; regenerate nameparser/config/_index.py with tools/vocab/build.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@derek73
derek73 merged commit 488ea60 into master Nov 21, 2026
14 checks passed
@derek73
derek73 deleted the feat/tse-familiar-forms branch November 21, 2026 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement matching Name matching: Parser.matching(), check() and keys()

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Brazil's ballot names as a source of Brazilian Portuguese familiar forms (Paulinho / Paulo, Cida / Aparecida)

1 participant