From 8467bfdead8570fb6730f181ceaf13146712cce4 Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Thu, 19 Nov 2026 21:37:09 -0800 Subject: [PATCH] Suggest two_family_names from a list's common surnames (#1452) Parser.suggest now decides rules/O6's two_family_names. A new signal, Signal.FIRST_SURNAME, reads each name under the suggested reader with the switch off and on: a common surname (COMMON_SURNAMES) where the switch would take a first surname votes True, a father's name there votes False and disagrees with a decided switch, and a common given name casts no vote. The switch is turned on, the bare switch and never a pack, where at least three names, more than 30% of every name it would change and more than the votes against carry the surname; it is weighed only under a given-first order, with the East Slavic rule neither decided nor on the base and the base's switch off, and a group never turns it off. Each Signal member votes on one setting, named in one table (_SETTING_OF) the deciding sites read. The shared second-to-last word the issue also proposed is not built: measured, it decides Vietnamese, Pakistani and Bangladeshi lists. No must-not-move country (BD, GH, KE, PK, VN, AO, MZ, TR) gets the switch at any size from 2 to 2,000 names; Spanish, Mexican, Colombian and Peruvian lists get it from 10 to 20 names. suggest_measure.py gains the orcid-span-CC populations and the two_family, whole and switch rows; the docs, a decisions entry and a release-log bullet record the measurement. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 2 +- docs/design/decisions/group-suggestion.md | 25 +- docs/getting-started.rst | 8 +- docs/policy.rst | 6 +- docs/release_log.rst | 1 + docs/suggest.rst | 115 ++++++++- nameparser/_parser.py | 17 +- nameparser/_suggest.py | 219 ++++++++++++++-- tests/v2/test_suggest.py | 298 +++++++++++++++++++++- tools/differential/README.md | 4 +- tools/differential/suggest_measure.py | 151 ++++++++++- 11 files changed, 785 insertions(+), 61 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index f8cae1e6f..f2ede1cad 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -326,7 +326,7 @@ The 2.0 rewrite landed as underscore-private modules beside the v1 code, which 2 **Measuring a change to name matching: use `tools/differential/match_diff.py --base `.** A change to `nameparser/_match.py`, or to the vocabulary only the name match reads (`same_as`, `familiar`), moves no parse, so the snapshot and every corpus check below report nothing; `match_diff.py` lists every name pair whose `check` result or keys moved, under twenty-two settings, and every consistent pair sharing no key (#1278). A clean run vouches only for the shapes its draw holds: it draws its pairs from tests/v2/test_match.py and the corpora, so a change to a shape no drawn pair holds reports 0 moves (#1390 moved 0 of 687,500 rows until its own test rows existed). Add the change's rows to the test file first, then read the run. A setting naming an outcome the base does not know subtracts nothing there, so `-joined` against a base older than #1261 compares a caller who drops `joined` with the old default, which is the claim that caller keeps what they accepted. The base is the branch's merge base, re-pointed for each branch: a scratch base kept from the previous PR measures that PR's moves too, and #1261's first figures came from #1262's base, found by review. #1221, #1267 and #1260 each wrote a throwaway oracle for this first (tools/differential/README.md, "Measuring a change"). It parses under `Parser()` and `locales.ES` alone, so a change to how a caller's `Lexicon` edit is applied moves nothing in it by construction (#1404's `remove` of a familiar pair: 0 moves, which vouches only that the default did not move), and is tested through a matcher built on the edited lexicon. And an edit that names a word the match reads must compare it as the match does: the familiar index files each name under its folded forms (`_lexicon._forms`), so #1404's first build, cutting a pair by its stored spelling, left `Alex` / `Alejandro` consistent through the pair `mul.toml` stores on `álex`, found only because a test asked the matcher and not the lexicon's readings; give such an edit a row whose stored word differs from the written one by an accent and by a transcription (`ü` / `ue`). -**Measuring a change to the group suggester: use `tools/differential/suggest_measure.py`.** Run it after any change to `nameparser/_suggest.py`, to `nameparser/config/_order_names.py` (or `tools/vocab/order_names.py`, which writes it) or to a predicate a signal reads (the capitals, particle and patronymic tests, and the title, suffix and numeral tests a name is read past), or to rules/O9, whose reading the `capitals_as_family` vote asks of the parse itself: `suggest` moves no parse, so the snapshot and every corpus check report nothing. It draws groups of known order, 2, 3, 4, 5, 10, 20, 50 and 200 names by default (a change to a threshold adds `--sizes 2,3,4,5,10,20,50,100,200,500,1000,2000`: a share counted among the names that vote holds at 200 names and fails past it, which no default size shows, and #1442's two stray votes decided lists of 500 and more for that reason), from the local corpora and reports the share of groups read right by size, the same-order rows being the anti-goal (at least 95% at every size, save `pv-listed-given`'s two same-order rows, a list of nothing but given names that are surnames the ORCID surname table lists (`Cooper`, `Burke`, `Clarke`), which that table reads the wrong way round, a cost left open (decisions/group-suggestion, 2026-11-19 #1364), save `orcid-givcaps`' two same-order rows, a list writing its given names in capitals (`ANNA Smith`), which the capitals signal reads the wrong way round by design (decisions/group-suggestion, 2026-11-12 CAPITALS), and `orcid-byline-joined`'s given-first row at 50 and 100 names, and at 200 until #1357, a list of nothing but `AM Hoy` bylines that the few names the name tables vote on decide (decisions/group-suggestion, 2026-11-14 #1355, which took `orcid-byline`'s own row off this list, as #1397 took `orcid-famcaps-short`'s); groups of 2 to 4 are where #1308's final review found a patronymic rule forcing given-first on a family-first base); `--set NAME=VALUE` overrides a threshold, and `--set _MIN_VOTES=1000000 --set _MIN_PATRONYMIC_VOTES=1000000 --set _MIN_RUN_NAMES=1000000` decides nothing and is the harness proof (the order count alone leaves the patronymic rule free to decide its own given-first order, and the two vote counts leave the letters setting free to decide; `_MIN_VOTES` also holds `capitals_as_family`, whose table `--set _MIN_CAPITALS_LETTERS=1000000` empties alone). A table change also moves the `print(suggestion)` evidence docs/getting-started.rst and docs/suggest.rst show as doctests, which `uv run pytest` does not run: run `uv run sphinx-build -b doctest docs ` too (#1374's ORCID table made `Wang Xiaoming` a given-name vote and failed every build job). Its figures are quoted in `Parser.suggest`'s docstring, docs/suggest.rst and docs/design/decisions/group-suggestion.md; re-take all three when they move (decisions/group-suggestion's THRESHOLDS entry names the command, and its latest dated entries carrying re-taken sizes, 2026-11-19 #1364's and #1447's, hold the figures the other two round; the 2026-11-12 CAPITALS entry holds the `capitals_as_family` table, which the docstring's and docs/suggest.rst's capitals sentences round). A signal that reads one of the pipeline's predicates must read it exactly where the pipeline's rule does, no wider and no narrower, and its tests need a row at each edge: #1310's patronymic signal first voted an `-ovich` ending on any word (wider: two-word `Abramovich Roman` decided East Slavic and forced given-first), then its fix refused one on the first word, which rules/O1 never asks about (narrower: `Abramovich Roman Arkadyevich`, which the rule reads right, cast nothing). Only the second review caught the narrowing. A signal that votes where exactly ONE end of a name is listed votes by the other end alone once one end is no longer read: #1355's first sketch stopped looking up a short capitals word opening a name, and `WU Zhi` then cast a given-first surname vote by `Zhi`, so the shipped rule silences the signal on the whole name; when a rule stops reading a word, put a name whose other word is listed too in its grid. And a rule keyed to a word's shape needs a population of nothing but that shape: the default populations mix short capitals surnames with long ones, so the ending word's twin of that defect (`Zhi LI`) went unseen from #1308 until #1355 cut `orcid-famcaps-short`, and #1397 fixed it (decisions/group-suggestion, 2026-11-14 #1355 and #1397). A setting has more than one effect, and a suggestion that leaves something out leaves it out on every base: #1356 was first decided on "the East Slavic rule stands down under a family-first order", true of its reordering and false of its `patronymic` view, and PR #1399 as first pushed then kept every family-first base's order. Five names written `Zzyvan Petrovich Qqsidorov` under `FAMILY_FIRST` were read family `Zzyvan` where master moved the base and read them right; and `SIDOROV Ivan Petrovich` five times under `FAMILY_FIRST_GIVEN_LAST` lost the rule, though `capitals_as_family`, suggested in the same patch, makes the rule name the patronymic there. Review found both; the tool's table was identical with and without them, its populations then holding neither shape and no `FAMILY_FIRST_GIVEN_LAST` base anywhere in it (it has read the parliament lists under one since, which catches the second kind on a real list; its draws still run under two bases). Before deciding what a suggestion leaves out, sweep every base order × every switch the same patch can turn on × both written positions of the word the rule reads, and compare whole names read right (given and family), not the family alone: `FAMILY_FIRST_GIVEN_LAST` reads the family of `Sidorov Ivan Petrovich` right and its given name wrong, which a family count scored as nothing to fix. One signal is wider on purpose, and says so where it is decided: the letters signal (#1254) counts a run joined with full stops (`B.K.`), which rules/O8 never moves, beside the spaced runs it does, since three quarters of Nepal's runs are written joined (decisions/group-suggestion, 2026-11-11 LETTER RUNS); a test holds every other run to the rule exactly. +**Measuring a change to the group suggester: use `tools/differential/suggest_measure.py`.** Run it after any change to `nameparser/_suggest.py`, to `nameparser/config/_order_names.py` (or `tools/vocab/order_names.py`, which writes it) or to a predicate a signal reads (the capitals, particle and patronymic tests, and the title, suffix and numeral tests a name is read past), or to rules/O9 or rules/O6, whose readings the `capitals_as_family` and `two_family_names` votes ask of the parse itself: `suggest` moves no parse, so the snapshot and every corpus check report nothing. It draws groups of known order, 2, 3, 4, 5, 10, 20, 50 and 200 names by default (a change to a threshold adds `--sizes 2,3,4,5,10,20,50,100,200,500,1000,2000`: a share counted among the names that vote holds at 200 names and fails past it, which no default size shows, and #1442's two stray votes decided lists of 500 and more for that reason), from the local corpora and reports the share of groups read right by size, the same-order rows being the anti-goal (at least 95% at every size, save `pv-listed-given`'s two same-order rows, a list of nothing but given names that are surnames the ORCID surname table lists (`Cooper`, `Burke`, `Clarke`), which that table reads the wrong way round, a cost left open (decisions/group-suggestion, 2026-11-19 #1364), save `orcid-givcaps`' two same-order rows, a list writing its given names in capitals (`ANNA Smith`), which the capitals signal reads the wrong way round by design (decisions/group-suggestion, 2026-11-12 CAPITALS), and `orcid-byline-joined`'s given-first row at 50 and 100 names, and at 200 until #1357, a list of nothing but `AM Hoy` bylines that the few names the name tables vote on decide (decisions/group-suggestion, 2026-11-14 #1355, which took `orcid-byline`'s own row off this list, as #1397 took `orcid-famcaps-short`'s); groups of 2 to 4 are where #1308's final review found a patronymic rule forcing given-first on a family-first base); `--set NAME=VALUE` overrides a threshold, and `--set _MIN_VOTES=1000000 --set _MIN_PATRONYMIC_VOTES=1000000 --set _MIN_RUN_NAMES=1000000 --set _MIN_TWO_FAMILY_VOTES=1000000` decides nothing and is the harness proof (the order count alone leaves the patronymic rule free to decide its own given-first order, the two vote counts leave the letters setting free to decide, and the last holds `two_family_names`; `_MIN_VOTES` also holds `capitals_as_family`, whose table `--set _MIN_CAPITALS_LETTERS=1000000` empties alone). A change to the `two_family_names` vote reads the `orcid-span-CC` populations (ORCID holders of a country, the boxes saying which words are the family) by country: the groups deciding the switch, which the countries the switch costs (Bangladesh, Ghana, Kenya, Pakistan, Vietnam, Angola, Mozambique, Turkey) must not reach, and whole names right under the suggestion against the base (decisions/group-suggestion, 2026-11-19 #1452). A table change also moves the `print(suggestion)` evidence docs/getting-started.rst and docs/suggest.rst show as doctests, which `uv run pytest` does not run: run `uv run sphinx-build -b doctest docs ` too (#1374's ORCID table made `Wang Xiaoming` a given-name vote and failed every build job). Its figures are quoted in `Parser.suggest`'s docstring, docs/suggest.rst and docs/design/decisions/group-suggestion.md; re-take all three when they move (decisions/group-suggestion's THRESHOLDS entry names the command, and its latest dated entries carrying re-taken sizes, 2026-11-19 #1364's, #1447's and #1452's, hold the figures the other two round; the 2026-11-12 CAPITALS entry holds the `capitals_as_family` table, which the docstring's and docs/suggest.rst's capitals sentences round). A signal that reads one of the pipeline's predicates must read it exactly where the pipeline's rule does, no wider and no narrower, and its tests need a row at each edge: #1310's patronymic signal first voted an `-ovich` ending on any word (wider: two-word `Abramovich Roman` decided East Slavic and forced given-first), then its fix refused one on the first word, which rules/O1 never asks about (narrower: `Abramovich Roman Arkadyevich`, which the rule reads right, cast nothing). Only the second review caught the narrowing. A signal that votes where exactly ONE end of a name is listed votes by the other end alone once one end is no longer read: #1355's first sketch stopped looking up a short capitals word opening a name, and `WU Zhi` then cast a given-first surname vote by `Zhi`, so the shipped rule silences the signal on the whole name; when a rule stops reading a word, put a name whose other word is listed too in its grid. And a rule keyed to a word's shape needs a population of nothing but that shape: the default populations mix short capitals surnames with long ones, so the ending word's twin of that defect (`Zhi LI`) went unseen from #1308 until #1355 cut `orcid-famcaps-short`, and #1397 fixed it (decisions/group-suggestion, 2026-11-14 #1355 and #1397). A setting has more than one effect, and a suggestion that leaves something out leaves it out on every base: #1356 was first decided on "the East Slavic rule stands down under a family-first order", true of its reordering and false of its `patronymic` view, and PR #1399 as first pushed then kept every family-first base's order. Five names written `Zzyvan Petrovich Qqsidorov` under `FAMILY_FIRST` were read family `Zzyvan` where master moved the base and read them right; and `SIDOROV Ivan Petrovich` five times under `FAMILY_FIRST_GIVEN_LAST` lost the rule, though `capitals_as_family`, suggested in the same patch, makes the rule name the patronymic there. Review found both; the tool's table was identical with and without them, its populations then holding neither shape and no `FAMILY_FIRST_GIVEN_LAST` base anywhere in it (it has read the parliament lists under one since, which catches the second kind on a real list; its draws still run under two bases). Before deciding what a suggestion leaves out, sweep every base order × every switch the same patch can turn on × both written positions of the word the rule reads, and compare whole names read right (given and family), not the family alone: `FAMILY_FIRST_GIVEN_LAST` reads the family of `Sidorov Ivan Petrovich` right and its given name wrong, which a family count scored as nothing to fix. One signal is wider on purpose, and says so where it is decided: the letters signal (#1254) counts a run joined with full stops (`B.K.`), which rules/O8 never moves, beside the spaced runs it does, since three quarters of Nepal's runs are written joined (decisions/group-suggestion, 2026-11-11 LETTER RUNS); a test holds every other run to the rule exactly. **Validating a new parsing rule** — before implementing, simulate it in a throwaway script against `TEST_NAMES` (plus a few target-language examples) to catch regressions/false-positives early. E.g. this surfaced the `last_base` `do`/`st`/`mc` empties and the patronymic `"David Michael Abramovich"` false-reorder. After the change, `tests/v2/test_snapshot.py` lists every corpus name it moved, grouped by changed field -- read them, and re-record with `uv run python tools/differential/snapshot.py --record` once every move is intended, so the PR diff of `snapshot.jsonl` shows the reviewer the same list. `uv run python tools/differential/cldr_agreement.py` reports how the tree's agreement with CLDR's stated name fields moved; `tests/v2/test_cldr_agreement.py` fails on any move, and `tools/differential/cldr_agreement.json` doubles as a measured list of names the parser and CLDR read differently. The same command and test score the GND corpus's real names (`gnd_fields.jsonl`, record `gnd_agreement.json`) by the same rules, and `--record` rewrites every record, printing per source what it accepts. A locale-pack change reads the second view the same command prints, per pack (`cldr_agreement_locales.json`, #672, and `wikidata_native_agreement_locales.json` for real Han and kana names); its `JA` rows run only with the `ja` extra installed. A change to Han, Hangul or kana order or to Korean segmentation reads `wikidata_native_agreement.json` too: the only real names in those scripts the corpora hold. It holds no honorific, so a change to the honorific peel moves nothing there. A change to comma or credential handling also reads the local corpus of hand-typed names (`snapshot.py --local ctgov-officials --base `, which reads the base from a baseline kept for its package's files and never the shared snapshot beside the corpus (a base read once from the same fetch is copied rather than parsed again; `--sample N` reads a fixed sample while iterating; the shared snapshot beside the corpus is one file per source for every worktree, and #752's phase 2f found ctgov reporting a sibling branch's 1,334 joined-credential readings as its own moves against it); tools/differential/README.md's "Local corpora"): the one population of names nobody chose for a test or a catalog, so it shows how often each shape is typed, and the one no CI run sees. A change to title handling reads `ukec-individuals` the same way: UK donors' names in spoken order and mixed case, in 8,219 of whose 15,214 `parse()` read a title on 2026-10-22. A change to English titles, honorifics or post-nominals also reads `snapshot.py --local govuk-people` the same way: GOV.UK's display names of ministers, officials and officers, the title run and the post-nominals as an office writes them (`The Rt Hon`, `Sir`, `Baroness`, ranks; `KC`, `CBE`, `KCB`), in 2,093 of whose 6,021 `parse()` read one or both on 2026-10-30. A change to Spanish titles, to the `es` pack, or to how a title marks where a name starts after an office reads `snapshot.py --local dof-signatures` the same way: the names in the signature blocks of Mexico's Diario Oficial for 2025, cut from the clause that names the signatory's office, 65.4% of its 33,565 signatures opening with a title (`Lic.`, `Dr.`, `Mtro.`, `C.`, `Licenciada`, `C.P.`), whose first word `parse()` read as a title in 82.1% and `parser_for(locales.ES)` in 86.8% on 2026-10-31. A change to particles or generational words reads `snapshot.py --local tse-donors` the same way, Brazilian names in spoken order dense with both. A change to initials, to a title word outside English, or to how a script's combining marks are read reads `snapshot.py --local nepal-candidates` the same way: Nepal's local election candidates, each a romanized name (surnames written as initials, `B.K.`, `K.C.`; honorific titles such as `Guru` in front, `Shekh`, a title there until #752's phase 2j made it one only inside a title phrase, and `Md.`, a title by its period's shape until #1383 made it Muhammad written short, the given name) beside the same name in Devanagari, written with vowel signs and the virama, combining marks the letter-shape tests do not count as letters (decisions/nfd-shapes), and with the joiners ZWJ and ZWNJ. It is the only large population of South Asian names the corpora hold, and its corpus reads both scripts. A change to non-Latin scripts or to Arabic-script names reads `snapshot.py --local jrc-names` the same way, and `local_corpora.py groups jrc-names`: the spellings of one person across scripts and transliterations, harvested from news text, with 17,074 Arabic-script spellings where the committed corpora hold 315 distinct names with an Arabic letter, 96 of them CLDR's fictional renderings (2026-10-24), and under a licence that keeps even a reading of one of its names in the cache. A change to patronymics, to Turkic or East Slavic names, to Indic titles and initials, or to Slavic or Portuguese double surnames reads `snapshot.py --local opensanctions-parliaments --base ` the same way, and `local_corpora.py groups opensanctions-parliaments`: the members of twenty-eight national chambers as each parliament writes them (Azerbaijan, the Central Asian chambers, Turkey, Croatia, Slovenia, Slovakia, Portugal, India, Ukraine, Belarus, Russia, Indonesia, Ethiopia, South Korea, Israel, Mongolia, and since 2026-11-19 Malaysia, Pakistan's two chambers, Egypt and Somalia, #1465) and Indonesia's 2018 regional heads, read through OpenSanctions, 26,515 spellings of 20,856 members on 2026-11-19 (24,302 of 19,283 on 2026-11-12, before the five chambers and some other lists' newer exports; 24,084 of 19,216 on 2026-11-08, before the Khural and other lists' newer exports), some members' aliases in another script (Kazakh beside Russian Cyrillic, Uzbek Cyrillic beside Latin, Devanagari beside Latin, Hangul and Hanja or Hebrew beside Latin) or with a title (`Shri`, `Smt.`), the population issues #1186 to #1192 were read from, and the one that measures Indonesia's `H.` and `Imam` (#1205, #1206) Ethiopia's father's name (#1203), Korea's Hangul and Hanja (#1213, #1215, #1216) Israel's Hebrew (#1209 to #1211) and Mongolia's Cyrillic, the father's name first (#1237, `mn_parliament`, 126 members, added 2026-11-12), and Egypt's Arabic-script names, each written short and with the full chain of names (#1072, #1464); `config_diff.py --group ` keeps one parliament. A change to Malay, Indian-Malaysian or Chinese-Malaysian names (`bin`, `binti`, `B.`, `bt`, `a/l`, `a/p`, `anak`, the `@` alias, `MD`, honorifics such as `Ustaz` and `Cikgu` opening a name, a Chinese name written family first) or to names written wholly in capitals reads `snapshot.py --local my-candidates --base ` the same way: Malaysia's election candidates of 2008 to 2023 as their ballots name them, in capitals, 3,077 distinct names on 2026-11-19, grouped by the ethnicity each file states (`config_diff.py --group chinese`), the population issues #1467, #1468, #1164, #1183 and #1179 were read from. A change that cuts one written word across two fields, or joins two written words, first reads how `local_agreement.py` compares a box (`agrees`, tools/differential/README.md): 3.1's #1296 cut `B.A.S.D.` into given `B.`, middle `A.S.D.`, and 1,140 `orcid-researchers` records scored a miss though read right until #1470 (measured 2026-11-19). A change to which field a word lands in also reads `local_agreement.py psc-individuals --base ` the same way: real names with the four boxes their filers typed them into (UK companies' people with significant control), scored field by field and by nationality; and `local_agreement.py orcid-researchers --base `, ORCID holders' own two boxes (given names, family name) from every country, scored by the country they work or live in -- a population each person split for themselves, academic but worldwide, the one to read for a change a language pack makes. Its `name` is COMPOSED from those boxes, given first, so it cannot show which word a writer put first: a count of where a word falls in it is fixed by construction, and #1163's 538 records with the trailing letters in the family box against 0 with the word before them (`Lakshmi R S`, never `R S Lakshmi`) reproduced from that field. Order is measured on the free-text `credit` name (125,960 of the 2026-10-27 fetch's 1,831,533 records, which lean towards bibliographic bylines), against the boxes (decisions/O8); and `local_agreement.py patentsview-inventors --base `, US patents' inventors in the two boxes their filings give, split by a professional filer, with how many people filed under each name in each country, the one to read for how common a name's word is among a country's US-patent inventors. A change to titles or post-nominals, or to the `cs` pack, reads `local_agreement.py cz-candidates --base `, and with `--locale cs` too: Czech election candidates' four boxes (the title before the name, given names, surname, the title after it), scored by election, the only population whose titles are stated apart from the name, 36% of its 170,181 records titled (2026-10-30), nearly all academic degrees; its names are composed from the boxes (`Ing. Jan Novák, Ph.D.`), so it says nothing about how a writer spaces or punctuates them. A change to family-first order, to Vietnamese names or to their titles reads `local_agreement.py uit-vinames --base ` and `local_agreement.py vn-assembly --base `, and with `--locale vi`, `locales.VI` being that pack (#1108): 21,090 distinct names and 499 National Assembly deputies written family name first with their diacritics, whose parts no one filed but the convention derives (first word the family, last the given, the words between the middle name), so they score middle names, which ORCID's two boxes cannot, and `vn-assembly` the `GS.`/`PGS.`/`TS.`/`ThS.` titles composed from the education each deputy states. These are the only real fielded populations outside the committed fields files, and no CI run sees them either. diff --git a/docs/design/decisions/group-suggestion.md b/docs/design/decisions/group-suggestion.md index 4445f00a7..1e45912ef 100644 --- a/docs/design/decisions/group-suggestion.md +++ b/docs/design/decisions/group-suggestion.md @@ -7,7 +7,7 @@ - The given-name table is derived from ORCID's public data file (CC0), per stated country the words its holders most often typed first in the given-name box, replacing the derivation from nam_dict (GNU FDL 1.2, which seeded the shipped familiar forms until decisions/name-matching's 2026-11-12 ENGLISH ONLY UNTIL REBUILT) approved on 2026-11-10 and in no release — 2026-11-12 GIVEN NAMES FROM ORCID. - The given-name table's size and the rest of its filter (the top 500 per country, each typed first in the given-name box at least 3 times there, at least 20 uses, no full stop, no word the default lexicon reads as a title outside `titles_ambiguous`) and the hand-kept surname lists — 2026-11-10 TABLES, 2026-11-12 GIVEN NAMES FROM ORCID. - The given-name table keeps a name written in ORCID's family box in at most 10% of its uses, and refuses every word the default lexicon lists as a suffix, the ones that may also be a name included, and every title it lists as an abbreviation — 2026-11-15 #1357. -- A second surname table, the given-name table's mirror: every word ORCID's holders typed in the family-name box 100 times or more and in the given-name box in at most 5% of their uses, less the other tables' words, the titles and suffixes the given names refuse, the lexicon's particles, conjunctions, bound given names, maiden markers and Hangul surnames, and the Turkic patronymic markers; mostly Spanish surnames. It votes with the romanized table as one surname signal, under that signal's rules (a listed word at one end and not at the other; the two- and three-letter capitals exclusions); no census-derived table for English until a real list written family first without commas is found — 2026-11-19 #1364. +- A second surname table, the given-name table's mirror: every word ORCID's holders typed in the family-name box 100 times or more and in the given-name box in at most 5% of their uses, less the other tables' words, the titles and suffixes the given names refuse, the lexicon's particles, conjunctions, bound given names, maiden markers and Hangul surnames, and the Turkic patronymic markers; mostly Spanish surnames. It votes with the romanized table as one surname signal, under that signal's rules (a listed word at one end and not at the other; the two- and three-letter capitals exclusions), and alone, since 2026-11-19 #1452, on `two_family_names`, so a change to it is measured on that setting's rows too; no census-derived table for English until a real list written family first without commas is found — 2026-11-19 #1364. - What `suggest` decides for a group is one release's answer, not a promise across releases: the tables and thresholds are tuned between them, so a caller keeps the settings applied (the patch, or the `Policy` it made) with the data; nothing promises that a later release suggests the same settings for the same names — 2026-11-15 ACROSS RELEASES. - The evidence declined (the vocabulary's name readings, `Reading.languages`, the familiar forms) — 2026-11-10 DECLINED. - A comma name states its own order and does not vote on order — 2026-11-10 SIGNALS. @@ -17,6 +17,9 @@ - A patronymic votes only where the pipeline's rule reads one (rules/O1's three name words, rules/O2's four, and since 2026-11-12 #1187 its three with the marker last), a name is read past its listed titles and post-nominals, and a comma followed by post-nominals alone reads the name before it — 2026-11-10 FIX WAVE. - An East Slavic patronymic also votes on the order, by where it stands as rules/O1 reads it (the ending on the middle word for given-first, whatever the last word ends in; otherwise family-first), under every base order, as a signal of its own, `Signal.PATRONYMIC_POSITION`; a Turkic patronymic casts no such vote — 2026-11-19 #1447. - One public `Signal` member per kind of vote: a signal votes on one setting, and a kind of evidence that votes on a second setting adds a member rather than a field on `NameEvidence` or a vote counted only in the tally — 2026-11-19 #1447. +- Each `Signal` member votes on one setting, named in one table (`_suggest._SETTING_OF`) that every site deciding which setting a vote is on reads (`_order_ends`, `_checked_vote`, `_setting_of`, and `_disagrees` through `_order_ends`), so a member voting on a new setting is a row there — 2026-11-19 #1452. +- `two_family_names` (rules/O6) is turned on, the bare switch and never a pack, where at least three names, more than three in ten of every name the switch would change (a comma name and one the signals do not split included) and more than the names voting against it, carry a common surname of `COMMON_SURNAMES` where the switch would take a first surname (`Signal.FIRST_SURNAME` voting `True`); a father's name there votes `False` and disagrees with a decided switch; a name carrying a common given name there casts no vote; it is weighed only after the order, and only where that order is given-first, the East Slavic rule neither decided nor on the base, and the base's switch off; a group never turns it off — 2026-11-19 #1452. +- A second-to-last word ending other names of the list (the shared-surname signal of #1452's text) casts no vote on `two_family_names` — 2026-11-19 #1452. - An order is decided by at least two names, more than two thirds of the names casting an order vote and at least 1% of the group's names a comma does not leave out; a patronymic rule by at least five names carrying it and more than four in five of the names casting any vote; otherwise the base stands — 2026-11-10 THRESHOLDS, 2026-11-16 ORDER FLOOR. - Where any name casts a trailing-initial vote, the votes are cast only where at least three names, and at least 60% of the group's names holding a name word, end in initials no other signal in the same name contradicts; elsewhere every one is set aside, a contested one included (60% kept after a curve of lower shares and a minimum of 2 names, each declined), the order evidence's note says how many names end so, and the patronymic evidence's note how many names whose only vote was set aside still count in its share — 2026-11-11 TRAILING INITIAL. - `initials_as_family` (rules/O8) is turned on where one run of letters ends at least two of the group's names and at least half of the names ending in a run, a spaced run counted where the rule moves it and a run joined with full stops (`B.K.`) counted beside it; a group decided so casts no trailing-initial vote on its order; a group never turns the switch off, and a base reading names family first decides nothing — 2026-11-11 LETTER RUNS. @@ -28,7 +31,7 @@ - A name word in a script that writes no initials followed by a letter of it casts no trailing-initial vote, since no byline writes such a name before an initial, as rules/T5 and the order report read it: a group of Thai or Burmese names, each a word and a letter, suggests nothing — 2026-11-12 #1256. - A caller with a large list is told a sample of a few hundred names from each source is enough: nearly every kind of list measured is read right from 200 names, a longer list is rarely better (bylines written given first under a family-first base are the one kind measured that kept improving), and since the 1% floor no list measured in its base's own order is read worse at 2,000 names — 2026-11-16 #1442, 2026-11-16 ORDER FLOOR. -Open: the other three settings count their shares among the names with evidence on them, never the group, so a few stray names decide `patronymic_rules`, `initials_as_family` or `capitals_as_family` in a long silent list (2026-11-16 ORDER FLOOR, its bullet on the other settings); no measured population moves on any of them, and no issue is filed. A group gate for the short capitals words, under which one votes where another name of the list writes a longer capitals word at the same end, measured and not taken for 3.1 (2026-11-14 #1355, its Declined bullet), to weigh beside #1402, which was decided 2026-11-19, left as it reads (decisions/O9). For a list mixing East Slavic and Turkic patronymics (uz_senate, kz_senate), suggesting both rules, and reading the Kazakh `-uly` and `-kyzy` endings as a Turkic signal, are not taken for 3.1 and not decided against (2026-11-15 #1356, its Not taken bullet). `_MIN_PATRONYMIC_VOTES`, five names, was set to keep small Russian groups written family first from moving a family-first base to given-first (2026-11-10 THRESHOLDS); since 2026-11-15 #1356 a `FAMILY_FIRST` base keeps its order on such a group, and that entry measured what relaxing the count did then: no same-order cell moved, and groups written given-first moved a family-first base sooner; since 2026-11-19 #1447 two names written given first decide given-first by their position votes without the rule, so that measurement predates the vote and is not re-taken. The threshold is unchanged and has no issue. #1308, the tracking issue, is closed; its other open item, the given names the given-name table's family-share filter drops, was #1357, settled for `John`, `David` and `Robert` by 2026-11-15 #1357, which leaves `James`, `Paul`, `George`, `Charles`, `Thomas` and `Martin` out. #1364's ORCID surname table at a given-box share of 12%, which helps Portuguese and Brazilian lists written given first and costs those written family first at 10 and 20 names, and the census table for English it held, are open (2026-11-19 #1364, its Declined and Open bullets; 2026-11-15 #1357 holds what a gate measured for the census table); so is the cost that table's `pv-listed-given` shows, English given names ORCID's holders rarely type as one (`Cooper`, `Burke`). Not measured, and without an issue: the table's 20-use floor (`MIN_USES`), and a family share between 10% and 15%. +Open: the other four settings count their shares among the names with evidence on them, never the group, so a few stray names decide `patronymic_rules`, `initials_as_family`, `capitals_as_family` or `two_family_names` (whose share is of the names the switch would change) in a long silent list (2026-11-16 ORDER FLOOR, its bullet on the other settings; 2026-11-19 #1452); no measured population moves on any of them, and no issue is filed. Suggesting `two_family_names` for Portuguese and Brazilian lists (the switch reading Brazil's ORCID holders better and its PatentsView inventors worse), and for the countries #1452 left out (Croatia, Slovenia, Iran, DR Congo, Cameroon), whose ORCID holders' names the bare switch reads better and their PatentsView inventors' a little worse, is open (2026-11-19 #1452, its Open bullet). A group gate for the short capitals words, under which one votes where another name of the list writes a longer capitals word at the same end, measured and not taken for 3.1 (2026-11-14 #1355, its Declined bullet), to weigh beside #1402, which was decided 2026-11-19, left as it reads (decisions/O9). For a list mixing East Slavic and Turkic patronymics (uz_senate, kz_senate), suggesting both rules, and reading the Kazakh `-uly` and `-kyzy` endings as a Turkic signal, are not taken for 3.1 and not decided against (2026-11-15 #1356, its Not taken bullet). `_MIN_PATRONYMIC_VOTES`, five names, was set to keep small Russian groups written family first from moving a family-first base to given-first (2026-11-10 THRESHOLDS); since 2026-11-15 #1356 a `FAMILY_FIRST` base keeps its order on such a group, and that entry measured what relaxing the count did then: no same-order cell moved, and groups written given-first moved a family-first base sooner; since 2026-11-19 #1447 two names written given first decide given-first by their position votes without the rule, so that measurement predates the vote and is not re-taken. The threshold is unchanged and has no issue. #1308, the tracking issue, is closed; its other open item, the given names the given-name table's family-share filter drops, was #1357, settled for `John`, `David` and `Robert` by 2026-11-15 #1357, which leaves `James`, `Paul`, `George`, `Charles`, `Thomas` and `Martin` out. #1364's ORCID surname table at a given-box share of 12%, which helps Portuguese and Brazilian lists written given first and costs those written family first at 10 and 20 names, and which would also add Portuguese surnames to the `two_family_names` vote, and so could reach Lusophone lists the switch costs (Angola, Mozambique; 2026-11-19 #1452; not measured) as well as Brazil and Portugal, so it is measured on that setting's rows too, and the census table for English it held, are open (2026-11-19 #1364, its Declined and Open bullets; 2026-11-15 #1357 holds what a gate measured for the census table); so is the cost that table's `pv-listed-given` shows, English given names ORCID's holders rarely type as one (`Cooper`, `Burke`). Not measured, and without an issue: the table's 20-use floor (`MIN_USES`), and a family share between 10% and 15%. ## Log @@ -523,7 +526,7 @@ Open: the other three settings count their shares among the names with evidence - Declined: 12% for 3.2. It gives Portuguese and Brazilian lists written given first a large gain at two to five names and Indian lists a smaller one, but costs Brazilian and Portuguese lists written family first at 10 and 20 names, moving the size from which two populations are read right in 95% of groups (PatentsView's Brazilian 20 to 50, PSC's Portuguese 10 to 20); whether those rows are a real cost or only the boxes' writing is open. Removing a word in both tables from both: no word can be, the recipe refusing every word of the other two. A per-country ranking, as the given names have: a family word's country is not the holder's. - Open: the 12% share, above; and the cost `pv-listed-given` shows, a given name in English that ORCID's holders rarely type as one (`Cooper`, `Burke`), which only a given-name source cleared for use could take out of the table (PatentsView and PSC are the tool's populations and may not build it, as the issue's measurement rules). A typographic apostrophe (`O’Brien`) is counted and looked up under its own spelling, apart from `o'brien`, as in the given names; nothing votes wrong for it. - For #1452, which will read this table for `two_family_names` (a listed surname second-to-last, another name word after it): the table is `COMMON_SURNAMES`, apart from the romanized surnames in `SURNAMES`, whose second-to-last word in a Chinese name is a given-name syllable. It counts a family word anywhere in the box, so a second surname is in it (`lopez` beside `garcia`); it holds surnames of other languages too, so a listed word is no evidence of a Spanish list alone; and the boxes the tool's populations compose from hold the first surname in the given box in a share of PatentsView's and PSC's Spanish-language records (above), which a measurement of that vote needs to know. -- **2026-11-19 #1447 — WHERE AN EAST SLAVIC PATRONYMIC STANDS IS A VOTE ON THE ORDER, CAST BY A SIGNAL OF ITS OWN, `PATRONYMIC_POSITION`.** Decided in [#1447](https://github.com/derek73/python-nameparser/issues/1447) on 2026-11-19: a patronymic's position is an order vote under all three base orders, last for family-first and in the middle for given-first, read where rules/O1 reads it; under a `FAMILY_FIRST_GIVEN_LAST` base a list whose patronymics stand last is suggested `FAMILY_FIRST`; the `-ovich` surname among silent names is checked on real lists before it counts against the change. A list of Russian names written family first said how it is written in every name and cast no order vote: `Sidorov Ivan Petrovich` × 20 got the rule with a given-first order, which the rule reorders each three-word name under, and read `Sidorov Ivan`, a name of two words in the same list, given `Sidorov`. +- **2026-11-19 #1447 (its For #1452 bullet's branch at each site superseded by 2026-11-19 #1452, which reads one `Signal → setting` table at them) — WHERE AN EAST SLAVIC PATRONYMIC STANDS IS A VOTE ON THE ORDER, CAST BY A SIGNAL OF ITS OWN, `PATRONYMIC_POSITION`.** Decided in [#1447](https://github.com/derek73/python-nameparser/issues/1447) on 2026-11-19: a patronymic's position is an order vote under all three base orders, last for family-first and in the middle for given-first, read where rules/O1 reads it; under a `FAMILY_FIRST_GIVEN_LAST` base a list whose patronymics stand last is suggested `FAMILY_FIRST`; the `-ovich` surname among silent names is checked on real lists before it counts against the change. A list of Russian names written family first said how it is written in every name and cast no order vote: `Sidorov Ivan Petrovich` × 20 got the rule with a given-first order, which the rule reorders each three-word name under, and read `Sidorov Ivan`, a name of two words in the same list, given `Sidorov`. - The vote: `_read` casts `Signal.PATRONYMIC_POSITION` beside `Signal.PATRONYMIC` on every name `_patronymic` votes East Slavic for, `GIVEN_FIRST` where the middle word carries the ending (whatever the last word ends in, as rules/O1 reads it) and `FAMILY_FIRST` otherwise, the family-first shape the rule restores (`_patronymic_end`, the one predicate `_keeps_family_first` counts with too). It is an order signal like the others: a name whose other signals vote the other end is contested and casts no order vote (`David Michael Abramovich`, `Boris Zzyvan Petrovich`), and a name that disagrees on a decided order is listed as one. A Turkic patronymic casts none: the Turkic rule reads either written order and moves no name between them. - The signal (decided 2026-11-19, replacing the issue's "no new member if the code allows"): a new public `Signal` member, not a field on `NameEvidence` and not a vote counted in the tally alone. A field and a member each add to the public API, so avoiding an addition does not choose between them; the member fits the structure there is, one vote a signal, so a caller reading a name's votes sees it with no special field; a vote counted only in the tally hides a vote the name cast, and saying what it saw is what `suggest` is for; and #1452 meets the same need, its surname signal voting on the order and on two family names, so one member per kind of vote is the rule that carries (Standing). The member is `PATRONYMIC_POSITION` (`"patronymic-position"`), after `PATRONYMIC`, the order `SettingEvidence.by_signal` sorts in. - How it relates to 2026-11-19 #1364's rule, stated once (Standing): where a decided East Slavic rule meets a family-first order the names' votes decide, a `FAMILY_FIRST_GIVEN_LAST` base gets `FAMILY_FIRST`. #1364 made it reachable for lists whose surnames vote; this makes it reachable for every list whose patronymics stand last, so the issue's "a list whose patronymics stand last is suggested `FAMILY_FIRST`" needs no second rule. One gap it leaves, as master leaves it: two to four such names under that base vote family-first, which is the base's own end, and decide no rule (five names), so the base's order stays and reads each patronymic as the given name. @@ -538,3 +541,19 @@ Open: the other three settings count their shares among the names with evidence - Recorded, found by the reviews of the branch, the first three pinned by tests: a name ending in a patronymic and an initial (`Zzyvan Petrovich Q.`) is now contested, its position voting given-first against the trailing initial, so it no longer counts as a name ending in initials: six such names read right under every base (the rule, given-first, the initial the family) where master read the given name as the family, but three bylines beside three such names fall under the trailing-initial signal's 60% and decide nothing, where master decided family-first; a list of four East Slavic names and three Turkic ones decides no rule (4 of 7), and the East Slavic names' positions decide the order alone, family-first where they stand last (which reads both kinds) and given-first where they stand in the middle beside Turkic names written family first under a `FAMILY_FIRST` base, which then reads each Turkic marker as the family (`Mamedov Ali Huseyn oglu`, family `oglu`; the mixed list is the open question of 2026-11-15 #1356); and a `NameEvidence` or `Suggestion` holding the new member does not unpickle under 3.1, an enum value it does not know (measured by the review, held by no test here, the older release being outside the tree), for the release's pickle-break bullet; a test holds that one round-trips under this release. - Declined: a guard against the `-ovich` surname, since no real list measured has a same-order row under 95% for it (above). Keeping the given-first order with the rule for lists written family first under a given-first base, as #1356 did: it misreads every name of two words in such a list, and the parliament lists read better without it. - For #1452: by the rule above, the surname signal's vote on `two_family_names` (a listed surname second-to-last) is a `Signal` member of its own, not a second value of `SURNAME`; `_order_ends` and `_disagrees` take any signal other than `PATRONYMIC` for an order signal, so a member voting on another setting needs its own branch there and in `_setting_of`, as `PATRONYMIC` has. +- **2026-11-19 #1452 — A GROUP WRITTEN GIVEN FIRST WHOSE NAMES CARRY A COMMON SURNAME WHERE THE SWITCH WOULD TAKE A FIRST SURNAME GETS `TWO_FAMILY_NAMES`; ONE SIGNAL, `FIRST_SURNAME`.** Decided in [#1452](https://github.com/derek73/python-nameparser/issues/1452) on 2026-11-19: `suggest` decides `two_family_names`, with a high bar, since a wrong suggestion costs a list more than a missed one; one vote a name, each kind of evidence its own `Signal` member, and the two proposed kinds measured to see whether each is needed; a common given name where the switch would take a surname casts no vote; the bare switch, no pack and no veto inside `suggest`, the docs saying the pack reads a known Spanish or Portuguese list better; no new floor; and no mirror under a family-first order, the order being decided first and the switch weighed only where it comes out given-first. Left out of this version: Croatia, Slovenia, Iran, DR Congo and Cameroon, whose ORCID holders' names the bare switch reads better (below; their PatentsView inventors, where there are any, a little worse) but which nothing proposed here reaches; `middle_as_family` and `two_given_names` as suggested settings, each a later issue. + - The vote asks the parse itself, as the `capitals_as_family` vote does (2026-11-12 CAPITALS): the reader is the base with the settings already decided applied, parsed with the switch off and on. A name the switch changes is one whose parse without it has a middle name and whose family under it differs, a comma name and one written with an interpunct included, and every such name counts in the share; a name votes only where it has no comma and three words or more and its family under the switch ends in its family without it, by the last word the switch takes. A word `is_patronymic_marker` or `has_patronymic_ending` matches votes against the switch (`Signal.FIRST_SURNAME`, `False`; `Ivan Petrovich Sidorov`: it would read the father's name as a first surname), and the name disagrees with a decided switch; a word of `COMMON_GIVEN_NAMES` casts nothing (`Maria Anna Berg`); a word of `COMMON_SURNAMES` votes for it (`Signal.FIRST_SURNAME`, `True`). `COMMON_SURNAMES` alone, never `SURNAMES`, whose romanized surnames stand second-to-last in a Chinese name as a given-name syllable (2026-11-19 #1364, its For #1452 bullet). It is decided where the votes for it are at least `_MIN_TWO_FAMILY_VOTES` (3), more than `_MIN_TWO_FAMILY_SHARE` (0.3) of every name the switch would change, and more than the votes against: a list of three Spanish names and five Russian ones (3 for, 5 against) is not suggested it. Not weighed, with a note saying so, where the base has the switch on, where the East Slavic rule is decided or on the base (its fathers' names the switch would take), or where the order comes out family-first. `NameEvidence.votes` may now hold `True` or `False`, `Vote` widened to `tuple[Role, Role, Role] | PatronymicRule | bool`, and `_checked_vote` refuses any other value for a two-family signal; `name_votes`, which reads a name alone and outside the group, casts none. + - The signal table (decided by the issue, "build the table so the four sites read it", after 2026-11-19 #1447's For #1452 bullet): `_SETTING_OF`, every member to the setting it votes on, read by `_order_ends`, `_checked_vote` and `_setting_of`, and by `_disagrees` through `_order_ends`; a test holds that every member has a row. + - The shared-surname signal (the issue's (a): the second-to-last word ends at least two other names of the list) earns no member, measured before building it by a scratch simulation (the session's `pre52.py` and `sim52.py`, outside the tree): per country, up to 5,000 records of the `orcid-span-CC` pool below drawn with `random.Random(cc)`, each name parsed under `Parser()` with the switch off and on and kept as its moved flag, its taken word and the tables that word is in; then, per variant and size, groups drawn from those names (400 a size to 200 names, 40 above, each variant drawing its own), decided by at least three votes and more than 30% of the names moved, a name counted moved only where it has no comma and three words or more and the switch takes a word in front of its family, where the shipped rule counts every name the switch changes (the pools hold no comma, the difference left unmeasured), and without the shipped clause on the votes against, which no simulated name cast. With the shared signal beside the listed one it decides Vietnamese lists in 99% of groups of 200 names, Pakistani in 88% of 500 and Bangladeshi in 100% of 2,000, where the listed signal alone decides none at any size; what it adds for the lists the switch is for is Brazilian and Portuguese lists from 500 names (100% and 95%). Counting a shared word only where it ends more than twice as many names of the list as it opens still decides Pakistani lists of 1,000 names in 92% of groups and Bangladeshi lists of 2,000 in 95%. + - The thresholds, measured with the same simulation: at the share of the other settings, more than two thirds, the listed signal decides Spanish-language lists in at most 28% of groups at any size (Mexican, 5 names; Spanish 15%), falling to 2% or less from 100 names, since the switch changes nearly every name of three words while the table lists only some second surnames; at 0.3 with three votes it decides them from 10 to 20 names (the table below), and no must-not-move country at any size; a fourth vote kept out nothing more and cost the Spanish-language rows from 3 to 20 names (Spanish 41% → 17% and Mexican 79% → 56% at 10 names). + - Measured with `tools/differential/suggest_measure.py` at seed 20261110, 300 groups a size, one `--json` run per arm compared cell by cell: master as `--tree `, this branch as itself based on 667828ae with the review's fixes to the vote (first taken on 13cf07cd before them: every decision cell the same at both size sets; #1490 takes `ud` out of the credentials and #1487 adds an `en.toml` reading, which the vote's parses may meet; then rebased onto 34771e2d, whose #1464 joins a Latin bound given name past the first word and adds `locales.MS`, and the default sizes taken again there for both arms: against 34771e2d every cell, `east_slavic`, `letters` and `capitals` row, parliament and whole-name row of a country never decided reads as on master, and against this branch on 667828ae one decision moved, PE at 20 names 87.0% → 86.7% written given first under either base (one group in 300), and whole names by at most 0.23 points (PE at 20 names 86.6% → 86.4%); the figures below are those on 667828ae, and the long sizes were not taken again), at the default sizes with `--wrong-words 12` and at `--sizes 2,3,4,5,10,20,50,100,200,500,1000,2000` (2026-11-19). The tool gained `orcid-span-CC` (`SPAN_COUNTRIES`): ORCID holders of each country with both boxes filled and no comma in either, the name composed given box then family box, so the boxes say which words are the family (ES 19,515, MX 19,520, CO 19,356, PE 19,470, AR 19,373, BR 19,000, PT 19,462, BD 16,222, GH 19,230, KE 18,433, PK 16,706, VN 18,896, AO 5,036, MZ 4,943, TR 19,122, HR 15,549, SI 7,815, IR 19,684, CD 3,854, CM 6,666, US 18,755 records), the groups deciding `two_family_names` per row (`two_family`), and for those populations whole names read right (given and middle against the given box, family against the family box, case folded) under the suggestion and under the base, written given first under a given-first base to 200 names (`whole`), and under the bare switch off and on over a sample of 3,000 (`switch`); and the parliament suggestions record a decided `two_family_names`. + - Groups suggested the switch (the long-size run; the default-size run reads the same within a point at the sizes both take, save PatentsView's Spanish inventors at 200 names, 85% against 87%, and `pv-listed-given`, below), written given first under a given-first base, at 2 / 3 / 4 / 5 / 10 / 20 / 50 / 100 / 200 / 500 / 1,000 / 2,000 names: ES 0 / 1 / 3 / 8 / 45 / 75 / 90 / 99 / 99 / 100 / 100 / 100%; MX 0 / 3 / 15 / 25 / 77 / 98 / 100% from 50; CO 0 / 7 / 19 / 33 / 84 / 96 / 99 / 100% from 100; PE 0 / 6 / 14 / 31 / 76 / 87 / 98 / 99 / 100% from 200; AR at most 7% (20 names), 0.3% at 100 and 0% from 200; BR and every must-not-move country (BD, GH, KE, PK, VN, AO, MZ, TR) 0% at every size; PT and IR at most 0.3% (one group in 300, at 10 to 50 names); US at most 3% (100 names); written given first under a family-first base the same within a point; written family first, under either base, at most 0.3% (one group in 300; the order comes out family-first). Among the other populations, PSC's Spanish filers reach 94.7% at 2,000 names and never 95%, and PatentsView's Spanish inventors reach 95% at 500, their boxes holding the first surname in the given box in a share of records (2026-11-19 #1364); `pv-listed-given`, written family first, gets the switch under either base, its order coming out given-first, the standing exception's wrong way round: under a given-first base in 36% of groups of 5 names and 88% of 10, under a family-first one in 10% of 5 and 63% of 10, all from 200 (the default-size run reads 37%, 90%, 9% and 69% there, its 607 names drawn apart); PatentsView's Colombian and Mexican inventors 62% and 66% at 10 names, 86% and 90% at 20, 100% from 100; PSC's Croatian filers 0.7% at 100 names and 2.3% at 200 (seven groups in 300; 3.0% in the default-size run), growing with the size; and in one group in 300 or two, the rest of the populations that ever get it: PSC's Brazilian filers 0.7% at 10 and its Portuguese 0.3% at 20, PatentsView's Argentine and Brazilian inventors 0.3% at 10 and 20, its German 0.3% at 100 and its French 0.3% at 200. + - Whole names: on ORCID, the bare switch (`config_diff.py score default --switches two_family_names --group CC --cap 20000`, taken on 13cf07cd; the tool's `switch` field, a sample of 3,000 scored by its own comparison, differs from it by up to 6 points, in Pakistan and Bangladesh) moves ES 49.6 → 94.8%, MX 33.6 → 95.8%, CO 24.9 → 95.4%, PE 14.7 → 97.3%, BR 49.6 → 74.5%, PT 71.8 → 83.4%, HR 88.4 → 98.5%, SI 90.4 → 97.6%, IR 84.2 → 91.7%, CD 56.6 → 84.0%, CM 56.8 → 70.7%, and AR 83.5 → 62.1%, BD 92.3 → 48.8%, GH 89.8 → 67.2%, KE 93.7 → 69.9%, PK 93.6 → 75.2%, VN 68.5 → 52.5%, AO 76.2 → 57.6%, MZ 85.4 → 50.4%, TR 91.8 → 79.7%, US 95.8 → 93.1%. On PatentsView's inventors, whose boxes a filer split, it helps ES 45.9 → 80.3%, CO 53.4 → 80.4%, MX 60.2 → 73.7%, PT 57.6 → 62.9% and PE 90.7 → 91.2%, and costs every other country measured: VN 90.3 → 37.5%, BD 98.4 → 53.9% (191 names), AR 93.8 → 56.4%, PK 99.1 → 66.1%, KE 99.5 → 68.2%, BR 75.7 → 51.2%, TR 96.0 → 77.7%, US 99.1 → 82.4%, GH 98.5 → 90.4% (135 names), IR 89.1 → 87.4%, SI 88.2 → 87.4%, HR 92.0 → 91.6% and CM 99.95 → 99.45% (no AO, MZ or CD rows). Under the suggestion, written given first under a given-first base, at 2 / 5 / 10 / 20 / 200 names, suggestion against base: ES 49 / 54 / 71 / 85 / 94% against 49 / 48 / 46 / 50 / 49%; MX 31 / 54 / 85 / 95 / 96% against 31 / 35 / 34 / 33 / 33%; CO 26 / 52 / 85 / 92 / 95% against 26 / 26 / 25 / 24 / 25%; PE 16 / 42 / 78 / 87 / 97% against 16 / 15 / 15 / 15 / 14%; every other country within a point of its base at every size and within half a point of master, the order suggestion apart, the switch never decided there and each as on master: CD and CM read up to 4 points better under the suggestion at 2 to 5 names, and VN, BD, AO and MZ up to 2 points worse (BD 85.8% against 87.4% at 10 names, AO 74.3% against 75.9% and MZ 84.6% against 85.9% at 4). + - Argentina belongs with the countries kept out, not with those the switch is for: its names carry one family name, often behind two given names (decisions/O6, its Standing: the convention is not Argentina's), the switch costs them 21 points on ORCID and 37 on PatentsView, and the listed signal decides at most 7% of their groups. Brazil and Portugal, which the switch reads better on ORCID, though not Brazil's inventors on PatentsView, are not reached (at most two groups in 300 of any of their populations, above): the table holds few Portuguese surnames (2026-11-19 #1364, its 12% bullet), and the only evidence that reached them, the shared signal, brought Pakistan and Bangladesh with it. + - Same-order rows, the anti-goal, and every row written against its base: identical to master in every cell at both size sets, the standing exceptions (`orcid-byline-joined`, `orcid-givcaps`, `pv-listed-given`) included; no `east_slavic`, `letters`, `capitals` or TURKIC row moves. + - Parliaments: no list decides `two_family_names` under any of the three bases (28 lists × 3 bases, the tool's `two_family` field), and no other field of a list's suggestion moves. + - The harness proof (`--set _MIN_VOTES=1000000 --set _MIN_PATRONYMIC_VOTES=1000000 --set _MIN_RUN_NAMES=1000000 --set _MIN_TWO_FAMILY_VOTES=1000000`, at the default sizes): each of the 138 rows written against its base reads 0% and each of the 138 written in it 100%, over 69 populations; no group of any population and no parliament list decides `two_family_names`. + - The sweep, base order × each switch on the base (a scratch script: nine made-up lists, Spanish names written given first, written family first, with the family in capitals or its last word in capitals, beside three runs of letters, beside five East Slavic patronymics, with a particle, with two given names, of two words; under the three bases with none, `two_family_names`, `capitals_as_family`, `initials_as_family` or the East Slavic rule on the base; master against the branch): 36 of 135 cases move, each a list written given first with Spanish surnames getting the switch under a base with none, `capitals_as_family` or `initials_as_family` on, beside `name_order=GIVEN_FIRST` under a family-first base. The pairs: with `capitals_as_family` and with `initials_as_family` the switch is suggested together and each reads its own names (`Hari K C` keeps family `K C`); a list writing its family names in capitals casts no vote, `capitals_as_family` already reading both words; with the East Slavic rule the switch excludes, whether the rule is decided or on the base; under a family-first order it is not weighed; a base with the switch on is suggested nothing, and a group never turns it off, as for the other switches. + - Recorded: the vote parses each name of three words or more twice more where it is weighed, and each name twice more to see whether the switch changes it at all, so `suggest` over 2,000 given-first names of three words takes about 0.65 s, and over 2,000 of two words, which cast nothing, 0.21 s, where master takes 0.04 s for either (best of five, py3.11, on a machine loaded by a measurement, 2026-11-19); a few hundred names, what the docs advise, take a tenth of that or less. A `NameEvidence` or `Suggestion` holding `FIRST_SURNAME` does not unpickle under 3.1 (an enum value it does not know), for the release's pickle-break bullet; a test holds that one round-trips under this release. + - Declined: the shared-surname signal (above); a share above 0.3 (above); a veto inside `suggest` on a list a pack would read better, the issue deciding the bare switch. + - Open: Portuguese and Brazilian lists, which the switch reads better on ORCID (Brazilian inventors on PatentsView worse) and nothing proposed here reaches without bringing Pakistani and Bangladeshi lists with it; the countries left out, whose ORCID holders' names the switch reads better too and their PatentsView inventors' a little worse (HR, SI, IR, CD, CM above); `middle_as_family` and `two_given_names` as suggested settings, each a later issue. diff --git a/docs/getting-started.rst b/docs/getting-started.rst index de3f1b01b..b536c6db3 100644 --- a/docs/getting-started.rst +++ b/docs/getting-started.rst @@ -119,6 +119,8 @@ it, and ``suggestion.base`` is the parser you started from: patronymic_rules unchanged (none) no evidence initials_as_family unchanged (False) no evidence capitals_as_family unchanged (False) 5 for, 0 against, 0 no evidence + two_family_names unchanged (False) no evidence + not read: the order is family-first, and two family names are weighed under a given-first order alone Each setting counts its names for and against the value the suggested parser has: all five names are in mixed case with no word in capitals, @@ -147,7 +149,7 @@ surname (``Mary``, not ``James``), at one end; a family name written in capitals; a lowercase particle; initials after the name, as a bibliography writes them (:ref:`suggest-evidence`). -``suggest`` decides four settings from it, each only where enough of +``suggest`` decides five settings from it, each only where enough of the list's names carry its evidence, and leaves every other one as the parser you called it on has it: @@ -163,6 +165,10 @@ parser you called it on has it: - **Family names in capitals** (:ref:`capitals-as-family`): for a list that writes the family name in capitals of four letters or more (``Mary SMITH``) (:ref:`suggest-capitals`). +- **Two family names** (:ref:`two-family-names`): for a list written + given name first whose names carry a common surname where a second + given name would stand (``Gabriel García Márquez``) + (:ref:`suggest-two-family`). Choose the language first ~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/policy.rst b/docs/policy.rst index 258994f4e..0fbe83c27 100644 --- a/docs/policy.rst +++ b/docs/policy.rst @@ -537,7 +537,11 @@ under a family-first order), and only then: :ref:`What it costs ` shows what it does to other names. ``locales.ES``, ``locales.ES_AR``, ``locales.PT_BR`` and ``locales.PT_PT`` turn it on together with a list of given names that it holds back (see -`Keeping a given name out of the family`_). +`Keeping a given name out of the family`_). For a list of names, +``Parser.suggest()`` turns the bare switch on where enough of the names +write a common surname where the switch would take a word into the +family (:ref:`suggest-two-family`); where you know the list is Spanish +or Portuguese, the pack reads it better. In Spain and most of Latin America a person carries two family names, the father's first and then the mother's, and writes both after the diff --git a/docs/release_log.rst b/docs/release_log.rst index 399fa6b15..a18e5bbe7 100644 --- a/docs/release_log.rst +++ b/docs/release_log.rst @@ -6,6 +6,7 @@ Release Log - **Fix Abdel, Abd and Abou past the first word of a name, which read as a middle name of their own.** ``parse("Tariq Abdel Aziz")`` gives family ``Abdel Aziz``, where 1.4.0 through 3.1.0 gave middle ``Abdel``, family ``Aziz``. ``Abdul`` joins only in a name of four words or more, titles and suffixes not counted, so ``Tariq Abdul Aziz`` keeps middle ``Abdul``; and after a family comma ``Abd`` before a name word is no longer the credential ABD. :issue:`1464` - **Add locales.MS, a Malay pack, which reads Malaysian titles written before a name: Puan, Cik, Ustaz, Ustazah and Cikgu.** ``parser_for(locales.MS).parse("Puan Siti binti Ahmad")`` gives title ``Puan``, given ``Siti``, family ``binti Ahmad``, where the default, as 1.4.0 through 3.1.0, gives given ``Puan``; ``Tuan`` stays a name word, being a hereditary prefix and a Vietnamese given name, and the pack reads the Indonesian given name ``Puan`` as the title too (``Puan Maharani``): keep it to Malaysian names. See :ref:`malay-names`. :issue:`1179` + - **Change Parser.suggest() to suggest two_family_names for a list whose names end in two family names, and add Signal.FIRST_SURNAME, the signal that votes for it.** ``Parser().suggest(["María García López", "Juan Pérez Ruiz", "Ana Martínez Soto"]).patch`` gives ``PolicyPatch(two_family_names=True)``, where 3.1.0 suggested nothing; it is weighed only where the list's order is given-first, and lists measured from Argentina, Brazil and Portugal are rarely or never suggested it. ``NameEvidence.votes`` may now hold ``True`` or ``False``, the switch's value a name votes for. :issue:`1452` - **Change Parser.suggest() to read where a Russian-style patronymic stands as a vote on the order, and add Signal.PATRONYMIC_POSITION, the signal that casts it.** ``Parser().suggest(["Sidorov Ivan Petrovich", "Volkov Pavel Sergeevich", "Orlova Anna Ivanovna", "Zaitsev Oleg Nikolaevich", "Belova Vera Andreevna"]).patch`` gives ``PolicyPatch(name_order=FAMILY_FIRST, patronymic_rules=...)``, where 3.1.0 gave the rule with the given-first order, which misread any name of two words in such a list (``Sidorov Ivan`` gave family ``Ivan``); a patronymic in the middle votes given-first. :issue:`1447` - **Fix ud inside a South Asian compound name, which read as a credential and took the rest of the name.** ``parse("NADIR ZIA UD DIN")`` gives middle ``ZIA UD``, family ``DIN``, as 1.4.0 through 2.3.0 did, where 2.4.0 through 3.1.0 gave family ``ZIA``, suffix ``UD DIN``; ``UD`` alone after a name and a comma now reads as initials (``Anke Vissering, UD`` gives given ``UD``, family ``Anke Vissering``, where 1.4.0 through 3.1.0 gave suffix ``UD``). ``bt`` stays a credential: for Malay names remove it, as :doc:`customize` shows. :issue:`1467` - **Fix the surname1 and surname2 views, which left a family of two surnames whole before a family comma, opening with a particle, or behind a given name a particle completes.** Under ``two_family_names``, as ``locales.ES``, ``ES_AR``, ``CS``, ``SK``, ``PT_BR`` and ``PT_PT`` turn it on, ``parser_for(locales.ES).parse("García Márquez, Gabriel")`` gives surname1 ``García``, surname2 ``Márquez``, as ``Gabriel García Márquez`` does, where 3.0.0 through 3.1.0 gave surname1 ``García Márquez``, surname2 ``''``. No field moves; a family joined by ``y`` or written as one hyphenated word stays whole, and so, where 3.0.0 through 3.1.0 divided them, do a lone particle and the word after it under a family-first order (``Van Gogh``) and a Turkic father's name with its marker; with ``capitals_as_family`` on too, the family the capitals name is divided. :issue:`1456`, :issue:`1479` diff --git a/docs/suggest.rst b/docs/suggest.rst index 64210f80e..5058fc440 100644 --- a/docs/suggest.rst +++ b/docs/suggest.rst @@ -35,11 +35,12 @@ first because the list is, and nothing in the name can confirm that. Each name votes on its order from the evidence it carries (:ref:`suggest-evidence`), and the group decides the order where enough -of its names agree (:ref:`suggest-deciding`). Three more settings are +of its names agree (:ref:`suggest-deciding`). Four more settings are decided the same way, each by its own evidence: a patronymic rule (:ref:`suggest-patronymics`), ``initials_as_family`` -(:ref:`suggest-initials`) and ``capitals_as_family`` -(:ref:`suggest-capitals`). Every setting the votes do not decide keeps +(:ref:`suggest-initials`), ``capitals_as_family`` +(:ref:`suggest-capitals`) and ``two_family_names`` +(:ref:`suggest-two-family`). Every setting the votes do not decide keeps the base parser's value. .. _suggest-how-many: @@ -118,6 +119,8 @@ the names that disagree with it: patronymic_rules unchanged (none) no evidence initials_as_family unchanged (False) no evidence capitals_as_family unchanged (False) 5 for, 0 against, 0 no evidence + two_family_names unchanged (False) no evidence + not read: the order is family-first, and two family names are weighed under a given-first order alone The report reads as follows: @@ -139,8 +142,8 @@ The report reads as follows: SMITH`` the surname in front says family first and the capitals at the end say family last). A contested name casts no order vote and never disagrees on the order. -- **The indented rows** under ``name_order`` and ``patronymic_rules`` - count the names by kind of evidence and the value it votes for. A +- **The indented rows** under ``name_order``, ``patronymic_rules`` + and ``two_family_names`` count the names by kind of evidence and the value it votes for. A name carrying two kinds is in two rows (``Wang Xiaoming`` above), so the rows can add up to more than the names for. - **An indented sentence**, where one follows, is a note saying why @@ -185,6 +188,8 @@ The report counts it as ``against`` and names it on its last line: patronymic_rules unchanged (none) no evidence initials_as_family unchanged (False) no evidence capitals_as_family unchanged (False) 6 for, 0 against, 0 no evidence + two_family_names unchanged (False) no evidence + not read: the order is family-first, and two family names are weighed under a given-first order alone disagreeing (1): Emily Clark .. _suggest-deciding: @@ -220,6 +225,12 @@ and enough of them agree: - 2 writing the family name in capitals of four letters or more - more than two thirds of the names with evidence either way - :ref:`suggest-capitals` + * - ``two_family_names`` + - 3 with a common surname where the switch would take a first + surname + - more than three in ten of the names the switch would change, + and more than the names voting against it + - :ref:`suggest-two-family` The group decides ``name_order`` when at least two names vote for one end and they are more than two thirds of the names that cast an order @@ -274,6 +285,7 @@ mixed case as ``for`` the switch staying off, :ref:`suggest-report`.) patronymic_rules unchanged (none) no evidence initials_as_family unchanged (False) no evidence capitals_as_family unchanged (False) 3 for, 0 against, 0 no evidence + two_family_names unchanged (False) no evidence Then, where you know how the list is written, set the order yourself (:ref:`name-order`): @@ -581,18 +593,99 @@ A list left with the switch off shows no note unless a name writes its family in capitals, and counts its names in mixed case as ``for`` (:ref:`suggest-report`). +.. _suggest-two-family: + +Lists that give two family names +-------------------------------- + +``suggest()`` turns ``two_family_names`` on (see +:ref:`two-family-names`) for a list written given name first whose +names end in two family names, as Spanish-speaking lists do, so that +the word before the family name joins it: + +.. doctest:: + + >>> hispanic = Parser().suggest(["María García López", "Juan Pérez Ruiz", + ... "Ana Martínez Soto"]) + >>> hispanic.patch + PolicyPatch(two_family_names=True) + >>> Parser().parse("Gabriel García Márquez").family + 'Márquez' + >>> hispanic.parser.parse("Gabriel García Márquez").family + 'García Márquez' + +A wrong suggestion here costs more than a missed one: the switch reads +a middle name as a first surname, and in lists from countries where +two family names are rare it cost up to 53 points of whole names read +right (:issue:`1452`). So the switch is decided only where at least +three names, more than three in ten of the names it would change, carry +a common surname where it would take a first surname. + +What counts for and against +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Every name the switch would change counts in that share. One of three +words or more with no comma also votes for it, against it, or not at +all, by the word the switch would take into the family: + +- **For**: a common surname (``García`` in ``Gabriel García + Márquez``), from the table of words ORCID's holders type as a family + name and rarely as a given name (:ref:`suggest-evidence`). +- **Against**: a father's name (``Ivan Petrovich Sidorov``), which the + switch would read as a first surname. The names voting for it must + outnumber these, and such a name disagrees with a decided switch. +- **No evidence**: every other name, a common given name there + included (``Maria Anna Berg``), which the switch would read as a + surname. A common given name casts no vote but still counts in the + share, among the names the switch would change. + +The switch is weighed only once the order is settled given name first, +by the base or by the list: a list written family first is not +suggested the switch, and neither is a list for which an East Slavic +patronymic rule is on, whose fathers' names the switch would read as +surnames. A group never turns the switch off, and a base with it on is +suggested no change to it. + +What the report shows +~~~~~~~~~~~~~~~~~~~~~ + +The note under ``two_family_names`` counts the names voting for it +among those it would change: + +.. doctest:: + + >>> [e.note for e in hispanic.evidence if e.setting == "two_family_names"] + ['3 of the 3 names two_family_names would change carry a common surname where it would take a first surname'] + +Where you know the list +~~~~~~~~~~~~~~~~~~~~~~~ + +The suggestion is the bare switch. Where you know a list is Spanish or +Portuguese, choose the language pack instead (:ref:`suggest-packs`): +it turns the switch on too, and its given names keep a compound given +name whole, which the bare switch reads as a first surname: + +.. doctest:: + + >>> from nameparser import locales, parser_for + >>> hispanic.parser.parse("Juan Pablo Montoya").family + 'Pablo Montoya' + >>> parser_for(locales.ES).parse("Juan Pablo Montoya").family + 'Montoya' + .. _suggest-packs: Choosing a language pack ------------------------ -A suggestion never chooses a language pack. It proposes the four +A suggestion never chooses a language pack. It proposes the five ``Policy`` settings above (``name_order``, ``patronymic_rules``, -``initials_as_family`` and ``capitals_as_family``) and leaves the -vocabulary as the base parser has it. The words a pack turns on, and -its other rules (two family names for Spanish, dividing a Chinese -surname from the given name), come only from choosing the pack -yourself: see :ref:`shipped-packs`. +``initials_as_family``, ``capitals_as_family`` and +``two_family_names``) and leaves the vocabulary as the base parser has +it. The words a pack turns on, and its other rules (dividing a Chinese +surname from the given name, the pack's own reading of two family +names), come only from choosing the pack yourself: see +:ref:`shipped-packs`. Where you know a list's language, build the base with ``parser_for`` and call ``suggest()`` on that; the suggested parser keeps the pack. diff --git a/nameparser/_parser.py b/nameparser/_parser.py index 4234f56ec..c395c0743 100644 --- a/nameparser/_parser.py +++ b/nameparser/_parser.py @@ -390,7 +390,22 @@ def suggest(self, names: Iterable[str]) -> Suggestion: never turns it off, nor turns it on under a base with ``unlisted_caps_suffixes=CapsSuffixes.EVERYWHERE``, beside which it cannot be set; it is decided apart from the order, which the - capitals in a name vote on as before. A setting the votes do not decide keeps this parser's value, so + capitals in a name vote on as before. ``two_family_names`` + (rules/O6) is weighed last, and only where the rest of the + suggestion reads given-first with the East Slavic rule off: each + name is parsed with the switch off and on, and where the switch + takes a word into the family, a common surname there votes for + it (``García`` in ``Gabriel García Márquez``), a common given + name casts no vote (``María`` in ``Ana María López``), and a + father's name votes against it. It is turned on where at least + three names vote for it, more than 30% of every name the switch + would change and more than those against; a group never turns + it off; a father's name the switch would take disagrees with it. + A caller who knows a list is Spanish or Portuguese does better + with the language's pack (``locales.ES``, ``locales.PT_BR``, + ``locales.PT_PT``), whose given names the switch leaves out of + the family. A setting the votes do not + decide keeps this parser's value, so an empty group, or one with no votes, suggests no change. A bare str, bytes, a mapping or a non-str item raises TypeError. diff --git a/nameparser/_suggest.py b/nameparser/_suggest.py index abbf0f193..c93ba2222 100644 --- a/nameparser/_suggest.py +++ b/nameparser/_suggest.py @@ -51,7 +51,14 @@ credential or numeral and the base reads as no title, against the names the switch would give a family the base reads as a title and the names in mixed case with no word in capitals; it is no vote on the order, -which the capitals signal casts as before. A setting is +which the capitals signal casts as before. Last it weighs +``two_family_names`` (rules/O6), where the rest reads given-first with +the East Slavic rule off, asking the parse itself under that parser +with the switch off and on: a name the switch would change votes for it +where the word it would take into the family is a common surname of +the ORCID table (`Signal.FIRST_SURNAME`), casts no vote where that word +is a common given name, and votes against it where it is a father's +name. A setting is decided only on the evidence the thresholds below admit; any other setting keeps the base's value, so an empty group, or one with no votes, gives back a parser that reads exactly as the base does. The @@ -90,7 +97,7 @@ ReadingSource, Role, _guarded_getstate, _guarded_setstate, ) -from .config._order_names import COMMON_GIVEN_NAMES, SURNAMES +from .config._order_names import COMMON_GIVEN_NAMES, COMMON_SURNAMES, SURNAMES if TYPE_CHECKING: from ._parser import Parser @@ -124,7 +131,9 @@ def fold(word: str) -> str: class Signal(StrEnum): - """The evidence a single name offers about its writer's name order.""" + """The evidence a single name offers about how its writer writes + names; each signal votes on one ``Policy`` setting: the order, the + patronymic rule or ``two_family_names``.""" #: A family name written in capitals at one end of a name in mixed #: case (``Mary SMITH``). @@ -151,6 +160,14 @@ class Signal(StrEnum): #: last (``Sidorov Ivan Petrovich``) it is written first. Cast only #: beside an East Slavic ``PATRONYMIC`` vote. PATRONYMIC_POSITION = "patronymic-position" + #: The word ``two_family_names`` would take into a name's family + #: (rules/O6), voting the switch's value: True where it is a common + #: surname of the ORCID table (``COMMON_SURNAMES``, #1364), ``García`` + #: in ``Gabriel García Márquez``, a first surname standing where a + #: second given name would; False where it is a father's name the + #: switch would read as a first surname (``Ivan Petrovich + #: Sidorov``). A listed given name there casts no vote. + FIRST_SURNAME = "first-surname" _INITIAL_JOINS = re.compile(r"[.-]+") @@ -425,14 +442,13 @@ def _letter_run(text: str, readers: tuple[Parser, Parser]) -> str | None: def _read(text: str, lexicon: Lexicon - ) -> tuple[dict[Signal, tuple[Role, Role, Role] | PatronymicRule], - bool, list[str]]: + ) -> tuple[dict[Signal, Vote], bool, list[str]]: """The votes one name casts, whether a comma left it out, and the words the signals read.""" words, comma = _name_words(text, lexicon) if len(words) < 2: return {}, comma, words - votes: dict[Signal, tuple[Role, Role, Role] | PatronymicRule] = {} + votes: dict[Signal, Vote] = {} capitals = _capitals(words) if capitals is not None: @@ -476,17 +492,22 @@ def name_votes(text: str, lexicon: Lexicon """The votes one name casts; empty for a name of fewer than two words once its titles and post-nominals are read past, and for a comma name, save one whose comma is followed by post-nominals - alone.""" - return _read(text, lexicon)[0] + alone. It holds no ``two_family_names`` vote, which reads the parse + the rest of a suggestion gives.""" + # one name read alone casts only orders and rules: the switch's + # votes are cast in suggest + return {signal: vote for signal, vote in _read(text, lexicon)[0].items() + if not isinstance(vote, bool)} # -- the group ---------------------------------------------------------- -#: A vote one signal casts: an order, or the patronymic rule a shape -#: matches. -Vote = tuple[Role, Role, Role] | PatronymicRule +#: A vote one signal casts: an order, the patronymic rule a shape +#: matches, or a switch's value (``two_family_names``). +Vote = tuple[Role, Role, Role] | PatronymicRule | bool #: A setting's value as SettingEvidence holds it: an order, a set of -#: patronymic rules, or a switch (initials_as_family, capitals_as_family). +#: patronymic rules, or a switch (initials_as_family, capitals_as_family, +#: two_family_names). SettingValue = tuple[Role, Role, Role] | frozenset[PatronymicRule] | bool # The thresholds, chosen with tools/differential/suggest_measure.py @@ -545,12 +566,32 @@ def name_votes(text: str, lexicon: Lexicon #: (decisions/group-suggestion, 2026-11-11 TRAILING INITIAL, #1254). _MIN_TRAILING_NAMES = 3 _MIN_TRAILING_SHARE = 0.6 +#: two_family_names is decided where at least this many names vote for +#: it, they are more than _MIN_TWO_FAMILY_SHARE of the names the switch +#: would change, and more than the names voting against it: a list of +#: two family names writes many first surnames the table does not hold, +#: so the share is lower than an order's, and at more than three in ten +#: no list from a country the switch costs is decided at any size +#: measured (decisions/group-suggestion, 2026-11-19 #1452). +_MIN_TWO_FAMILY_VOTES = 3 +_MIN_TWO_FAMILY_SHARE = 0.3 _NAME_ORDER = "name_order" _PATRONYMIC_RULES = "patronymic_rules" _INITIALS_AS_FAMILY = "initials_as_family" _CAPITALS_AS_FAMILY = "capitals_as_family" +_TWO_FAMILY_NAMES = "two_family_names" _SIGNAL_RANK = {signal: rank for rank, signal in enumerate(Signal)} +#: The setting each signal votes on: one setting a signal, one signal a +#: kind of vote (decisions/group-suggestion, 2026-11-19 #1447), read by +#: every site that tells the kinds apart (2026-11-19 #1452). +_SETTING_OF: Mapping[Signal, str] = MappingProxyType({ + Signal.CAPITALS: _NAME_ORDER, Signal.TRAILING_INITIAL: _NAME_ORDER, + Signal.PARTICLE: _NAME_ORDER, Signal.SURNAME: _NAME_ORDER, + Signal.GIVEN_NAME: _NAME_ORDER, Signal.PATRONYMIC: _PATRONYMIC_RULES, + Signal.PATRONYMIC_POSITION: _NAME_ORDER, + Signal.FIRST_SURNAME: _TWO_FAMILY_NAMES, +}) def _end(order: tuple[Role, ...]) -> tuple[Role, Role, Role]: @@ -565,16 +606,23 @@ def _order_ends(pairs: Iterable[tuple[Signal, Vote]] order vote) or both (the name is contested and casts no order vote).""" return frozenset(vote for signal, vote in pairs # type: ignore[misc] - if signal is not Signal.PATRONYMIC) + if _SETTING_OF[signal] == _NAME_ORDER) def _checked_vote(signal: object, vote: object, owner: str = "NameEvidence") -> tuple[Signal, Vote]: """One (signal, vote) pair, validated: an order signal votes ``GIVEN_FIRST`` or ``FAMILY_FIRST``, the patronymic signal a - ``PatronymicRule``. ``owner`` names the type in the message.""" + ``PatronymicRule``, a ``two_family_names`` signal the switch's + value, True or False. ``owner`` names the type in the message.""" signal = Signal(signal) # type: ignore[arg-type] # ValueError names it - if signal is Signal.PATRONYMIC: + if _SETTING_OF[signal] == _TWO_FAMILY_NAMES: + if not isinstance(vote, bool): + raise TypeError( + f"{owner} vote for {signal.value!r} must be True or False, " + f"got {vote!r}; pass e.g. {{Signal.{signal.name}: True}}") + return signal, vote + if _SETTING_OF[signal] == _PATRONYMIC_RULES: if not isinstance(vote, PatronymicRule): raise TypeError( f"{owner} vote for {signal.value!r} must be a " @@ -946,7 +994,9 @@ def disagreeing(self) -> tuple[NameEvidence, ...]: disagree with; a name that cast no vote, or whose order signals are contested, never disagrees on order; a name in mixed case with no word in capitals disagrees with a decided - ``capitals_as_family``; and a name carrying an + ``capitals_as_family``; a name whose father's name the switch + would take disagrees with a decided ``two_family_names``; and a + name carrying an East Slavic patronymic never disagrees on order where the East Slavic rule is decided with a given-first order, since the rule reorders it there.""" @@ -1011,7 +1061,7 @@ def _check_against_the_patch(self) -> None: def _setting_of(signal: Signal) -> str: - return _PATRONYMIC_RULES if signal is Signal.PATRONYMIC else _NAME_ORDER + return _SETTING_OF[signal] def _disagrees(name: NameEvidence, decided: Mapping[str, object]) -> bool: @@ -1019,6 +1069,9 @@ def _disagrees(name: NameEvidence, decided: Mapping[str, object]) -> bool: if (decided.get(_CAPITALS_AS_FAMILY) is True and name.family_in_capitals is False): return True + if (decided.get(_TWO_FAMILY_NAMES) is True + and dict(name._votes).get(Signal.FIRST_SURNAME) is False): + return True patronymic = dict(name._votes).get(Signal.PATRONYMIC) rules = decided.get(_PATRONYMIC_RULES) if (rules is not None and patronymic is not None @@ -1568,11 +1621,107 @@ def _trailing_initials_vote( f"names and {_MIN_TRAILING_SHARE:.0%} of the group do") +def _two_family_votes( + with_words: list[tuple[str, dict[Signal, Vote], bool, list[str]]], + reader: Parser) -> tuple[list[dict[Signal, Vote]], int, int]: + """Each name's votes on ``two_family_names``, read where rules/O6 + reads it: the parse itself is asked, under ``reader`` (the parser the + rest of the suggestion gives) with the switch off and on, and a name + the switch moves is one whose family it changes, every name of the + group with a middle name asked. Where such a name has no comma and three name words or + more, the last word the switch takes into its family votes + (`Signal.FIRST_SURNAME`): for the switch where it is a common + surname of the ORCID table, against it where it is a patronymic or + its marker, a father's name the switch would read as a first + surname, and not at all where it is a common given name, the second + given name the switch would take (`COMMON_GIVEN_NAMES`). Returns the + votes, the names the switch moves and the names whose taken word is + a listed given name.""" + with warnings.catch_warnings(): + # the base gave its construction warnings when it was built + warnings.simplefilter("ignore") + on = dataclasses.replace(reader, policy=dataclasses.replace( + reader.policy, two_family_names=True)) + out: list[dict[Signal, Vote]] = [] + moved = vetoed = 0 + for text, _, comma, words in with_words: + votes: dict[Signal, Vote] = {} + out.append(votes) + # every name the switch changes counts in the share, a comma name + # and one whose words the signals do not split included; only a + # name they read casts a vote + off = reader.parse(text) + if not off.middle: + # the switch takes the word before the family from the + # middle, so a name with none is one it leaves as it is + continue + off_family, on_family = off.family, on.parse(text).family + if on_family == off_family: + continue + moved += 1 + if (comma or len(words) < 3 + or not on_family.endswith(" " + off_family)): + continue + word = on_family[:len(on_family) - len(off_family)].split()[-1] + bare = word.rstrip(".") or word + if is_patronymic_marker(bare) or has_patronymic_ending(bare): + # a father's name or its marker, never a first surname + votes[Signal.FIRST_SURNAME] = False + elif _listed(word, COMMON_GIVEN_NAMES): + vetoed += 1 + elif _listed(word, COMMON_SURNAMES): + votes[Signal.FIRST_SURNAME] = True + return out, moved, vetoed + + +def _decide_two_family_names( + votes: list[dict[Signal, Vote]], moved: int, vetoed: int, + base_value: bool, note: str = "" + ) -> tuple[SettingEvidence, dict[str, object]]: + """Decide ``two_family_names`` (rules/O6): true where at least + _MIN_TWO_FAMILY_VOTES names vote for it and they are more than + _MIN_TWO_FAMILY_SHARE of the names the switch would move, and more + than the names it would read a father's name in as a first surname. + A group never decides it false.""" + size = len(votes) + voters = sum(v.get(Signal.FIRST_SURNAME) is True for v in votes) + fathers = sum(v.get(Signal.FIRST_SURNAME) is False for v in votes) + rows: Counter[tuple[Signal, Vote]] = Counter( + pair for v in votes for pair in v.items()) + by_signal = tuple(sorted(((sig, vote, n) for (sig, vote), n + in rows.items()), + key=lambda row: (_SIGNAL_RANK[row[0]], + _label(row[1])))) + if note or not moved: + return (SettingEvidence(_TWO_FAMILY_NAMES, base_value, False, 0, 0, + 0, size, (), note), {}) + decided = (voters >= _MIN_TWO_FAMILY_VOTES + and voters > _MIN_TWO_FAMILY_SHARE * moved + and voters > fathers) + value = True if decided else base_value + noun = "name" if moved == 1 else "names" + text = (f"{voters} of the {moved} {noun} two_family_names would " + f"change carry a common surname where it would take a first " + f"surname") + if vetoed: + text += (f"; {vetoed} of them a common given name there, which " + f"casts no vote") + if fathers: + text += (f"; {fathers} a father's name there, which it would read " + f"as a first surname") + fields: dict[str, object] = ( + {_TWO_FAMILY_NAMES: True} if decided and not base_value else {}) + # counted for and against the value kept, as the other switches are + for_, against = (voters, fathers) if value else (fathers, voters) + return (SettingEvidence(_TWO_FAMILY_NAMES, value, decided, for_, + against, 0, size - voters - fathers, by_signal, + text), fields) + + def suggest(parser: Parser, names: Iterable[str]) -> Suggestion: """The settings a group of names suggests, with ``parser`` as the base: see :meth:`Parser.suggest`.""" tallies = {_NAME_ORDER: _Tally(), _PATRONYMIC_RULES: _Tally()} - evidence: list[NameEvidence] = [] any_voters = comma_left_out = 0 texts = list(_texts(names)) family_first = parser.policy.name_order != GIVEN_FIRST @@ -1619,7 +1768,6 @@ def capitals_reader() -> Parser: if not trailing_votes and Signal.TRAILING_INITIAL in votes: del votes[Signal.TRAILING_INITIAL] set_aside += not votes - evidence.append(NameEvidence(text, votes, family_in_capitals=mark)) comma_left_out += comma per_setting: dict[str, list[tuple[Signal, Vote]]] = { setting: [] for setting in tallies} @@ -1634,7 +1782,8 @@ def capitals_reader() -> Parser: tallies[_PATRONYMIC_RULES], policy.patronymic_rules, any_voters, _keeps_family_first(policy, tallies[_NAME_ORDER].winner(), with_words)) - if set_aside and any(Signal.PATRONYMIC in n.votes for n in evidence): + if set_aside and any(Signal.PATRONYMIC in votes + for _, votes, _, _ in with_words): # the evidence says what its share was taken of: the names a # set-aside vote left with none still count among those casting # one, and show as no evidence @@ -1651,6 +1800,34 @@ def capitals_reader() -> Parser: trailing_note) fields = {**order_fields, **patronymic_fields, **letter_fields, **capitals_fields} + # weighed only where the rest gives a given-first order (#1452): the + # parser the other settings suggest, asked with the switch on + with warnings.catch_warnings(): + # the base gave its construction warnings when it was built + warnings.simplefilter("ignore") + reader = dataclasses.replace(parser, policy=apply_patch( + policy, PolicyPatch(**fields))) # type: ignore[arg-type] + family_votes: list[dict[Signal, Vote]] = [{} for _ in texts] + moved = vetoed = 0 + if policy.two_family_names: + two_note = "not read: the base reads two family names already" + elif PatronymicRule.EAST_SLAVIC in reader.policy.patronymic_rules: + two_note = ("not read: the East Slavic rule is on, and the switch " + "would read a patronymic as a first surname") + elif reader.policy.name_order != GIVEN_FIRST: + two_note = ("not read: the order is family-first, and two family " + "names are weighed under a given-first order alone") + else: + family_votes, moved, vetoed = _two_family_votes(with_words, reader) + two_note = "" + two_family, two_fields = _decide_two_family_names( + family_votes, moved, vetoed, policy.two_family_names, two_note) + fields.update(two_fields) + evidence = [NameEvidence(text, {**votes, **extra}, + family_in_capitals=mark) + for (text, votes, _, _), mark, extra + in zip(with_words, marks, family_votes)] patch = PolicyPatch(**fields) # type: ignore[arg-type] - return Suggestion(parser, patch, (order, patronymic, letters, capitals), + return Suggestion(parser, patch, + (order, patronymic, letters, capitals, two_family), tuple(evidence)) diff --git a/tests/v2/test_suggest.py b/tests/v2/test_suggest.py index 0821b7db4..d4af28408 100644 --- a/tests/v2/test_suggest.py +++ b/tests/v2/test_suggest.py @@ -2497,11 +2497,23 @@ def test_a_decomposed_name_votes_as_its_composed_twin( #: relaxed answer equals its guarded one guards nothing here. #: (threshold, relaxed value, group, base order, guarded, relaxed), the #: answers as the name_order, patronymic_rules and initials_as_family -#: patches, and the capitals_as_family patch where a fourth is given (a -#: row of three holds it unset under both). +#: patches, the capitals_as_family patch where a fourth is given and the +#: two_family_names patch where a fifth is (a shorter row holds the rest +#: unset under both). _UNGUARDED_EFFECT: list[tuple[str, object, list[str], tuple[Role, Role, Role], tuple[object, ...], tuple[object, ...]]] = [ + # two names with a listed surname second-to-last: two votes, under + # the three the switch needs (#1452) + ("_MIN_TWO_FAMILY_VOTES", 2, ["Ana García López", "Luis Pérez Ruiz"], + GIVEN_FIRST, (UNSET, UNSET, UNSET, UNSET, UNSET), + (UNSET, UNSET, UNSET, UNSET, True)), + # three votes among twelve names the switch moves: 25%, under 30% + ("_MIN_TWO_FAMILY_SHARE", 0.1, + ["Ana García López", "Luis Pérez Ruiz", "Elena Torres Díaz"] + + [f"Ana Xx{c}mir Qq{c}lov" for c in "abcdefghi"], + GIVEN_FIRST, (UNSET, UNSET, UNSET, UNSET, UNSET), + (UNSET, UNSET, UNSET, UNSET, True)), ("_MIN_VOTES", 1, ["Smith Mary", "Xyzzy Plugh"], GIVEN_FIRST, (UNSET, UNSET, UNSET), (FAMILY_FIRST, UNSET, UNSET)), ("_MIN_SHARE", 0.5, ["Smith Mary", "Kim Minjun", "Jason Smith"], @@ -2561,10 +2573,11 @@ def test_each_threshold_changes_its_recorded_answer( def answer() -> tuple[object, ...]: patch = base.suggest(names).patch return (patch.name_order, patch.patronymic_rules, - patch.initials_as_family, patch.capitals_as_family) + patch.initials_as_family, patch.capitals_as_family, + patch.two_family_names) def four(answers: tuple[object, ...]) -> tuple[object, ...]: - return answers if len(answers) == 4 else (*answers, UNSET) + return (*answers, *(UNSET,) * (5 - len(answers))) assert answer() == four(guarded) monkeypatch.setattr(_suggest, threshold, relaxed) @@ -3141,18 +3154,21 @@ def test_the_base_parse_is_asked_only_of_a_listed_title( monkeypatch: pytest.MonkeyPatch) -> None: # a family in capitals the vocabulary lists as no title costs the # switch-on parse alone; one it lists costs the base parse too + # (the base object itself: the two_family_names vote parses under a + # copy of it, #1452) calls: list[str] = [] real = Parser.parse + base = Parser() def counting(self: Parser, text: str) -> object: - if not self.policy.capitals_as_family: + if self is base: calls.append(text) return real(self, text) monkeypatch.setattr(Parser, "parse", counting) - Parser().suggest(["Jean DUPONT", "Marie MARTIN", "Anne Leroy"]) + base.suggest(["Jean DUPONT", "Marie MARTIN", "Anne Leroy"]) assert calls == [] - Parser().suggest(["MISS Ann Berg", "Jean DUPONT"]) + base.suggest(["MISS Ann Berg", "Jean DUPONT"]) assert calls == ["MISS Ann Berg"] @@ -3346,3 +3362,271 @@ def test_a_suggestion_holding_a_position_vote_round_trips() -> None: again = pickle.loads(pickle.dumps(s)) assert again.names == s.names assert again.patch == s.patch + + +# -- #1452: two_family_names ----------------------------------------------- +# The word the switch would take into the family, asked of the parse: +# a listed surname (`García`, `López`) votes True, a father's name votes +# False, a listed given name (`María`) is moved and casts no vote, and a +# name the switch leaves as it is casts nothing. On 13cf07cd no row votes. +@pytest.mark.parametrize("text, vote, moved", [ + ("Zzana García Qqmoreno", True, True), + # the taken word is the unlisted one, the listed surname ending it + ("Zzana Qqmoreno García", None, True), + ("Zzana María Qqmoreno", None, True), + (unicodedata.normalize("NFD", "Zzana María Qqmoreno"), None, True), + ("Zzana Xxmir Qqmoreno", None, True), + # a particle run after it: the word before the run is taken + ("Zzana García de la Qqvega", True, True), + ("Zzana García López Qqmoreno", True, True), + # read past a title, a post-nominal and a comma before post-nominals + ("Dr. Zzana García Qqmoreno", True, True), + ("Zzana García Qqmoreno Jr.", True, True), + ("Gabriel García Qqmarquez, PhD", True, True), + # capitals and the decomposed spelling vote alike + ("Zzana GARCÍA Qqmoreno", True, True), + (unicodedata.normalize("NFD", "Zzana García Qqmoreno"), True, True), + # a father's name or its marker votes against, in any script or case + ("Ivan Petrovich Qqsidorov", False, True), + ("IVAN PETROVICH QQSIDOROV", False, True), + ("Иван Петрович Сидорров", False, True), + ("Anna Ivanovna Qqsidorova", False, True), + (unicodedata.normalize("NFD", "Ali Vali oğlu Qqmammadov"), False, True), + # moved but read by no signal: a comma before a job, words joined by + # an interpunct; each counts in the share and casts no vote + ("Zzana García Qqmoreno, Clinical Research Coordinator", None, True), + ("马丁·路德·金", None, True), + # not moved: an initial, a comma, two words, a hyphenated family + ("Zzana G. Qqmoreno", None, False), + ("Qqmoreno, Zzana García", None, False), + ("Zzana Qqmoreno", None, False), + ("Zzana García-López", None, False), +]) +def test_a_listed_surname_the_switch_would_take_votes_for_it( + text: str, vote: bool | None, moved: bool) -> None: + from nameparser._suggest import _read, _two_family_votes + parser = Parser() + votes, moved_count, _ = _two_family_votes( + [(text, *_read(text, parser.lexicon))], parser) + assert votes[0].get(Signal.FIRST_SURNAME) is vote + assert bool(moved_count) is moved + + +#: Three names written given first with two family names, each first +#: surname a listed one (`García`, `López`, `Pérez`). +_TWO_FAMILY = ["Zzana García Qqmoreno", "Qqluis López Xxromero", + "Xxelena Pérez Vvnavarro"] +#: Three Russian names written given first, too few to decide the East +#: Slavic rule, each a father's name where the switch would take a word. +_RUSSIAN_GIVEN_FIRST = ["Ivan Petrovich Qqsidorov", "Anna Sergeevna Qqpetrova", + "Oleg Ivanovich Qqvolkov"] + + +@pytest.mark.parametrize("base_order", [ + GIVEN_FIRST, FAMILY_FIRST, FAMILY_FIRST_GIVEN_LAST]) +def test_a_list_of_two_family_names_gets_the_switch( + base_order: tuple[Role, Role, Role]) -> None: + # `Ana` and `Luis`, listed given names opening each name, decide the + # given-first order on every base, under which the switch is weighed + names = [f"Ana {n}" for n in _TWO_FAMILY] + [f"Luis {n}" for n in + _TWO_FAMILY] + s = Parser(policy=Policy(name_order=base_order)).suggest(names) + assert s.parser.policy.name_order == GIVEN_FIRST + assert s.parser.policy.two_family_names is True + assert s.patch.two_family_names is True + evidence = [e for e in s.evidence if e.setting == "two_family_names"][0] + assert (Signal.FIRST_SURNAME, True, 6) in evidence.by_signal + assert {s.parser.parse(n).surname2 for n in names} == { + "Qqmoreno", "Xxromero", "Vvnavarro"} + + +def _two_family(s: Suggestion) -> SettingEvidence: + return [e for e in s.evidence if e.setting == "two_family_names"][0] + + +def test_the_switch_needs_three_votes() -> None: + # left off, the report counts for and against the value kept, as the + # other switches do: the two names voting for the switch are against + s = Parser().suggest(_TWO_FAMILY[:2]) + assert s.patch.two_family_names is UNSET + evidence = _two_family(s) + assert (evidence.votes_for, evidence.votes_against, + evidence.decided) == (0, 2, False) + # three alone decide it, with no order vote cast + s = Parser().suggest(_TWO_FAMILY) + assert s.patch == PolicyPatch(two_family_names=True) + assert (_two_family(s).votes_for, _two_family(s).votes_against) == (3, 0) + + +@pytest.mark.parametrize("unlisted, decided", [(6, True), (7, False)]) +def test_the_switch_needs_three_in_ten_of_the_names_it_moves( + unlisted: int, decided: bool) -> None: + # three votes among nine moved is a third, among ten 30%: not more + names = _TWO_FAMILY + [f"Zzana Xx{c}mir Qq{c}lov" + for c in "abcdefg"[:unlisted]] + s = Parser().suggest(names) + assert _two_family(s).decided is decided + + +def test_a_name_with_a_comma_counts_among_the_names_the_switch_moves() -> None: + # the switch reads the names before a job title too, so they count in + # the share though no signal reads them: 3 of 15 is not more than 30% + names = ["Gabriel García Qqmarquez", "Juan Pérez Qqlopez", + "Ana Gómez Qqsanchez"] + [ + "John Michael Smith, Clinical Research Coordinator", + "Mary Ann Jones, Study Nurse", + "Robert James Brown, Principal Investigator"] * 4 + s = Parser().suggest(names) + assert s.patch.two_family_names is UNSET + assert _two_family(s).note.startswith( + "3 of the 15 names two_family_names would change") + + +def test_a_given_name_the_switch_would_take_lowers_the_share() -> None: + # `María` is a second given name: moved, so it counts in the share, + # and casts no vote; three surnames among eight moved is 37.5%, over + # 30%, so the given names lower the share without vetoing the switch + names = _TWO_FAMILY + [f"Zzana María Qq{c}lov" for c in "abcde"] + s = Parser().suggest(names) + note = _two_family(s).note + assert "5 of them a common given name there" in note + assert _two_family(s).decided + + +def test_names_the_table_does_not_list_can_be_outvoted() -> None: + # the accepted cost of the 30% share: three Spanish names decide the + # switch beside four English ones, whose second given names it then + # reads as first surnames (Michael and Ann listed, James not) + names = _TWO_FAMILY + ["John Michael Smith", "Mary Ann Jones", + "Robert James Brown", "Zzx Qqy Zzz"] + s = Parser().suggest(names) + assert s.patch.two_family_names is True + assert s.parser.parse("John Michael Smith").family == "Michael Smith" + + +def test_patronymics_beside_two_family_names_keep_the_switch_off() -> None: + # five Russian names written given first, which the switch would read + # with the patronymic as the first surname, against three Spanish + # ones, whose listed given name `Ana` votes on the order, so the + # rule is not decided (5 of 8): 3 for the switch, 5 against, so it + # stays off, counted for and against the value kept + names = [f"Ana {n}" for n in _TWO_FAMILY] + _written("middle", 0, 5) + s = Parser().suggest(names) + evidence = _two_family(s) + assert (evidence.votes_for, evidence.votes_against) == (5, 3) + assert not evidence.decided + assert s.patch.two_family_names is UNSET + + +@pytest.mark.parametrize("spanish, decided", [(3, False), (4, True)]) +def test_the_switch_needs_more_votes_for_it_than_against( + spanish: int, decided: bool) -> None: + names = (_TWO_FAMILY + ["Zzmaria Sánchez Qqruiz"])[:spanish] + _RUSSIAN_GIVEN_FIRST + s = Parser().suggest(names) + assert s.patch.patronymic_rules is UNSET + assert _two_family(s).decided is decided + + +def test_a_fathers_name_disagrees_with_a_decided_switch() -> None: + names = _TWO_FAMILY * 2 + ["Ivan Petrovich Qqsidorov"] + s = Parser().suggest(names) + assert s.patch.two_family_names is True + assert [n.text for n in s.disagreeing()] == ["Ivan Petrovich Qqsidorov"] + assert s.names[-1].votes[Signal.FIRST_SURNAME] is False + report = str(s) + assert "two_family_names True 6 for, 1 against, 0 no evidence" in report + assert "first-surname False 1" in report + assert "; 1 a father's name there" in report + assert "disagreeing (1): Ivan Petrovich Qqsidorov" in report + + +def test_the_evidence_for_the_switch_reads_alike_in_either_order() -> None: + # a False and a True row of one signal sort by their value, not by + # which name of the list cast its vote first + names = ["Ivan Petrovich Qqsidorov"] + _TWO_FAMILY * 2 + forward = _two_family(Parser().suggest(names)) + backward = _two_family(Parser().suggest(names[::-1])) + assert forward.by_signal == backward.by_signal == ( + (Signal.FIRST_SURNAME, False, 1), (Signal.FIRST_SURNAME, True, 6)) + assert forward == backward + + +def test_the_east_slavic_rule_excludes_the_switch() -> None: + base = Parser(policy=Policy(patronymic_rules=_EAST_SLAVIC_RULE)) + s = base.suggest(_TWO_FAMILY * 2) + assert s.patch == PolicyPatch() + assert _two_family(s).note.startswith("not read: the East Slavic rule") + + +def test_a_family_first_list_is_not_weighed_for_the_switch() -> None: + # no mirror under a family-first order in this version (#1452) + names = ["García Qqmoreno Zzana", "López Xxromero Qqluis", + "Pérez Vvnavarro Xxelena"] * 2 + s = Parser(policy=Policy(name_order=FAMILY_FIRST)).suggest(names) + assert s.patch.two_family_names is UNSET + assert _two_family(s).note.startswith("not read: the order is family") + + +def test_an_east_slavic_rule_the_list_decides_excludes_the_switch() -> None: + # read under the parser the rest of the suggestion gives, not the base + names = _TWO_FAMILY * 3 + [f"Ivan Petrovich Qq{c}ov" for c in "abcde"] + s = Parser().suggest(names) + assert s.patch == PolicyPatch(patronymic_rules=_EAST_SLAVIC_RULE) + assert _two_family(s).note.startswith("not read: the East Slavic rule") + + +def test_a_family_first_order_the_list_decides_is_not_weighed() -> None: + names = ["Qqmoreno García Zzana", "Xxromero López Qqluis", + "Vvnavarro Pérez Xxelena"] * 2 + [ + "WANG Xiao Li", "LI Ming Hua", "ZHANG Wei Qi"] + s = Parser().suggest(names) + assert s.patch.name_order == FAMILY_FIRST + assert s.patch.two_family_names is UNSET + assert _two_family(s).note.startswith("not read: the order is family") + + +def test_a_capitals_switch_the_list_decides_moves_no_name() -> None: + # the family in capitals is read whole under capitals_as_family, so + # the switch would take nothing + names = ["Zzana García QQMORENO", "Qqluis López XXROMERO", + "Xxelena Pérez VVNAVARRO"] * 2 + s = Parser().suggest(names) + assert s.patch == PolicyPatch(capitals_as_family=True) + assert (_two_family(s).decided, _two_family(s).note) == (False, "") + + +def test_a_base_reading_middle_names_as_family_moves_no_name() -> None: + s = Parser(policy=Policy(middle_as_family=True)).suggest(_TWO_FAMILY * 2) + assert s.patch == PolicyPatch() + assert (_two_family(s).votes_for, _two_family(s).note) == (0, "") + + +def test_a_base_reading_two_family_names_is_not_weighed() -> None: + s = Parser(policy=Policy(two_family_names=True)).suggest(_TWO_FAMILY) + assert s.patch == PolicyPatch() + assert _two_family(s).note.startswith("not read: the base reads") + + +@pytest.mark.parametrize("vote", [1, 0, "yes", None, GIVEN_FIRST]) +def test_a_first_surname_vote_must_be_a_bool(vote: object) -> None: + with pytest.raises(TypeError, match="must be True or False"): + NameEvidence("Zzana García Qqmoreno", {Signal.FIRST_SURNAME: vote}) # type: ignore[dict-item] + for value in (True, False): + assert NameEvidence("Zzana García Qqmoreno", { + Signal.FIRST_SURNAME: value}).votes == { + Signal.FIRST_SURNAME: value} + + +def test_every_signal_votes_on_one_setting() -> None: + from nameparser._suggest import _SETTING_OF + assert set(_SETTING_OF) == set(Signal) + assert set(_SETTING_OF.values()) <= {f.name for f in + dataclasses.fields(Policy)} + + +def test_a_suggestion_holding_a_first_surname_vote_round_trips() -> None: + import pickle + s = Parser().suggest(_TWO_FAMILY) + assert any(Signal.FIRST_SURNAME in n.votes for n in s.names) + again = pickle.loads(pickle.dumps(s)) + assert (again.names, again.patch) == (s.names, s.patch) diff --git a/tools/differential/README.md b/tools/differential/README.md index c0dbef8d4..f08bc237a 100644 --- a/tools/differential/README.md +++ b/tools/differential/README.md @@ -420,11 +420,11 @@ uv run python tools/differential/config_diff.py score default plain:ES --switche uv run python tools/differential/match_diff.py --base ../master-checkout ``` -**Measuring a change to the group suggester.** `Parser.suggest` moves no parse either, so its check is `suggest_measure.py`: it draws groups of 2 to 200 names (`--sizes`, `--trials`, `--seed`) from populations whose order is known because each name is composed from the boxes its filer typed it into -- PatentsView inventors by country (and, since #1364, the non-CJK inventors whose given box opens with a word PatentsView's boxes write as a family name at least as often, `pv-surname-given`, or with a word of the ORCID surname table, `pv-listed-given`), UK company filers (`psc-individuals`) by nationality, Czech candidates, Vietnamese names, the Russian inventors whose given box holds a patronymic (`pv-RU-patronymic`, the list the East Slavic rule is decided on), ORCID's bylines (and the ones written two or three joined initials first) and the ORCID holders who typed one box wholly in capitals (and the ones from China, Korea, Vietnam and Taiwan, `orcid-famcaps-ea`, and the ones whose family box is two or three letters), all local corpora -- writes each group given-first and family-first, and prints the share of groups whose suggested `name_order` writes the family at the end the group was written with, under a given-first and a family-first base. The two rows where the group is written in its base's own order are the anti-goal (decisions/group-suggestion): a suggestion must not move a group the base already reads right, and the thresholds in `nameparser/_suggest.py` were chosen so that neither falls below 95% at any size, save `orcid-givcaps`' two, names typed with the given name in capitals (`ANNA Smith`), which the capitals signal reads the wrong way round by design (decisions/group-suggestion, 2026-11-12 CAPITALS), `pv-listed-given`'s two, a list of nothing but given names the ORCID surname table lists (`Cooper`, `Burke`), which that table reads the wrong way round, a cost left open (decisions/group-suggestion, 2026-11-19 #1364), and `orcid-byline-joined`'s given-first row at 50 and 100 names, and at 200 until #1357 (bylines written `AM Hoy` and nothing else), one of two cuts added with #1355 to hold the short capitals words in view and explained in that file's 2026-11-14 #1355 entry; the other, `orcid-famcaps-short` (`Zhi LI`), left the list with #1397 (that file's 2026-11-14 #1397 entry). Under each population it prints the groups that decided the East Slavic rule and those that decided `initials_as_family` (rules/O8); under the order table, the share of groups deciding `capitals_as_family` (rules/O9), for every population where any group did, and `--base` lists those cells too. It also prints each population's votes per name (right, wrong, contested, none) and per signal, with `--wrong-words N` each signal's commonest words in a wrong vote; the opensanctions-parliaments table of the 2026-11-10 TURKIC entry; and every parliament list's own suggestion, under the two bases and `FAMILY_FIRST_GIVEN_LAST`, beside the order it was read by eye to write. Its draws run under the two bases only, so what a suggestion does under `FAMILY_FIRST_GIVEN_LAST`, and the East Slavic rule beside `capitals_as_family`, are held by tests (decisions/group-suggestion, 2026-11-15 #1356). `--set NAME=VALUE` tries another threshold without editing the module, and is the harness's proof that it can report a difference: `--set _MIN_VOTES=1000000 --set _MIN_PATRONYMIC_VOTES=1000000 --set _MIN_RUN_NAMES=1000000` decides nothing (the second holds the patronymic rule, which decides a given-first order of its own, save where #1356 keeps the family-first base's, and the third the letters signal's `initials_as_family`, which the two vote counts leave free to decide), so every group written against its base reads 0% (all 60 such rows, at all eight sizes, on 2026-11-15, measured with the first two). `--checks` prints, instead of the tables, the per-name checks the decisions entry quotes (the short romanized surnames' wrong votes, names ending in a bare non-ASCII letter, and, over the groups holding enough names of one patronymic rule to decide it, whether the patronymic share's denominator decides any differently without the contested names). `--base ` measures another tree in a child process and lists the cells that moved, the populations whose count of groups deciding the East Slavic rule moved, and the parliament tables' rows that moved. A source present but yielding no names, and a population or parliament list a present source holds none of, prints a note. A whole run with every source fetched took 20s with `--jobs 12` on one 12-CPU machine (2026-11-10, sizes 2 to 200; a machine-bound figure). +**Measuring a change to the group suggester.** `Parser.suggest` moves no parse either, so its check is `suggest_measure.py`: it draws groups of 2 to 200 names (`--sizes`, `--trials`, `--seed`) from populations whose order is known because each name is composed from the boxes its filer typed it into -- PatentsView inventors by country (and, since #1364, the non-CJK inventors whose given box opens with a word PatentsView's boxes write as a family name at least as often, `pv-surname-given`, or with a word of the ORCID surname table, `pv-listed-given`), UK company filers (`psc-individuals`) by nationality, Czech candidates, Vietnamese names, the Russian inventors whose given box holds a patronymic (`pv-RU-patronymic`, the list the East Slavic rule is decided on), ORCID's bylines (and the ones written two or three joined initials first) and the ORCID holders who typed one box wholly in capitals (and the ones from China, Korea, Vietnam and Taiwan, `orcid-famcaps-ea`, and the ones whose family box is two or three letters), all local corpora -- writes each group given-first and family-first, and prints the share of groups whose suggested `name_order` writes the family at the end the group was written with, under a given-first and a family-first base. The two rows where the group is written in its base's own order are the anti-goal (decisions/group-suggestion): a suggestion must not move a group the base already reads right, and the thresholds in `nameparser/_suggest.py` were chosen so that neither falls below 95% at any size, save `orcid-givcaps`' two, names typed with the given name in capitals (`ANNA Smith`), which the capitals signal reads the wrong way round by design (decisions/group-suggestion, 2026-11-12 CAPITALS), `pv-listed-given`'s two, a list of nothing but given names the ORCID surname table lists (`Cooper`, `Burke`), which that table reads the wrong way round, a cost left open (decisions/group-suggestion, 2026-11-19 #1364), and `orcid-byline-joined`'s given-first row at 50 and 100 names, and at 200 until #1357 (bylines written `AM Hoy` and nothing else), one of two cuts added with #1355 to hold the short capitals words in view and explained in that file's 2026-11-14 #1355 entry; the other, `orcid-famcaps-short` (`Zhi LI`), left the list with #1397 (that file's 2026-11-14 #1397 entry). Under each population it prints the groups that decided the East Slavic rule and those that decided `initials_as_family` (rules/O8); under the order table, the share of groups deciding `capitals_as_family` (rules/O9), and of those deciding `two_family_names` (rules/O6), for every population where any group did, and `--base` lists those cells too. The `orcid-span-CC` populations (#1452: ORCID holders of each of `SPAN_COUNTRIES`, the name composed from their two boxes) add, written given first under a given-first base, whole names read right against the boxes under the suggestion and under the base, and the bare switch off and on over a sample. It also prints each population's votes per name (right, wrong, contested, none) and per signal, with `--wrong-words N` each signal's commonest words in a wrong vote; the opensanctions-parliaments table of the 2026-11-10 TURKIC entry; and every parliament list's own suggestion, under the two bases and `FAMILY_FIRST_GIVEN_LAST`, beside the order it was read by eye to write. Its draws run under the two bases only, so what a suggestion does under `FAMILY_FIRST_GIVEN_LAST`, and the East Slavic rule beside `capitals_as_family`, are held by tests (decisions/group-suggestion, 2026-11-15 #1356). `--set NAME=VALUE` tries another threshold without editing the module, and is the harness's proof that it can report a difference: `--set _MIN_VOTES=1000000 --set _MIN_PATRONYMIC_VOTES=1000000 --set _MIN_RUN_NAMES=1000000 --set _MIN_TWO_FAMILY_VOTES=1000000` decides nothing (the second holds the patronymic rule, which decides a given-first order of its own, save where #1356 keeps the family-first base's, the third the letters signal's `initials_as_family`, which the two vote counts leave free to decide, and the fourth `two_family_names`, #1452), so every group written against its base reads 0% (all 60 such rows, at all eight sizes, on 2026-11-15, measured with the first two). `--checks` prints, instead of the tables, the per-name checks the decisions entry quotes (the short romanized surnames' wrong votes, names ending in a bare non-ASCII letter, and, over the groups holding enough names of one patronymic rule to decide it, whether the patronymic share's denominator decides any differently without the contested names). `--base ` measures another tree in a child process and lists the cells that moved, the populations whose count of groups deciding the East Slavic rule moved, and the parliament tables' rows that moved. A source present but yielding no names, and a population or parliament list a present source holds none of, prints a note. A whole run with every source fetched took 20s with `--jobs 12` on one 12-CPU machine (2026-11-10, sizes 2 to 200; a machine-bound figure). ``` uv run python tools/differential/suggest_measure.py -uv run python tools/differential/suggest_measure.py --set _MIN_VOTES=1000000 --set _MIN_PATRONYMIC_VOTES=1000000 --set _MIN_RUN_NAMES=1000000 +uv run python tools/differential/suggest_measure.py --set _MIN_VOTES=1000000 --set _MIN_PATRONYMIC_VOTES=1000000 --set _MIN_RUN_NAMES=1000000 --set _MIN_TWO_FAMILY_VOTES=1000000 ``` For a vocabulary word whose reading acts on a name position, `tools/vocab/word_report.py` gives the per-word view before and alongside this: the word in a grid of shapes, its incidence in every fetched local corpus, and its `name_usage.py` rows (`nameparser/vocab/README.md`, "Adding a word"). diff --git a/tools/differential/suggest_measure.py b/tools/differential/suggest_measure.py index 5ee997cdd..f149f4c1a 100644 --- a/tools/differential/suggest_measure.py +++ b/tools/differential/suggest_measure.py @@ -176,6 +176,20 @@ SEED = 20261110 #: The most names a population keeps, drawn by a seeded reservoir. POOL_CAP = 20_000 +#: `orcid-span-CC`: ORCID holders of these countries, their given and +#: family boxes as typed (#1452), the population of known surname span +#: two_family_names is measured on: the Spanish- and Portuguese- +#: speaking countries the switch is for, the countries where a second +#: given name or a name both given and family stands second-to-last and +#: the switch must not be suggested, the five the signals do not see, and +#: the United States. +SPAN_FOR = ("ES", "MX", "CO", "PE", "AR", "BR", "PT") +SPAN_NOT = ("BD", "GH", "KE", "PK", "VN", "AO", "MZ", "TR") +SPAN_UNSEEN = ("HR", "SI", "IR", "CD", "CM") +SPAN_COUNTRIES = (*SPAN_FOR, *SPAN_NOT, *SPAN_UNSEEN, "US") +#: The largest group whose names are each parsed for the whole-name +#: score of a span population: the score costs a parse a name a draw. +SPAN_SCORED = 200 #: The names each population's signal counts read. SIGNAL_NAMES = 3_000 PV_COUNTRIES = ("US", "DE", "FR", "CN", "JP", "KR", "IN", "IT", "ES", "RU", @@ -202,10 +216,11 @@ SETTABLE = ("_MIN_VOTES", "_MIN_SHARE", "_MIN_PATRONYMIC_SHARE", "_MIN_PATRONYMIC_VOTES", "_MIN_TRAILING_NAMES", "_MIN_TRAILING_SHARE", "_MIN_RUN_NAMES", "_MIN_RUN_SHARE", - "_MIN_CAPITALS_LETTERS", "_MIN_ORDER_GROUP_SHARE") + "_MIN_CAPITALS_LETTERS", "_MIN_ORDER_GROUP_SHARE", + "_MIN_TWO_FAMILY_VOTES", "_MIN_TWO_FAMILY_SHARE") #: The thresholds that count names (or letters), read as int. _COUNTS = ("_MIN_VOTES", "_MIN_PATRONYMIC_VOTES", "_MIN_TRAILING_NAMES", - "_MIN_RUN_NAMES", "_MIN_CAPITALS_LETTERS") + "_MIN_RUN_NAMES", "_MIN_CAPITALS_LETTERS", "_MIN_TWO_FAMILY_VOTES") #: The countries `orcid-famcaps-ea` reads. EAST_ASIAN_COUNTRIES = frozenset({"CN", "KR", "VN", "TW"}) @@ -460,6 +475,19 @@ def _orcid(keep: _Reservoir) -> None: for r in _checked_rows("orcid-researchers"): _orcid_capitals(keep, r, is_capitals_word) _orcid_byline(keep, r) + _orcid_span(keep, r) + + +def _orcid_span(keep: _Reservoir, r: dict[str, Any]) -> None: + """A holder of one of SPAN_COUNTRIES with both boxes filled and no + comma in either, the boxes as typed (`orcid-span-CC`).""" + country = r.get("country") + if country not in SPAN_COUNTRIES: + return + given = " ".join(unicodedata.normalize("NFC", r.get("given") or "").split()) + family = " ".join(unicodedata.normalize("NFC", r.get("family") or "").split()) + if given and family and "," not in given + family: + keep.add(f"orcid-span-{country}", given, family) def _orcid_capitals(keep: _Reservoir, r: dict[str, Any], @@ -521,7 +549,8 @@ def _orcid_byline(keep: _Reservoir, r: dict[str, Any]) -> None: "cz-candidates": ("cz",), "uit-vinames": ("vi",), "orcid-researchers": ("orcid-byline", "orcid-byline-joined", "orcid-famcaps", "orcid-famcaps-ea", - "orcid-famcaps-short", "orcid-givcaps")} + "orcid-famcaps-short", "orcid-givcaps", + *(f"orcid-span-{c}" for c in SPAN_COUNTRIES))} def load_pools(seed: int) -> tuple[dict[str, Pool], list[str]]: @@ -679,17 +708,26 @@ def family(parser: Parser, text: str) -> str: return families[key] east_slavic = letters = 0 + two: dict[str, list[float | None]] = {} + # a span population's whole names read right against the boxes, + # written given first under the given-first base, at each size up to + # SPAN_SCORED: (names, under the suggestion, under the base) + span = label.startswith("orcid-span-") + whole: dict[int, list[int]] = {} for order in (GF, FF): row = {base: [] for base in bases} caps_row = {base: [] for base in bases} + two_row = {base: [] for base in bases} for size in sizes: if size > len(pool): for base in bases: row[base].append(None) caps_row[base].append(None) + two_row[base].append(None) continue right = Counter[str]() decided = Counter[str]() + two_decided = Counter[str]() for _ in range(trials): names = rng.sample(pool, size) group = [written(t, order) for t in names] @@ -705,6 +743,18 @@ def family(parser: Parser, text: str) -> str: switched = getattr(s.parser.policy, "capitals_as_family", False) decided[base] += switched + # rules/O6's switch (#1452); a tree without the + # suggestion never turns it on + two_decided[base] += ( + getattr(s.parser.policy, "two_family_names", False) + and not parser.policy.two_family_names) + if (span and order == GF and base == GF + and size <= SPAN_SCORED): + tally = whole.setdefault(size, [0, 0, 0]) + for (given, box), text in zip(names, group): + tally[0] += 1 + tally[1] += _whole(s.parser, text, given, box) + tally[2] += _whole(parser, text, given, box) if switched: on = s.parser off = dataclasses.replace(on, policy=dataclasses.replace( @@ -717,9 +767,11 @@ def family(parser: Parser, text: str) -> str: for base in bases: row[base].append(right[base] / trials) caps_row[base].append(decided[base] / trials) + two_row[base].append(two_decided[base] / trials) for base in bases: cells[f"{order}/{base}"] = row[base] capitals[f"{order}/{base}"] = caps_row[base] + two[f"{order}/{base}"] = two_row[base] signals: dict[str, dict[str, int]] = {} words: dict[str, dict[str, list[tuple[str, int]]]] = {} sample = random.Random(f"{seed}-{label}-signals").sample( @@ -759,7 +811,40 @@ def family(parser: Parser, text: str) -> str: # decides in compares equal against a tree without the switch "capitals": (capitals if any(x for row in capitals.values() for x in row) else {}), - "capitals_family_right": dict(family_right)} + "capitals_family_right": dict(family_right), + # only where some group decided it, as the capitals rows + "two_family": (two if any(x for row in two.values() for x in row) + else {}), + "whole": {str(k): v for k, v in sorted(whole.items())}, + "switch": _switch_score(pool) if span else {}} + + +def _whole(parser: Parser, text: str, given: str, family: str) -> bool: + """Whether the parser reads the name as its boxes split it: the given + and middle names the given box, the family the family box, case + folded.""" + r = parser.parse(text) + read_given = " ".join(w for w in (r.given, r.middle) if w) + return (read_given.casefold() == given.casefold() + and r.family.casefold() == family.casefold()) + + +def _switch_score(pool: Pool) -> dict[str, int]: + """A span population's whole names read right written given first, + under the default parser and with the bare switch on, over a fixed + sample of SIGNAL_NAMES names: what the switch is worth for the list, + as config_diff.py's score reads it from the same boxes.""" + from nameparser import Parser as _Parser, Policy as _Policy + sample = random.Random("span-switch").sample( + pool, min(SIGNAL_NAMES, len(pool))) + off, on = _Parser(), _Parser(policy=_Policy(two_family_names=True)) + out = Counter[str]() + for given, family in sample: + text = f"{given} {family}" + out["names"] += 1 + out["off"] += _whole(off, text, given, family) + out["on"] += _whole(on, text, given, family) + return dict(out) #: The populations whose names the romanized surname table is for. @@ -953,6 +1038,9 @@ def _measure_parliaments(lists: dict[str, dict[str, list[str]]] if capitals is not None and capitals.decided: row["capitals"] = [capitals.votes_for, capitals.votes_against] + two = evidence.get("two_family_names") + if two is not None and two.decided: + row["two_family"] = [two.votes_for, two.votes_against] suggestions.append(row) return {"turkic": turkic, "suggestions": suggestions} @@ -1026,6 +1114,30 @@ def report(result: dict[str, Any], show_words: bool) -> None: print(f"{'':16} family read as the box where decided: " f"{right['on'] / n:.1%} with the switch, " f"{right['off'] / n:.1%} without, over {n} names") + two = [p for p in result["populations"] if p.get("two_family")] + if two: + print("\n-- groups deciding two_family_names (rules/O6), where any " + "did; written order / base order") + print(f"{'population':16} {'written':7} {'base':4} " + + " ".join(f"{n:>6}" for n in sizes)) + for p in two: + for key, row in p["two_family"].items(): + order, base = key.split("/") + print(f"{p['label']:16} {order:7} {base:4} " + + " ".join(_pct(x) for x in row)) + spans = [p for p in result["populations"] if p.get("whole")] + if spans: + print("\n-- whole names read right against the boxes, written given " + "first under a given-first base: under the suggestion / under " + "the base, by size; then the bare switch over a sample") + for p in spans: + cells = " ".join( + f"{n}:{w[1] / w[0]:.0%}/{w[2] / w[0]:.0%}" + for n, w in p["whole"].items()) + sw = p["switch"] + print(f"{p['label']:16} {cells} switch " + f"{sw['off'] / sw['names']:.1%} -> " + f"{sw['on'] / sw['names']:.1%} of {sw['names']}") print(f"\n-- votes per name (right/wrong/contested/none) and per signal " f"(right/wrong), at most {SIGNAL_NAMES} names") for p in result["populations"]: @@ -1074,8 +1186,12 @@ def report(result: dict[str, Any], show_words: bool) -> None: def moved(base: dict[str, Any], head: dict[str, Any]) -> list[str]: """What differs between two runs of the same draw: the cells, the - groups that decided the East Slavic rule, the TURKIC table's rows - and every parliament list's suggestion.""" + groups that decided the East Slavic rule, initials_as_family, + capitals_as_family or two_family_names, the whole names read right + against the boxes, the TURKIC table's rows and every parliament + list's suggestion (a parliament's capitals and two_family fields are + recorded only where decided, so a move between two undecided counts + is not listed).""" old = {p["label"]: p for p in base["populations"]} out = [] for p in head["populations"]: @@ -1097,13 +1213,22 @@ def moved(base: dict[str, Any], head: dict[str, Any]) -> list[str]: out.append(f"{p['label']:14} capitals_as_family family right " f"{was.get('capitals_family_right')} -> " f"{p.get('capitals_family_right')}") - old_caps, new_caps = was.get("capitals") or {}, p.get("capitals") or {} - for key in sorted(set(old_caps) | set(new_caps)): - before, after = old_caps.get(key), new_caps.get(key) - if before != after: - out.append(f"{p['label']:14} capitals_as_family {key:6} " - + " ".join(_pct(x, 1) for x in before or []) - + " -> " + " ".join(_pct(x, 1) for x in after or [])) + for field, setting in (("capitals", "capitals_as_family"), + ("two_family", "two_family_names")): + old_rows, new_rows = was.get(field) or {}, p.get(field) or {} + for key in sorted(set(old_rows) | set(new_rows)): + before, after = old_rows.get(key), new_rows.get(key) + if before != after: + out.append(f"{p['label']:14} {setting} {key:6} " + + " ".join(_pct(x, 1) for x in before or []) + + " -> " + + " ".join(_pct(x, 1) for x in after or [])) + for field in ("whole", "switch"): + # #1452's scores against the boxes: which names are read + # right can move where how often the switch is decided does not + if was.get(field) != p.get(field): + out.append(f"{p['label']:14} {field} {was.get(field)} -> " + f"{p.get(field)}") parl_old, parl_new = base.get("parliaments") or {}, head.get("parliaments") or {} turkic_old = parl_old.get("turkic", {}) for dataset, row in (parl_new.get("turkic") or {}).items():