diff --git a/AGENTS.md b/AGENTS.md index 6e6065c97..2915c7a60 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -283,7 +283,7 @@ The compiled sets, read by `Lexicon` (mostly as the `_sets` field of the same na - listed spellings — `SAME_AS`, private, read by `Lexicon` as `_same_as` and nowhere in a parse: every `same_as` keyed by the group of its reading's kind (`_reading_index.SAME_AS_GROUPS`: `given` for a given name or a bound given name, `family` for a surname or a particle, `title`, `suffix`), each word with every full form it carries there (`sr` among titles is both `señor` and `senhor`). The name match (`_match.py`) reads each role in its group through `Lexicon._headwords`, every word reachable through the group's links, so a given name's spelling never matches a surname (`Ma, Jack` / `María, Jack` conflict) and a loop is simply all its words (decisions/name-matching, 2026-11-08); and `SAME_AS_NAMED`, per group, the words of it whose name reading's `same_as` stands beside a name reading of the same kind with none, a name of its own too (`jo`), whose links `_headwords` follows only where `_match._spellings` read the word with its trailing period (the 2026-11-08 #1006 follow-up) - familiar forms — `FAMILIAR`, private, read by `Lexicon` as `_familiar` (through `Lexicon._familiar_forms`) and nowhere in a parse: each `familiar` reading's `short_for`, the longer given names a short one stands for (`max` -> `maximilian`, `maxwell`), every file's together, which `Lexicon` reads both ways (a pair matches whichever way its source wrote it, never chained) and the name match reads as the opt-in `familiar-form`. `familiar` is a category of its own, never a `given` reading, which would move parses where the word is also a title, particle or suffix; a choice neither prefers nor drops by it (`_reading_index.UNPREFERRED`), and `tools/vocab/familiar.py` writes the shipped ones, and the shipped spellings, from `tools/vocab/familiar_reviewed.tsv` alone, the pairs `tools/vocab/familiar_candidates.py` finds in ORCID, and a few familiar forms the FEC's filings and Congress's legislators evidence, counted by recipes in decisions/name-matching rather than a committed tool, as two readers reviewed them (decisions/name-matching, 2026-11-08 FAMILIAR FORMS, 2026-11-12 ALTERNATE SPELLINGS ARE OPT-IN and 2026-11-13 THE FAMILIAR FORMS FROM DATA ALONE); and `ALTERNATE_SPELLINGS` beside it, each `spelling` reading's `spelling_of`, the given names a name is another spelling of by the person's or a romanization's choice (`olha` of `olga`), read by `Lexicon` as `_alternate` (through `Lexicon._alternate_spellings`) both ways and never chained, and by the name match as the opt-in `alternate-spelling`: a kind of its own, never a `given` reading's `same_as`, which would make the word a name written short and move parses (`GIVEN_NAME_ABBREVIATIONS`) -- the group suggester's tables — `config/_order_names.py`, private, written by `tools/vocab/order_names.py` (`--write`; its hand-kept spelling lists sit above the generated blocks) and read by `_suggest` only, never by a parse or a `Lexicon`: `ROMANIZED_SURNAMES` (zh, ko and vi surnames folded by `_suggest.fold`) and `COMMON_GIVEN_NAMES`. They are not `Lexicon` kinds, so a language choice, `strict=True` and a caller's edit do not reach them and no snapshot moves with them (decisions/group-suggestion, 2026-11-10 TABLES) +- the group suggester's tables — `config/_order_names.py`, private, written by `tools/vocab/order_names.py` (`--write`; its hand-kept spelling lists sit above the generated blocks) and read by `_suggest` only, never by a parse or a `Lexicon`: `ROMANIZED_SURNAMES` (zh, ko and vi surnames folded by `_suggest.fold`), `COMMON_GIVEN_NAMES`, and `COMMON_SURNAMES` (#1364, the given names' mirror: family-box words ORCID's holders rarely type as a given name, mostly Spanish), the two surname tables read together as `SURNAMES`. They are not `Lexicon` kinds, so a language choice, `strict=True` and a caller's edit do not reach them and no snapshot moves with them (decisions/group-suggestion, 2026-11-10 TABLES) `config/__init__.py` holds a docstring only: the package is the home of the data modules, and since 3.0 nothing else (#357), all of them private (#1007; `regexes` went with #1008; `surnames` became `_ko_surnames` in #1077, named for `vocab/ko.toml`'s tag, and stays in `config/` because the default lexicon reads it and `_lexicon` may not import `locales/`, a layer above it). @@ -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 `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 entry carrying a re-taken table, 2026-11-15 #1357's, holds the table 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, 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 entry carrying re-taken sizes, 2026-11-19 #1364's, holds 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 b3114555e..0e600992c 100644 --- a/docs/design/decisions/group-suggestion.md +++ b/docs/design/decisions/group-suggestion.md @@ -3,15 +3,15 @@ ## Standing - The parser never detects language; the group suggester (`Parser.suggest`) may, over a group the caller declares, says what it saw, and its answer is configuration the caller applies; the parse itself is untouched by it — 2026-11-10 SCOPE. -- The two word tables the suggester reads (romanized zh, ko and vi surnames; common given names) are private compiled tables for the first version, not `Lexicon` kinds: no parse reads them, a language choice or `strict=True` does not filter them and a caller cannot edit them — 2026-11-10 TABLES. +- The word tables the suggester reads (romanized zh, ko and vi surnames; common given names; the surnames ORCID's holders rarely type as a given name, below) are private compiled tables for the first version, not `Lexicon` kinds: no parse reads them, a language choice or `strict=True` does not filter them and a caller cannot edit them — 2026-11-10 TABLES. - 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. -- No surname table beyond the romanized zh, ko and vi one for 3.1; #1364 stays open for 3.2 — 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. - 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. -- An East Slavic group gets the patronymic rule with a given-first order, since the rule reads either written order one name at a time and reorders none under a declared family-first order, unless the names' own order votes decide family-first, which the rule never overrides, or the next line keeps a `FAMILY_FIRST` base's order — 2026-11-10 SIGNALS, 2026-11-10 FIX WAVE. +- An East Slavic group gets the patronymic rule with a given-first order, since the rule reads either written order one name at a time and reorders none under a declared family-first order, unless the names' own order votes decide family-first, which the rule never overrides (a `FAMILY_FIRST_GIVEN_LAST` base then gets `FAMILY_FIRST`), or the next line keeps a `FAMILY_FIRST` base's order — 2026-11-10 SIGNALS, 2026-11-10 FIX WAVE, 2026-11-19 #1364. - Where the East Slavic rule is decided under a `FAMILY_FIRST` base and the names' own votes do not decide given-first, the suggestion keeps the base's order and suggests the rule alone if more of the names carrying the patronymic write it last (family, given, patronymic) than in the middle (given, patronymic, family); a tie, a middle majority, a `FAMILY_FIRST_GIVEN_LAST` base and a given-first base get the given-first order with the rule, as before; a base already carrying the rule keeps its rule value on every branch — 2026-11-15 #1356. - A list mixing East Slavic and Turkic patronymics is left as it is for 3.1: one patronymic decision is made for the list, by the thresholds, so the larger set's rule where it clears them and none where neither does — 2026-11-15 #1356. - 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. @@ -26,12 +26,12 @@ - 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. 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 does now: no same-order cell moves, and groups written given-first move a family-first base sooner. 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, a surname table for names outside zh, ko and vi, is open for 3.2: 2026-11-15 #1357 holds what a gate measured for it (a dated snapshot), the cost no population of the tool shows (a list whose given names are listed surnames) and the sources no entry of decisions/shipped-data-licences clears. 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 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. 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 does now: no same-order cell moves, and groups written given-first move a family-first base sooner. 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%. ## Log - **2026-11-10 SCOPE — THE NEVER-DETECT-LANGUAGE RULE IS ABOUT THE PARSE, AND THE GROUP SUGGESTER IS OUTSIDE IT (DECIDED BY 2026-11-15 ACCEPTED).** AGENTS.md's design philosophy says the parser never detects language, because the language of a Latin-script name cannot be read off the name. `Parser.suggest` works on a group the caller declares to share one convention, reads statistics over the group and returns configuration with the evidence behind it, which the caller applies; it never mutates a base `Parser` or a default and changes no parse. Proposed wording: "the parser never detects language; the group suggester may, says what it saw, and its answer is configuration the caller applies". The given-name table does not ask what language a name is; it asks whether a word is almost always a given name, anywhere. This entry is the first commit of the branch so the wording can be settled before the code is read; the only items recorded as decided are the two under TABLES (the private tables, the nam_dict approval); the rest of this file was proposed for review when this entry was written (decided since, 2026-11-15 ACCEPTED). -- **2026-11-10 TABLES — TWO PRIVATE COMPILED TABLES, READ BY THE SUGGESTER ONLY (THE PRIVATE TABLES AND THE NAM_DICT DERIVATION DECIDED THAT DAY; THE REST DECIDED BY 2026-11-15 ACCEPTED).** (The pinyin's source and its Unicode licence superseded by 2026-11-12 PINYIN FROM WIKIDATA: the surname readings Wikidata's family-name items state, CC0; the given-name table's source, nam_dict's country columns, by 2026-11-12 GIVEN NAMES FROM ORCID: ORCID's given-name boxes by stated country; its family share of 5%, "set once and not tuned", superseded by 2026-11-15 #1357: 10%, measured.) The romanized surnames (zh, ko, vi) and the common given names are written by tools under `tools/vocab/`, like `familiar.py`, into committed private modules under `nameparser/config/`, with a test that each is current. They are not `Lexicon` kinds for the first version, because a `family` reading on `Lee`, `Song` or `Long` would move the suffix gates derived from name readings and a `given` reading would move titles and particles; a table no parse reads moves no snapshot. Making them `Lexicon` kinds later, if a caller needs to tune them, stays open. The given-name table is derived from nam_dict's 55 country columns (top N per country by frequency band, unioned), keeping a name only if ORCID's researchers wrote it in the family box at most 5% of the times they wrote it (at least 20 uses), it is longer than one letter and it is not in the romanized surname sets. N (500) was chosen with the spikes (SIGNALS, top 100 against top 500); the family share and the use count were set once and not tuned, the THRESHOLDS measurement finding that the tables meet its constraint as built. Licences: nam_dict GNU FDL 1.2, ORCID's public data file CC0, Unihan the Unicode licence; the module header carries the sources once. The table derived from nam_dict is approved. +- **2026-11-10 TABLES — TWO PRIVATE COMPILED TABLES, READ BY THE SUGGESTER ONLY (THE PRIVATE TABLES AND THE NAM_DICT DERIVATION DECIDED THAT DAY; THE REST DECIDED BY 2026-11-15 ACCEPTED).** (The pinyin's source and its Unicode licence superseded by 2026-11-12 PINYIN FROM WIKIDATA: the surname readings Wikidata's family-name items state, CC0; the given-name table's source, nam_dict's country columns, by 2026-11-12 GIVEN NAMES FROM ORCID: ORCID's given-name boxes by stated country; its family share of 5%, "set once and not tuned", superseded by 2026-11-15 #1357: 10%, measured; its two tables made three by 2026-11-19 #1364, the ORCID surnames.) The romanized surnames (zh, ko, vi) and the common given names are written by tools under `tools/vocab/`, like `familiar.py`, into committed private modules under `nameparser/config/`, with a test that each is current. They are not `Lexicon` kinds for the first version, because a `family` reading on `Lee`, `Song` or `Long` would move the suffix gates derived from name readings and a `given` reading would move titles and particles; a table no parse reads moves no snapshot. Making them `Lexicon` kinds later, if a caller needs to tune them, stays open. The given-name table is derived from nam_dict's 55 country columns (top N per country by frequency band, unioned), keeping a name only if ORCID's researchers wrote it in the family box at most 5% of the times they wrote it (at least 20 uses), it is longer than one letter and it is not in the romanized surname sets. N (500) was chosen with the spikes (SIGNALS, top 100 against top 500); the family share and the use count were set once and not tuned, the THRESHOLDS measurement finding that the tables meet its constraint as built. Licences: nam_dict GNU FDL 1.2, ORCID's public data file CC0, Unihan the Unicode licence; the module header carries the sources once. The table derived from nam_dict is approved. - **2026-11-10 SIGNALS (its "the rule stands down under a family-first base" superseded by 2026-11-15 #1356 as wider than true: the rule's reordering stands down, its patronymic view fills under `FAMILY_FIRST`) — WHAT EACH SIGNAL VOTES, AS MEASURED WITH THE THROWAWAY SPIKES (DECIDED BY 2026-11-15 ACCEPTED).** Measured with the throwaway spikes on 2026-11-10. The spikes counted votes per SIGNAL (a name read by two signals cast two votes, and its group decided on the signal votes), where `suggest` counts one order vote per NAME, so their group figures below are not comparable with suggest's; the per-name re-take, with its command, is 2026-11-10 THRESHOLDS. Populations are PatentsView inventors by country, UK company filers (PSC) by nationality, Czech candidates, Vietnamese names and national parliament lists (OpenSanctions); none of them built the given-name list. - Capitals word position: decisive where present (Turkey's parliament `Mehmet DEMİR` 592:0); a capitals run in the middle (Hong Kong `Jeffrey LAM Kin-fung`) does not vote. - Comma names do not vote on order: 373 comma names outvoted the comma-less majority of India's Lok Sabha list. @@ -95,7 +95,7 @@ Open: the other three settings count their shares among the names with evidence - The real parliament lists, each read whole under both bases (the tool's last table; no draw is involved, so the draw's re-seeding left them as they were): every Latin and Cyrillic list's order comes out as the list writes it or is decided East Slavic (ua_rada, ru_duma_deputies, kg_jogorku_kenesh, kz_senate, uz_senate, uz_legislative_chamber, tm_mejlis), and the same under both bases; az_parliament family-first with `{TURKIC}`, by_council_republic family-first (48 for, 0 against), tr_parliament given-first (566 for, 6 contested), in_sansad given-first (647 for, 167 against, 3 contested, 7,478 no evidence), re-taken after the fix wave read names past their titles, in_sansad's `Smt.`, `Shri` and `Shrimati` above all (565 and 441 for before it, and 586 and 443 before the final capitals word of two or three letters stopped voting). The East Slavic lists that write family-first (ua_rada, kz_senate, uz_senate) get the given-first order the rule needs. - Checks deferred from the reviews: `uv run python tools/differential/suggest_measure.py --checks`, over every population's whole pool written both ways (830,822 names, 2026-11-10, re-taken after the fix wave). The seven short romanized surnames (`do`, `to`, `la`, `le`, `ha`, `ho`, `an`) cast 182 wrong surname votes of 162,521 (183 of 162,546 before); outside the East Asian populations the wrong surname votes come from `lee` 294, `dan` 248 (a Romanian given name), `rao` 179 (an Indian name element written mid-name), `ma` 72 and `kim` 51. A bare non-ASCII trailing letter (`Jean Ö`), which casts no trailing-initial vote where `Jean O` does, ends 51 names against 1,706 ASCII ones. Neither is fixed: the group rule absorbs each. The third check, `fold` leaving `ø` and `ł` unmapped (25 such spellings in the table, several without their ASCII form beside them, so the UK filers' Polish names typed in ASCII cast no vote; mapping both sides moved 2,607 given-name votes to right, 2,543 of them Polish, and 22 away), was taken up by the fix wave, and the check is gone with it. -- **2026-11-10 FIX WAVE (its `Cem`, the example of a table word never read past as a credential, and its `baris`, `pinar` and `blaz` leaving the table at a 5% family share, superseded by 2026-11-15 #1357: no listed suffix is a table word, and those three names are in the table at 10%; its "the rule stands down" under a family-first order superseded by 2026-11-15 #1356: true of the reordering alone, the note now saying the rule "reorders no name", and absent where a `FAMILY_FIRST` base's order is kept) — WHERE A SIGNAL READS, AND WHAT THE RESULT TYPES HOLD (DECIDED BY 2026-11-15 ACCEPTED).** A four-way review of the branch found signals reading where the pipeline does not, and result types that could hold evidence contradicting their patch. What changed in the reading, each as proposed: +- **2026-11-10 FIX WAVE (its `Cem`, the example of a table word never read past as a credential, and its `baris`, `pinar` and `blaz` leaving the table at a 5% family share, superseded by 2026-11-15 #1357: no listed suffix is a table word, and those three names are in the table at 10%; its "the rule stands down" under a family-first order superseded by 2026-11-15 #1356: true of the reordering alone, the note now saying the rule "reorders no name", and absent where a `FAMILY_FIRST` base's order is kept; its family-first order the rule does not override given, for a `FAMILY_FIRST_GIVEN_LAST` base, as `FAMILY_FIRST` by 2026-11-19 #1364) — WHERE A SIGNAL READS, AND WHAT THE RESULT TYPES HOLD (DECIDED BY 2026-11-15 ACCEPTED).** A four-way review of the branch found signals reading where the pipeline does not, and result types that could hold evidence contradicting their patch. What changed in the reading, each as proposed: - A patronymic votes only where the pipeline's rule reads one: rules/O1's three name words with the East Slavic ending on the middle word (given-first) or on the last (`_vocab.east_slavic_rotates`, O1's word test, shared with `_post_rules` rather than copied), whatever the first word ends in, as O1 asks only about the middle and last words, and no initial first or in the middle (O1's precedence); rules/O2's four name words with the Turkic marker last (family-first, O2's rotation) or third (given-first, which `{TURKIC}` reads too, the TURKIC entry above). Before it, an `-ovich` ending on any word voted, so six family-first names whose surnames end in `-ovich` (`Abramovich Roman`, `Rabinovich Pavel`, ...) decided East Slavic 6-0 under a family-first base and forced given-first, reading `Abramovich` as the given name. A first draft of the fix also refused an ending on the first word, which O1 does not ask: `Abramovich Roman Arkadyevich`, which `{EAST_SLAVIC}` reads right, then cast no vote; the PR's re-review found it (2026-11-10), and the two-word false positive is excluded by the three-word count alone. - A decided East Slavic rule no longer overrides an order the names' own votes decide family-first: the rule stays in the patch, the order is the votes', and the order evidence's note says the rule stands down under it (five East Slavic names written `SIDOROV Ivan Petrovich`, their capitals voting family-first). A name carrying the rule's patronymic disagrees on order then, as any name does. - A name is read past the titles the base lexicon lists, and rules/H2's period shape, at its head, and past the suffixes it lists and the numerals the trailing fork reads as the generation at its end, a one-letter numeral and a listed acronym written as initials needing two name words in front (`Armitage V`, `Smith J.P.` end in initials); a word the name tables list is never read past (`Law`, a Cantonese surname and a title; `Cem`, a Turkish given name and a credential). Before it, `Dr. Zhang Xiaoming` cast no surname vote and six titled Chinese names whose given name is also a listed surname (`Dr. Zhang Wei`) moved a family-first base to given-first. An unlisted credential is a name word to the suggester as to the parse (`Tanaka Hiroshi FRCS`, `frcs` being unlisted, still casts a capitals vote). @@ -261,7 +261,7 @@ Open: the other three settings count their shares among the names with evidence - A group gate (option C), not taken for 3.1 and left open beside #659: a short capitals word casts its capitals vote, and is looked up as a surname, only where at least one other name of the group casts a capitals vote for the same end by a word of four letters or more. Same as the shipped rule on the bylines. Its gain: `orcid-famcaps-ea` written family-first under a given-first base 62 / 81 / 94 / 96 / 100% (shipped 21 / 42 / 68 / 79 / 100%), and written given-first under a family-first base, a row weak before and after this entry, 65 / 80 / 93 / 97 / 100 / 100% against 23 / 42 / 58 / 65 / 86 / 92%; the `-CAPS` populations within a few points of those. Its cost: one name with a long capitals word in front (`ANNA Smith`) in a list of joined-initial bylines opens the gate, and 1% to 3% of such groups of 5 to 50 names keep their given-first base, against 79% to 94% under the shipped rule (0% to 1% before either). A gate of two names is as robust as the shipped rule to one such name and recovers about a third of the gain (`orcid-famcaps-ea` family-first under a given-first base 21 / 45 / 69 / 79 / 100%). - #659's item 7 ("capitals words of two or three letters ... stay out of the suggester's evidence") now holds for the order vote too, at both ends of a name; before this entry the opening word voted. The other reading was measured, short words counting toward `capitals_as_family` on master, with this tree's tool reading master's package (`uv run python tools/differential/suggest_measure.py --tree --set _MIN_CAPITALS_LETTERS=2`; master's own tool has no `orcid-byline-joined`): `orcid-byline-joined` groups written given-first decide the switch in 47 / 71 / 85 / 89 / 98 / 100 / 100 / 100% of draws, and over every group of that population that decided it, either written order, the suggested parser reads 4.3% of the families as the box against 40.2% without the switch, over 349,614 names. - Not changed, found here: a short capitals word ENDING a name casts no capitals vote whatever stands before it, a capitals word included (`Zhi WANG LI` casts none, where the opening rule lets a run vote), and is not looked up as a surname (2026-11-10 THRESHOLDS), while the word in front of it still is, so `Zhi LI` casts a family-first surname vote where the given name is a listed surname. In `orcid-famcaps-short` written given-first the surname signal casts 0 right and 440 wrong votes in 3,000 names, and the row under a given-first base, an anti-goal row no default population showed, reads 97 / 96 / 93 / 90 / 79 / 83 / 94 / 100% before and after this entry. Silencing the surname signal on such a name too was measured in the scratch copy: that row reads 100% at every size, at the cost of the family-first bylines' surname votes (`Kim QZ`): `orcid-byline-joined` written family-first under a given-first base 0 / 2 / 4 / 5 / 16 / 37 / 78 / 99% to 0 / 0 / 0 / 0 / 1 / 2 / 10 / 26%. Left open, #1397 (settled by 2026-11-14 #1397, which took a narrower form). -- **2026-11-14 #1397 (its `orcid-byline-joined` row "under 95% at 50 and 200 names" superseded by 2026-11-15 #1357: at 50 names only; its table and its worst same-order row superseded by 2026-11-15 #1356, under which PatentsView's Russian groups read 100% in their base's order) — A LISTED SURNAME ENDING A NAME IN TWO OR THREE CAPITALS SILENCES THE SURNAME VOTE; THE WORD NEVER VOTES ALONE.** Since 2026-11-10 THRESHOLDS a capitals word of two or three letters ending a mixed-case name was not looked up as a surname, while the word in front of it was, so the surname signal, which votes where exactly one end is listed, voted by the word in front alone: `Zhou NG` cast a family-first vote wherever the given name is a listed surname too, and a given-first list of nothing but short capitals surnames moved a given-first base (2026-11-14 #1355's last bullet). Decided: in a name holding a lowercase letter that ends in a capitals word of two or three letters, the surname signal casts no vote where that ending word is itself a listed surname; otherwise it votes by the word in front, as before; the ending word never votes alone; the capitals vote stays silent. The rest of this entry is implementation and record, not decision. +- **2026-11-14 #1397 (its `orcid-byline-joined` row "under 95% at 50 and 200 names" superseded by 2026-11-15 #1357: at 50 names only; its table and its worst same-order row superseded by 2026-11-15 #1356, under which PatentsView's Russian groups read 100% in their base's order; its lookup of the ending word "in the suggester's romanized-surname table" widened by 2026-11-19 #1364 to both surname tables) — A LISTED SURNAME ENDING A NAME IN TWO OR THREE CAPITALS SILENCES THE SURNAME VOTE; THE WORD NEVER VOTES ALONE.** Since 2026-11-10 THRESHOLDS a capitals word of two or three letters ending a mixed-case name was not looked up as a surname, while the word in front of it was, so the surname signal, which votes where exactly one end is listed, voted by the word in front alone: `Zhou NG` cast a family-first vote wherever the given name is a listed surname too, and a given-first list of nothing but short capitals surnames moved a given-first base (2026-11-14 #1355's last bullet). Decided: in a name holding a lowercase letter that ends in a capitals word of two or three letters, the surname signal casts no vote where that ending word is itself a listed surname; otherwise it votes by the word in front, as before; the ending word never votes alone; the capitals vote stays silent. The rest of this entry is implementation and record, not decision. - As implemented: the ending word is looked up, in the suggester's romanized-surname table and under its spelling fold (`Zhou LÍ`), only to veto. A listed one silences the surname signal on the name (`Zhou NG`, `Yoon Zhou LI`, `Zhi WANG NG`, a title or post-nominals read past: `Dr Zhou NG`, `Zhou NG, PhD`); an unlisted one leaves the word in front to vote as before (`Kim QZ`, a byline written family first; `Zhou QZ`), and a listed one behind an unlisted word casts nothing, as before (`Marsh JO`). "The word in front" is the name's first word, the one the surname signal has always read beside the last: in a name of three words or more the words between are read by no table (`Zhou Yoon QZ` votes by `Zhou`). With the veto in place the earlier "not looked up" guard decides nothing the lookup does not (an unlisted word is no vote either way), so the code now looks both ends up and the guard is gone: no reading differs from keeping it, and a mutant restoring it passes every test. The opening word's rule of 2026-11-14 #1355 is unchanged, and silences the signal whatever ends the name (`NG Zhou JO`). The given-name, particle, trailing-initial and patronymic signals read the name as before. - Measured with `uv run python tools/differential/suggest_measure.py --wrong-words 12 --base `, the master this sits on (2026-11-14; 300 groups a size, seed 20261110, sizes 2 / 3 / 4 / 5 / 10 / 20 / 50 / 200). The comparison lists 9 rows that moved, 6 of the order table and 3 of `capitals_as_family`'s names read right: - `orcid-famcaps-short` written given-first, given-first base (the anti-goal row #1397 is about): 97.0 / 96.0 / 93.0 / 89.7 / 79.3 / 83.0 / 94.3 / 100% to 100% at every size. Under a family-first base: 2.0 / 2.3 / 11.3 / 11.3 / 18.3 / 17.0 / 10.3 / 1.3% to 2.0 / 3.7 / 14.0 / 16.7 / 43.0 / 75.3 / 97.3 / 100%. @@ -318,7 +318,7 @@ Open: the other three settings count their shares among the names with evidence - The ending word looked up as any word, so it votes alone too (`silent = _opens_in_short_capitals(words)`). The largest gains written given-first under a family-first base (`orcid-famcaps-short` 43.0 / 69.3 / 82.0 / 93.7 / 99.7 / 100%, `orcid-famcaps-ea` 74.0 / 94.7 / 98.3 / 99.3 / 100%), but initials that spell a surname then vote given-first (`Marsh JO`): `orcid-byline-joined` written family-first casts 41 right and 71 wrong surname votes, and its same-order row falls to 98.7 / 97.0 / 94.3 / 93.7 / 80.3 / 66.7 / 72.3 / 76.7%; `orcid-byline`'s to 100 / 99.3 / 99.3 / 99.3 / 99.0 / 98.0 / 98.7 / 100%. - The first variant for a name of exactly two words, the rule before this entry for a longer one (`silent = _opens_in_short_capitals(words) or (_ends_in_short_capitals(words) and len(words) == 2)`, and in the loop below it `at_last = False` for the surname table where the name ends in a short capitals word). The byline costs of the first variant, cell for cell, and less of the fix: `orcid-famcaps-short` given-first under a given-first base 99.7 / 99.7 / 98.7 / 99.0 / 96.0 / 97.3 / 99.7 / 100%, 147 wrong surname votes left of 440. - How often each shape is written, a dated snapshot of 2026-11-14 on d516e89c (the tree before this change), counted with a script in the 3.1 cycle's session notes (`1397-gate/shapes1397.py`, not the repository; the definition here is all it does). Over the 1,831,533 records of ORCID's `raw.jsonl`, the 125,960 with a non-empty `credit` field: read `words = _suggest._name_words(credit, Lexicon.default())[0]`, the words the signals read past titles and post-nominals, and keep the name where no comma left it out, it has two words or more and `_suggest._ends_in_short_capitals(words)` holds. 1,025 names. A word matches the family box where the two are equal once casefolded with hyphens and spaces removed (the `family` field whole). The last word matches it in 156 (the family written last, in short capitals); of the rest the first word matches it in 573 (a byline, its initials joined); 296 match neither way. The surname vote (`name_votes(credit, lexicon)` at d516e89c) was cast on 40 of the 573, all family-first and so right, and on 19 of the 156, all family-first and so wrong, which is why silencing every such name was not taken. A recount that reads other words (the raw text split at spaces) or matches the family box another way gives other digits; these are this definition's. 5,013 holders have a family box of that shape and a given box with no capitals word (the tool's `orcid-famcaps-short`), which is how they filled a form, not how they write a name. -- **2026-11-15 #1356 (its table, and its `orcid-byline-joined` exception "at 50 and 200 names", superseded by 2026-11-15 #1357) — PATRONYMICS WRITTEN LAST KEEP A FAMILY_FIRST BASE'S ORDER; EVERY OTHER EAST SLAVIC GROUP GETS THE GIVEN-FIRST ORDER AS BEFORE.** A decided East Slavic rule decided the order as given-first on any base (2026-11-10 SIGNALS, FIX WAVE), so a caller who had declared `FAMILY_FIRST` for a list written family first was moved to a setting that reads its names without a patronymic family-last (`Aliyev Farrukh`) and its Turkic marker names by the wrong word. Decided: where the base's order is `FAMILY_FIRST`, the East Slavic rule is decided and the names' own votes do not decide given-first, the suggestion keeps the base's order and suggests the rule only where MORE East Slavic voters end in the patronymic than have it in the middle; otherwise, a tie included, it behaves as before (given-first with the rule). A `FAMILY_FIRST_GIVEN_LAST` base and a given-first base are as before. The order is kept only on that one branch, and a base's own rule value is never dropped. A list mixing East Slavic and Turkic patronymics is left as it is, and `_MIN_PATRONYMIC_VOTES` is unchanged. The rest of this entry is implementation and record. +- **2026-11-15 #1356 (its table, and its `orcid-byline-joined` exception "at 50 and 200 names", superseded by 2026-11-15 #1357; its `QQSIDOROV Zzyvan Petrovich` case under a `FAMILY_FIRST_GIVEN_LAST` base, whose patch now carries `name_order=FAMILY_FIRST` too, by 2026-11-19 #1364) — PATRONYMICS WRITTEN LAST KEEP A FAMILY_FIRST BASE'S ORDER; EVERY OTHER EAST SLAVIC GROUP GETS THE GIVEN-FIRST ORDER AS BEFORE.** A decided East Slavic rule decided the order as given-first on any base (2026-11-10 SIGNALS, FIX WAVE), so a caller who had declared `FAMILY_FIRST` for a list written family first was moved to a setting that reads its names without a patronymic family-last (`Aliyev Farrukh`) and its Turkic marker names by the wrong word. Decided: where the base's order is `FAMILY_FIRST`, the East Slavic rule is decided and the names' own votes do not decide given-first, the suggestion keeps the base's order and suggests the rule only where MORE East Slavic voters end in the patronymic than have it in the middle; otherwise, a tie included, it behaves as before (given-first with the rule). A `FAMILY_FIRST_GIVEN_LAST` base and a given-first base are as before. The order is kept only on that one branch, and a base's own rule value is never dropped. A list mixing East Slavic and Turkic patronymics is left as it is, and `_MIN_PATRONYMIC_VOTES` is unchanged. The rest of this entry is implementation and record. - The facts it rests on, by parse on 8f4b77b9. Under a declared family-first order the rule's REORDERING stands down (rules/O1), and the `patronymic` view it fills (rules/R9) does not: `Policy(name_order=FAMILY_FIRST, patronymic_rules={EAST_SLAVIC})` reads `Sidorov Ivan Petrovich` as family `Sidorov`, given `Ivan`, middle `Petrovich`, patronymic `Petrovich`, the fields of `FAMILY_FIRST` alone and the view. `FAMILY_FIRST` reads a name written given, patronymic, family wrong with or without the rule (`Ivan Petrovich Sidorov`: family `Ivan`). `FAMILY_FIRST_GIVEN_LAST` reads the family of `Sidorov Ivan Petrovich` right and its given name wrong (given `Petrovich`, middle `Ivan`), and the rule alone moves no field and fills no view there. And with a given-first order the rule reads BOTH writings right, rotating the one written family first: a list where every name carries a patronymic is read whole under the forced order, whatever the mix; what that order costs is the names with no patronymic in a list written family first. - As implemented: of the names casting the East Slavic vote, each of three words by rules/O1, a name writes the patronymic in the middle where its middle word carries the ending (`has_patronymic_ending`, the first of the vote's own two tests), and last otherwise; a name with the ending on both words counts as middle, as rules/O1 reads it and rotates nothing. Names casting no East Slavic vote are not counted. Where the order is kept the patronymic evidence's note says how many of the voters write the patronymic last and, where some write it in the middle, how many get no given-first order from the suggestion; it says nothing of how those are read, since `capitals_as_family`, suggested in the same patch, reads them where their family is in capitals (five `QQSIDOROV Zzyvan Petrovich` and three `Jjmark Borisovich JJVOLKAR`: the order kept, the rule and the switch suggested, 8 of 8 whole names read right, 5 at the base); the order evidence is the votes' or the base's, with no rule note. Everywhere else the order evidence carries the earlier note ("it needs a given-first order"). Where the names' own votes decide family-first under a given-first or a `FAMILY_FIRST_GIVEN_LAST` base the rule comes with the votes' order as before, its order note now saying the rule "reorders no name" under it where it said "stands down". A base already carrying the rule: under `FAMILY_FIRST` with the patronymics mostly last, nothing changes and the evidence is decided as the base's; on every other branch the given-first order is suggested and the rule stays the base's. A base carrying the Turkic rule alone gets the East Slavic one beside it on every branch. The Turkic rule's own decision is untouched. - Measured with `uv run python tools/differential/suggest_measure.py --wrong-words 12 --base `, the master this sits on (2026-11-15; 300 groups a size, seed 20261110, sizes 2 / 3 / 4 / 5 / 10 / 20 / 50 / 200), the tool reading one population and one base added with this entry: `pv-RU-patronymic` (8,393 names: PatentsView's Russian inventors whose given box is a given name and a patronymic, so that written given-first they are given, patronymic, family and written family-first family, given, patronymic), and `FAMILY_FIRST_GIVEN_LAST` as a third base for the parliament lists. The parliament rows are from the `opensanctions-parliaments` cache as fetched 2026-11-12, not re-fetched. Five rows moved: @@ -379,7 +379,7 @@ Open: the other three settings count their shares among the names with evidence - And under a `FAMILY_FIRST_GIVEN_LAST` base a list written family, given, patronymic: a9dacf7d left the base's reading, 0 of 8 whole names right, where 8f4b77b9's forced order reads 8. Its own measurements had compared the family alone, which that order reads right. The tool as it stood at a9dacf7d, with no patronymic population and no `FAMILY_FIRST_GIVEN_LAST` base, gave one table for a9dacf7d and for a sketch of this entry's rule: nothing in it showed either regression. The tool as this entry leaves it shows the four differences named above. - Not taken for 3.1, and not decided against: for a list mixing the two patronymic kinds, suggesting both rules where each has votes (`{EAST_SLAVIC, TURKIC}` reads `uz_senate` 54/59 against the 52/59 of the rule the larger set decides, the TURKIC table's columns), and reading the Kazakh `-uly` and `-kyzy` endings as a Turkic signal, which is a vocabulary and rules/O2 question before it is the suggester's. One patronymic decision is made for the list, by the thresholds: the larger set's rule where it clears them (`uz_senate`, 52 names against 2), none where neither set does (four East Slavic names beside three Turkic ones decide neither), as 2026-11-10 TURKIC recorded of the first case. -- **2026-11-15 #1357 — THE GIVEN-NAME TABLE'S FAMILY SHARE GOES FROM 5% TO 10%, AND NO LISTED SUFFIX OR TITLE ABBREVIATION IS A TABLE WORD; NO WIDER SURNAME TABLE FOR 3.1.** The table left out the commonest English given names, each written in ORCID's family box a little over 5% of the time (`david` 5.1%, `robert` 5.7%, `john` 7.1%), so a list of them cast no vote: `Smith John`, `Jones David`, `Brown James`, `Taylor Robert`, `Clark Thomas`, `Wilson Paul`, `Evans George`, `Walker Charles` was "no evidence" under every base. Decided: `MAX_FAMILY_SHARE` is 0.10, and the builder refuses every word the default lexicon compiles into `suffix_acronyms` or `suffix_words`, as it refuses a title, and every title it lists as an abbreviation (`title_abbreviations`). #1364's surname table is not taken for 3.1, and is open for 3.2. +- **2026-11-15 #1357 (its #1364 "open for 3.2" decided by 2026-11-19 #1364, which takes the ORCID mirror and holds the census table its gate measured) — THE GIVEN-NAME TABLE'S FAMILY SHARE GOES FROM 5% TO 10%, AND NO LISTED SUFFIX OR TITLE ABBREVIATION IS A TABLE WORD; NO WIDER SURNAME TABLE FOR 3.1.** The table left out the commonest English given names, each written in ORCID's family box a little over 5% of the time (`david` 5.1%, `robert` 5.7%, `john` 7.1%), so a list of them cast no vote: `Smith John`, `Jones David`, `Brown James`, `Taylor Robert`, `Clark Thomas`, `Wilson Paul`, `Evans George`, `Walker Charles` was "no evidence" under every base. Decided: `MAX_FAMILY_SHARE` is 0.10, and the builder refuses every word the default lexicon compiles into `suffix_acronyms` or `suffix_words`, as it refuses a title, and every title it lists as an abbreviation (`title_abbreviations`). #1364's surname table is not taken for 3.1, and is open for 3.2. - The suffix exclusion, and why the share needs it. At 10% the ranking admits `md` (typed in the given box 5,379 times, 4,935 of them first, Muhammad written short, 7.7% of its uses in the family box) and `ala`, `ei`, `ing` and `ed`, each a listed credential. A word the tables list is never read past as a post-nominal (`_suggest._a_listed_name`), so four invented names ending in a bare `MD` (`Zorvan Qelliot MD`) cast given-name votes that the given name is written last, and a default base was moved to `FAMILY_FIRST`. The exclusion reads the two suffix sets whole, the gated words included (`suffix_acronyms_ambiguous`, `suffix_words_ambiguous`, both subsets), which is wider than the title exclusion (it keeps `titles_ambiguous`). The reason for the gated words is not the one for `md`: the suggester does not read a gated word past at the end of a name, in the table or out of it (`suffix_as_written` leaves the gated sets out unless the word is written with its stops), but the parse reads one as the credential by the case it is written in, in capitals after a name word and in lower case after two (`Zorvan Qelliot ASA` and `Zorvan ASA`: suffix `ASA`; `Zorvan Qelliot Asa`: family `Asa`), and as a table word it voted there that the given name is written last. On 0d643d2b four such names ending in `ASA` moved a default base to `FAMILY_FIRST`, `asa` and `ace` being in the table; they cast no vote now. The cost is the six gated words as given names: `ace`, `ala`, `asa`, `ed` and `ei`, and `ing`, which is `Ing.`, the title, typed into the given box. The generation, credential, honorific and agnomen kinds are all inside the two sets (checked on the default lexicon, 2026-11-15). It also removes the four listed suffixes the 5% table held, `mst`, `cem`, `asa` and `ace`, which 2026-11-12 GIVEN NAMES FROM ORCID had kept. - What the table holds (2026-11-15, `tools/vocab/order_names.py` over the `orcid-researchers` cache: ORCID's public data file dated 2025-10-17, fetched 2026-10-27, 1,831,533 records, sha256 `b95ffd683d03d44c80260dff55a0dc7e1224bdeaedfc6eee6e9015d41b2ca6d2` in its `meta.json`): 8,026 names, from 6,409; 1,668 enter and 51 leave. Of the 51, 47 are rare names pushed out of a country's 500 by the names entering above them, and four are the suffixes. The table equals the same build without the two exclusions less ten words: `md`, `ala`, `ei`, `ing`, `ed`, `mst`, `cem`, `asa`, `ace`, and `gen`. No entered word has a family share over 10% by construction; `mohamed` (24.6%), `ahmed` (31.8%) and `ali` (35.0%) stay out, while `muhammad` (9.0%) and `mohammad` (7.6%) enter. Still out: `james` 10.3%, `jean` 10.7%, `paul` 11.3%, `charles` 12.3%, `george` 12.7%, `thomas` 15.8%, `martin` 19.6%. - The title abbreviations. `gen` (35 uses in the given box, 7.9% of its uses in the family box) entered at 10%, being in `titles_ambiguous`, which the title exclusion keeps. But the lexicon lists it as an abbreviation, and written with its full stop the parse reads it as the title at either end of a name: four names written `Zorvan Qelliot Gen.` moved a default base to `FAMILY_FIRST` on the first build of this entry, and four written `Gen. Zorvan Qelliot` moved a `FAMILY_FIRST` base to `GIVEN_FIRST` (the code review of b6791db7). The builder refuses `title_abbreviations` (`brig`, `gen`, `hon`, `maj` on 2026-11-15), which removes `gen` and nothing else; a test parses every table word in capitals and in Title case, with and without a full stop at the end of a name and without one at its head, and finds no title and no suffix. The head spelling with a full stop is left out of that test: by rules/H2's shape the parse reads 7,976 of the 8,026 table words as a title there (`Aaron. Zorvan Qelliot`; the rest are hyphenated or apostrophed words and `muh`, a given name written short), and the suggester, which does not read a word of that shape past, votes on it all the same, on 0d643d2b as now: four names so written move a `FAMILY_FIRST` base to `GIVEN_FIRST`. That gap is every table word's, is older than this entry and has no issue. What sets `gen` apart is the end of a name, where rules/H5 reads `Gen.` as a title by vocabulary as it reads no other table word, and that `Gen. Qelliot` is a writing people use where `Aaron. Qelliot` is not. @@ -449,7 +449,7 @@ Open: the other three settings count their shares among the names with evidence - The eight that never settle: `orcid-givcaps`' four rows and `orcid-byline-joined` written given first under a family-first base, the kinds docs/suggest.rst's "Where it stops" names; `orcid-byline` written given first under a family-first base, which reads 57% at 200 names and 99% only at 2,000, the one row a longer list kept helping; and `pv-RU-patronymic` written family first, both rows. The two that settle at 500 are the same-order rows `orcid-byline` (99% at 200) and `orcid-byline-joined` (94 / 92 / 96% at 50 / 100 / 200, its 100-name cell a size no earlier table printed, and its 500 a draw from a population of 644), each written given first under a given-first base. - `pv-RU-patronymic` written family first under a family-first base, a same-order row, reads 100 / 100 / 100 / 100 / 99 / 100 / 94 / 84 / 88% at those sizes: under 95% from 500 names, where every earlier table stopped at 200. About 3 of its names in 1,000 cast a wrong given-name vote (a surname that is also a given name, written first) and about 1 in 1,000 a right order vote, from the capitals and surname signals (the given-name signal casts no right vote there), and `_MIN_VOTES` and `_MIN_SHARE` count only the names that voted, so two stray votes decide a list of any length. #1442 holds the reproduction with made-up names and what a fix has to keep; one run of 200 groups a size, so 84% and 88% are not told apart. - Decided for the docs: the user page advises a sample of a few hundred names per source, which is true before and after any fix to #1442. Not decided: a floor on votes as a share of the whole list. -- **2026-11-16 ORDER FLOOR — AN ORDER NEEDS ITS VOTES TO BE AT LEAST 1% OF THE GROUP, NOT ONLY OF THE NAMES THAT VOTE.** Settles [#1442](https://github.com/derek73/python-nameparser/issues/1442). `_MIN_VOTES` and `_MIN_SHARE` counted only the names casting an order vote, so in a long list where almost no name votes, two stray votes decided the order for every name (2026-11-16 #1442 above: `pv-RU-patronymic` written family first under a family-first base, 87% at 1,000 and 2,000 names). +- **2026-11-16 ORDER FLOOR (its sizes from which a row written against its base is read right, and `orcid-byline`'s given-first row, superseded by 2026-11-19 #1364 for the populations its table moves: 500 names for `orcid-byline` written given first under a family-first base, 100 for `orcid-byline-joined` written family first under a given-first base, and `orcid-byline` written given first under a given-first base 99.0 / 98.7 / 100% at 50 / 100 / 200 names, no longer an exception) — AN ORDER NEEDS ITS VOTES TO BE AT LEAST 1% OF THE GROUP, NOT ONLY OF THE NAMES THAT VOTE.** Settles [#1442](https://github.com/derek73/python-nameparser/issues/1442). `_MIN_VOTES` and `_MIN_SHARE` counted only the names casting an order vote, so in a long list where almost no name votes, two stray votes decided the order for every name (2026-11-16 #1442 above: `pv-RU-patronymic` written family first under a family-first base, 87% at 1,000 and 2,000 names). - Decided: `_suggest._MIN_ORDER_GROUP_SHARE = 0.01`. The names voting for the winning end must also be at least 1% of the group's names, voting or not, save the names a comma left out (`_Tally.winner`). The order evidence's note says how many names voted for which end and why that is too few where the floor alone leaves the order undecided, and where the votes it holds back are for family-first against the given-first order a decided East Slavic rule sets; where they are for the rule's own given-first order the note says nothing of them, since they decided nothing (found by the review of 66c827d9, whose note named the held-back votes beside an order the rule had decided). - The denominator leaves out the names a comma left out (`_comma_note`) because a comma name states its own order and the order decided reads none of them: 199 `Smith, John` with `Smith Mary` and `Kim Minjun` decide family-first on the two names the order reads, where a whole-list denominator (66c827d9) held them back as 2 of 201. Re-measured after the change with the same command: no cell of any table and no parliament suggestion moves, the one parliament list holding comma names, `in_sansad` (373 of its 8,295), deciding given-first on 1,068 votes, far over 1% either way. - What the floor changes beside a decided East Slavic rule, pinned by tests (`test_strays_against_the_rules_order_no_longer_decide_it`): ten names written given, patronymic, family (`Qqsan Petrovich Zzyvova`) with `Smith Mary` and `Kim Minjun` among 1,000 silent names decided family-first on master under a given-first base and under `FAMILY_FIRST` (the two strays outvoting nothing), under which the rule reorders no name, and now get the rule's given-first order; under `FAMILY_FIRST_GIVEN_LAST` the same with the patronymic written last (`Zzyvova Qqsan Petrovich`), where master kept that order and its reading of the patronymic as the given name. This is the one place the floor moves an outcome toward an order rather than toward the base, and it moves it to the order the patronymics carry. `_keeps_family_first` reads the same winner, so a held-back stray order under a `FAMILY_FIRST` base whose patronymics are written last falls to #1356's branch: the base keeps its order and gets the rule alone. @@ -501,3 +501,23 @@ Open: the other three settings count their shares among the names with evidence - `orcid-byline-joined` written given first under a given-first base, every cell of the 300-trial run (2 / 3 / 4 / 5 / 10 / 20 / 50 / 100 / 200 / 500 names; it holds 644): 100.0 / 100.0 / 100.0 / 99.7 / 99.7 / 98.3 / 94.7 / 93.3 / 97.3 / 100.0%, identical with and without the floor. Its 200-name cell is 0.3 points over 97%, and two other runs read it 96% (#1442's entry above, 200 trials, and the review's of 66c827d9, 100 trials), so "at least 97% at every size but 50 and 100" in `Parser.suggest`'s docstring rests on this run alone and is within a group or two of failing it. - The same-order cells under 97%, exactly, outside `orcid-givcaps` (whose rows fail at every size from 2, as 2026-11-12 CAPITALS records): `orcid-byline-joined` written given first under a given-first base, 94.7% and 93.3% at 50 and 100 names, the lowest same-order cells of a population other than `orcid-givcaps`, so docs/suggest.rst's "just under 95% of groups of 50" holds and gains the 100; `orcid-byline` written the same way, 95.3% and 96.7% at 100 and 200 (97.0% at 50), which `Parser.suggest`'s docstring and docs/suggest.rst had as "at least 97%" from tables that printed no 100 and rounded the 200. #1442's entry above read the first 92% at 100 names on 200 trials. - The docs: docs/suggest.rst's advice to give a sample of a few hundred names stands, for speed and because more rarely helps. It says the order's own votes are not read worse in a long list, scoped to the lists measured, and that a handful of names can still decide the other three settings in one (the bullet above on them); its deciding table and the order paragraph state the floor. +- **2026-11-19 #1364 — A SECOND SURNAME TABLE, ORCID'S FAMILY-BOX WORDS ITS HOLDERS RARELY TYPE AS A GIVEN NAME, VOTES WITH THE ROMANIZED ONE; ITS GIVEN-BOX SHARE IS 5%.** Decided in [#1364](https://github.com/derek73/python-nameparser/issues/1364) on 2026-11-19: option (B), the ORCID mirror of the given-name table, Spanish first because that is what the recipe gives, private to the suggester, its size whatever the recipe yields at the measured cutoff, and a looser share of about 12% measured for Portuguese surnames; a census-derived table for English (option A) is held until a real list written family first without commas is found, the example in the issue being constructed. Decided here, by the measurement below: the share is 5%, and a `FAMILY_FIRST_GIVEN_LAST` base gets `FAMILY_FIRST` where a decided East Slavic rule meets a family-first order the names' votes decide. + - The recipe, `tools/vocab/order_names.py`'s `common_surnames`: every word ORCID's holders typed in the family-name box 100 times or more (`MIN_SURNAME_USES`), anywhere in the box, and in the given-name box in at most 5% of the times they typed it in either (`MAX_GIVEN_SHARE`), with two or more letters and no full stop, counted under the spelling the suggester looks it up by (`spelling`, the given names' fold), with no ranking per country (a holder's stated country says where they work, not where a surname is from). `surname_refusals` then leaves out the romanized surnames and the given names the same run writes (so no word is in two tables, which `check_tables` refuses), the titles and suffixes the given names refuse, and `listed_name_pieces`: the default lexicon's particles, conjunctions, bound given names, maiden markers and its Hangul surnames, which the parse reads by their script (rules/W1, rules/W4) and which the suggester's tables hold none of; `load_common_surnames` leaves out a Turkic patronymic marker. A floor of 400 (`MIN_SURNAMES`) refuses a cut input. + - What it gives (2026-11-19, over the `orcid-researchers` cache: ORCID's public data file dated 2025-10-17, fetched 2026-10-27, 1,831,533 records, sha256 `b95ffd683d03d44c80260dff55a0dc7e1224bdeaedfc6eee6e9015d41b2ca6d2` in its `meta.json`): 1,812 family words reach the floor, 1,783 of them with two or more letters and no full stop; 578 of them have a given-box share of 5% or less; 14 of those are romanized surnames and none a given name, leaving 564; the refusals remove five (`den`, `der`, particles; `김`, `이`, the Hangul surnames; `кызы`, a Turkic marker), and the table holds 559. The issue's figures, 1,776, 578 and 565, were taken on 2026-11-12 under an earlier spelling and given-name table; the two counts that differ were not traced word by word. The 25 commonest are Spanish (`rodriguez`, `gonzalez`, `garcia`, `lopez`, `perez`, …); beside them Serbian and Croatian (`jovanovic`, `horvat`), Azerbaijani and Bulgarian (`mammadov`, `georgieva`), Arabic (`alshammari`), Persian (`hosseini`), Japanese (`sato`, `suzuki`), Nepali (`paudel`, `shrestha`), Indian (`banerjee`, `mukherjee`), Danish and Swedish (`jensen`, `nilsson`), German (`schmidt`, `mvller`, Müller under the fold's `ü`) and English and Irish (`moore`, `white`, `hall`, `cooper`, `murphy`). The title and suffix refusals remove nothing at 5%; at 12% they remove `phd`, `caro`, `neto` and `filho`, and the particle refusal `von`, `ait` and `abou` too. Recompute: `uv run python tools/vocab/order_names.py` prints the block. + - The vote: the table joins the romanized one as `SURNAMES`, read by the one surname signal under its rules: a listed word at one end of a name and not at the other votes that the family is written at that end, a name listed at both ends from either table votes nothing (`García Quispe`, `Wang García`), a one-letter word is never looked up, a name opening in two or three capitals casts no surname vote (2026-11-14 #1355: `AM García`) and a listed short capitals word ending one silences it (2026-11-14 #1397, now read from both tables: `Zorvan LYU`, `lyu` being the one table word of three letters or fewer). `_a_listed_name` reads both, so a listed surname is never read past as a title (`García. Zorvan`, which rules/H2's shape reads as a title at the head). No word of the table is a title or a suffix by the parse's own reading at either end of a name, which a test holds as it holds the given names. No new `Signal`: the evidence is the same kind, a surname at one end. + - Found by the code review of the first build, a regression master did not have: five Latin-script Russian names written family first with their patronymics (`Popov Ivan Ivanovich`, three of five family names listed) under a `FAMILY_FIRST_GIVEN_LAST` base got the East Slavic rule and kept that base, the names' family-first votes deciding the order, which the rule never overrides (2026-11-10 FIX WAVE); that order reads the patronymic as the given name, so all five read given `Ivanovich`, where master, its names casting no order vote, gave them the rule's given-first order and read them right. Decided: where the rule is decided and the votes decide family-first, a `FAMILY_FIRST_GIVEN_LAST` base gets `FAMILY_FIRST`, which reads the names as written. That holds where `capitals_as_family` is on too: the switch reads only a name with its family in capitals (rules/O9), so under it the given-last order still read every other name's patronymic as its given name. The first fix kept that order wherever the switch was on, suggested or the base's, and the review of the fix found a base with the switch on reading five mixed-case names `Popov Ivan Ivanovich` 0 of 5 (master 5 of 5), and a list in capitals but for one name losing that one; `FAMILY_FIRST` reads every name right in each case, capitals or not, so the switch changes nothing here. 2026-11-15 #1356's case of five names with the family in capitals under the given-last base (`QQSIDOROV Zzyvan Petrovich`; `test_the_rule_comes_with_capitals_as_family_under_a_given_last_base`) now gets `FAMILY_FIRST` in its patch, reading as before. The tool's draws run under two bases and its parliament lists, the only patronymic lists it holds under `FAMILY_FIRST_GIVEN_LAST`, are Cyrillic, which the table does not hold (`Попов` folds to `попов`), so no table of the tool showed it. + - New populations in `tools/differential/suggest_measure.py`: PSC's Filipino, Portuguese, Bangladeshi, Pakistani and Brazilian filers, and PatentsView's Mexican, Argentine, Colombian, Philippine, Portuguese and Turkish inventors; `pv-surname-given`, the inventors of those countries less China, Taiwan, Korea and Japan whose given box opens with a word PatentsView's own boxes write in the family box at least as often (by 20 inventors or more in the given box, the two spellings of a word counted together under the suggester's fold), less a romanized surname (`Lee`, whose cost is as old as its table); and `pv-listed-given`, the same inventors whose given box opens with a word of the new table. Both leave out a record whose family box opens with a listed given name (`Diaz` given, `Angel` family: boxes likely swapped) and read the tables from the tool's own checkout, so a `--base` run draws them alike (found by the silent-failure review). + - Measured with the branch's `tools/differential/suggest_measure.py`, one run per arm, each written with `--json ` and the files compared cell by cell: master as `--tree `, the 5% table as the branch itself (no `--tree`), and the 12% table as `--tree `; `--tree` measures the named checkout with the script's own populations, which is what `--base` does for its base, so the three arms draw the same groups. Each with `--wrong-words 12` at the default sizes (2 / 3 / 4 / 5 / 10 / 20 / 50 / 200), then with `--sizes 2,3,4,5,10,20,50,100,200,500,1000,2000` (the bullet below); 300 groups a size, seed 20261110. The runs were taken before the review of the fix dropped its `capitals_as_family` exception (above), which moves no row: the draws run under the two bases without it, and every parliament list's suggestion under `FAMILY_FIRST_GIVEN_LAST` is the same with and without it (2026-11-19). 2026-11-19. + - Same-order rows, the anti-goal: at 5% the lowest cells outside the standing exceptions are 99.0% or more (PatentsView's Mexican, Spanish, Colombian and Philippine inventors written family first under a family-first base each lose one or two groups in 300 at one size); `orcid-byline-joined` and `orcid-givcaps` read as before. At 12% they reach 98.0% (PatentsView's Brazilian inventors) and 98.3% (PSC's Brazilian filers, PatentsView's Portuguese inventors). `pv-listed-given` fails both rows at every size from 2 under either table, 0% at 5 names and more at 5%: a list of nothing but given names the table lists as surnames, 606 names, three quarters of them US inventors named `Clarke` (65), `Cooper` (56), `Burke` (54), `Murphy` (32), `Hughes` (28), `Turner` (25), `Hall` (14), `Wright` (13), the rest Spanish surnames typed into the given box (`Moreno` 49). This is the cost the issue's option text accepted ("a surname that is a given name in another language"), a constructed worst case; in the lists that hold such names among others it does not show: PatentsView's US inventors written given first cast 13 wrong surname votes in 3,000 names on master and 13 at 5%, and their same-order rows read 100%. + - Spanish-language lists written family first under a given-first base, at 2 / 3 / 4 / 5 names, master → 5% → 12%: PSC's Spanish filers 35 / 58 / 82 / 84% → 44 / 68 / 86 / 90% → 45 / 71 / 87 / 91%; PatentsView's Spanish inventors 36 / 63 / 78 / 85% → 49 / 71 / 84 / 90% → 50 / 72 / 84 / 90%; Mexican 31 / 52 / 73 / 84% → 47 / 66 / 80 / 90% → 48 / 69 / 84 / 93%; Colombian 40 / 75 / 83 / 94% → 59 / 83 / 88 / 93% → 62 / 85 / 90 / 97%; Argentine 40 / 69 / 85 / 94% → 46 / 74 / 87 / 94% (12% the same within a point). Written given first under a family-first base: PSC's Spanish 46 / 80 / 90 / 94% → 55 / 87 / 93 / 96%; Mexican 62 / 89 / 99 / 99% → 74 / 94 / 100 / 100%. + - Portuguese and Brazilian lists: at 5% within a point or two of master everywhere. PSC's Brazilian and Portuguese filers written family first under a given-first base sit within two points of 95% at 10 names, on one side or the other by run: Brazilian 96.0% → 94.7% in the default-size run and 97.7% → 96.7% in the long one, Portuguese 95.3% → 94.0% in the long one, so the size from which each reaches 95% (10 or 20 names) is not settled by 300 groups. At 12%, written given first under a family-first base they rise (PSC's Brazilian 41 / 74 / 79 / 90% → 63 / 89 / 94 / 99% at 2 to 5; PatentsView's Brazilian 52 / 75 / 89 / 96% → 66 / 86 / 95 / 99%; PSC's Portuguese 42 / 71 / 85 / 93% → 55 / 82 / 93 / 95%), and written family first under a given-first base they fall at 10 and 20 names (PatentsView's Brazilian 86 / 98% → 82 / 90%, so from 50 names, not 20; PSC's Brazilian 96 / 100% → 88 / 97%; PSC's Portuguese 99% → 94% at 10, from 20 names, not 10). + - Why the family-first rows of these lists lose: PatentsView's and PSC's boxes hold the first of two surnames in the given box (`Ismael Ortiz` given, `Ramirez` family; 952 of PatentsView's Mexican inventors' given boxes end in a word of the 5% table), so the tool's family-first writing is `Ramirez Ismael Ortiz`, which no list writes, and the listed `Ortiz` votes against it. A Portuguese given box holds the mother's surname the same way (`Silva João Santos`), and the 12% table lists the commonest of them. The wrong votes are an artifact of composing the writing from these boxes; that it is no real list's writing is reasoning, not a measurement, so the 12% figures are recorded as measured. + - Lists outside the table's languages move within a point at 5%, mostly up: PSC's Indian, Nigerian, Turkish, Bangladeshi and Pakistani filers and PatentsView's Indian and Turkish inventors (PSC's Indian written family first under a given-first base 22 / 58% → 23 / 58% at 5 and 10 names). Japanese lists rise (PatentsView's, written given first under a family-first base, 69 / 94% → 74 / 96% at 5 and 10 names), and reach 95% from 10 names, not 20, as PSC's Filipino filers do. At 12% the Indian lists rise further (`sharma`, `patel`, `gupta`, `mishra` enter): PSC's Indian written family first under a given-first base 22 / 58% → 35 / 75%. + - Per name, every population and both writings, `pv-listed-given` apart (237,268 names): the surname signal's right votes 26,339 → 37,881 at 5% (+11,542) and → 50,283 at 12% (+23,944); its wrong votes 1,192 → 1,807 (+615, 5.1% of the added votes) and → 2,748 (+1,556, 6.1%). + - Parliaments: the order counts of twelve lists move at 5% (`in_sansad` 1,068 for and 138 against to 1,110 and 139; `pt_parliament` 959 and 2 to 968 and 2) and fourteen at 12%; no list's order, rule or capitals decision moves under any of the three bases at either share, and the TURKIC table is unchanged. + - Whole names, given and family against the boxes (a script of the session's, outside the tree: 100 groups a size of 2, 5 and 20, 21 populations, each written both ways under each of the three bases): every same-order cell at 5% within 1.0 point of master, `pv-listed-given` apart; at 12% within 2.5 points (PatentsView's Portuguese inventors written family first under a family-first base, 52.0% → 49.5% at 2 names). + - Read from 2 to 2,000 names (`--sizes 2,3,4,5,10,20,50,100,200,500,1000,2000 --trials 300`), the size from which each row written against its base is read right in 95% of groups, master → 5% → 12%, where any moves: `orcid-byline` written given first under a family-first base 2,000 → 500 → 200, and written family first under a given-first base 50 → 50 → 20; `orcid-byline-joined` written family first under a given-first base 200 → 100 → 50; PSC's Filipino filers written given first under a family-first base 20 → 10 → 10; PSC's Romanian filers written family first under a given-first base 20 → 10 → 10; PSC's Spanish filers written given first under a family-first base 10 → 5 → 5; PatentsView's Argentine inventors written family first under a given-first base 10 → 5 → 5; Japanese both ways 20 → 10 → 10; Taiwanese written family first under a given-first base 5 → 4 → 4; Colombian written given first under a family-first base 4 → 3 → 3; `pv-surname-given` written family first under a given-first base 100 → 50 → 50, and written given first under a family-first base 100 → 100 → 200; Brazilian and Portuguese written family first under a given-first base as the bullet above says (PatentsView's Brazilian 20 → 20 → 50, PSC's Brazilian and Portuguese 10 → 10 or 20 → 20); the rest move at 12% alone, each earlier: PatentsView's Colombian inventors written family first under a given-first base 10 → 4, Brazilian, Portuguese and Mexican lists written given first under a family-first base a size earlier (PSC's Brazilian and Portuguese 10 → 5), and `pv-RU-patronymic` written family first under a given-first base, read right at no size on master and at 5%, from 1,000 names. The slowest kinds are PSC's Bangladeshi filers (200 names) and PatentsView's Philippine inventors (100), both new populations and both the same on master. Same-order rows: at 5% none under 99.0% outside the standing exceptions; `orcid-byline` written given first under a given-first base 97.0 / 95.3 / 96.7% at 50 / 100 / 200 names on master and 99.0 / 98.7 / 100% at 5%; `orcid-byline-joined` 94.7 / 93.3% at 50 / 100 names, the same as master, and 95.0 / 94.7% at 12%; at 12% the lowest outside the exceptions is 98.0% (PatentsView's Brazilian inventors written family first under a family-first base, at 2 and 4 names). + - The harness proof (`--set _MIN_VOTES=1000000 --set _MIN_PATRONYMIC_VOTES=1000000 --set _MIN_RUN_NAMES=1000000`, on the branch): each of the 86 rows written against its base reads 0%, each of the 86 written in it 100%, and no parliament list's order is decided. + - 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. diff --git a/docs/getting-started.rst b/docs/getting-started.rst index e69c90f87..de3f1b01b 100644 --- a/docs/getting-started.rst +++ b/docs/getting-started.rst @@ -114,7 +114,7 @@ it, and ``suggestion.base`` is the parser you started from: >>> print(suggestion) Suggested for 5 names (base: Parser(Lexicon(default), Policy())): name_order FAMILY_FIRST 4 for, 0 against, 1 no evidence - surname FAMILY_FIRST 3 + surname FAMILY_FIRST 4 given-name FAMILY_FIRST 2 patronymic_rules unchanged (none) no evidence initials_as_family unchanged (False) no evidence @@ -125,10 +125,10 @@ parser has: all five names are in mixed case with no word in capitals, so they are evidence for leaving ``capitals_as_family`` off. Four names vote for family first: ``Kim``, ``Wang`` and ``Nguyen`` by -the romanized surname in front, ``Garcia Emily`` by the common given -name at the end (``Garcia`` is not one of the surnames ``suggest`` -reads). ``Wang Xiaoming`` carries both kinds, so the surname and -given-name rows count it once each. +the common surname in front, ``Garcia Emily`` by the surname in front +and the common given name at the end. ``Wang Xiaoming`` and ``Garcia +Emily`` carry both kinds, so the surname and given-name rows count each +of them once. ``Taylor Morgan`` gives no evidence, so the suggested parser reads it family first only because the rest of the list is written that way; @@ -140,9 +140,10 @@ disagrees `). What ``suggest`` decides ~~~~~~~~~~~~~~~~~~~~~~~~ -The evidence is in the names themselves: a common romanized Chinese, -Korean or Vietnamese surname, or a common given name that is rarely -a surname (``Mary``, not ``James``), at one end; a +The evidence is in the names themselves: a common surname (a +romanized Chinese, Korean or Vietnamese one, or one rarely written as +a given name, ``Garcia``), or a common given name that is rarely a +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`). diff --git a/docs/release_log.rst b/docs/release_log.rst index 633ed4df4..75a2e367b 100644 --- a/docs/release_log.rst +++ b/docs/release_log.rst @@ -4,6 +4,7 @@ Release Log nameparser 3.2 is under development. + - **Change Parser.suggest() to read common surnames beyond the Chinese, Korean and Vietnamese ones, most of them Spanish.** ``Parser().suggest(["García Zorvan", "Quispe Qelliot"]).patch`` gives ``PolicyPatch(name_order=FAMILY_FIRST)``, where 3.1.0 found no evidence in either name and suggested nothing; a list of two to five Spanish names written family first now moves a given-first parser more often. :issue:`1364` - **Fix Malaysian a/l, a/p and anak, which read as middle names and cut the father's name.** ``parse("KUMAR A/L RAJAN NAIDU")`` gives family ``A/L RAJAN NAIDU`` and the same ``patronymic``, as ``bin`` reads, where 1.4.0 through 3.1.0 gave middle ``A/L RAJAN``, family ``NAIDU``; ``anak`` opening a name written without a comma (Balinese ``Anak Agung``) is left to position, the given name by default, and reported. :issue:`1468` - **Fix Dutch Oude, which read as a middle name.** ``parse("Piet Oude Luttikhuis")`` gives family ``Oude Luttikhuis``, where 1.4.0 through 3.1.0 gave middle ``Oude``, family ``Luttikhuis``; ``Oude`` opening a name stays the given name, reported, being a rare Dutch given name too. :issue:`1455` - **Add locales.NL, which reads ten as a family-name particle.** ``parser_for(locales.NL).parse("Jan ten Brink")`` gives family ``ten Brink``, where the default, as 1.4.0 through 3.1.0, gives middle ``ten``; a ``Ten`` opening a name stays the given name, reported, save under ``strict=True``. It also takes a Chinese given-name syllable inside a name into the family (``Kheng Ten Choo`` gives family ``Ten Choo``), and choosing Dutch reads ``VD`` as ``van der`` rather than the credential (``John Smith, VD`` gives family ``John Smith VD``). See :ref:`dutch-particles`. :issue:`1455` diff --git a/docs/suggest.rst b/docs/suggest.rst index a4f8e3e9c..690cfbed0 100644 --- a/docs/suggest.rst +++ b/docs/suggest.rst @@ -28,9 +28,9 @@ the settings its names agree on, and a parser that reads with them. 'Morgan' Four names vote for family first: ``Kim``, ``Wang`` and ``Nguyen`` by -the romanized surname in front, ``Garcia Emily`` by the common given -name at the end; ``Wang Xiaoming`` carries both, so each signal's row -counts it. ``Taylor Morgan`` gives no evidence: it is read family +the common surname in front, ``Garcia Emily`` by the surname in front +and the common given name at the end; ``Wang Xiaoming`` and ``Garcia +Emily`` carry both, so each signal's row counts them. ``Taylor Morgan`` gives no evidence: it is read family first because the list is, and nothing in the name can confirm that. Each name votes on its order from the evidence it carries @@ -113,7 +113,7 @@ the names that disagree with it: >>> print(suggestion) Suggested for 5 names (base: Parser(Lexicon(default), Policy())): name_order FAMILY_FIRST 4 for, 0 against, 1 no evidence - surname FAMILY_FIRST 3 + surname FAMILY_FIRST 4 given-name FAMILY_FIRST 2 patronymic_rules unchanged (none) no evidence initials_as_family unchanged (False) no evidence @@ -179,7 +179,7 @@ The report counts it as ``against`` and names it on its last line: >>> print(mixed) Suggested for 6 names (base: Parser(Lexicon(default), Policy())): name_order FAMILY_FIRST 4 for, 1 against, 1 no evidence - surname FAMILY_FIRST 3 + surname FAMILY_FIRST 4 given-name FAMILY_FIRST 2 given-name GIVEN_FIRST 1 patronymic_rules unchanged (none) no evidence @@ -249,7 +249,7 @@ A setting whose votes fall short of its threshold above keeps the base parser's value rather than a guess, whatever the other settings decide. Where every setting falls short, or no name in the list carries evidence, the patch is empty. None of these -names holds a romanized surname, a given name that is rarely a +names holds a listed surname, a given name that is rarely a surname, or any other evidence on the order: .. doctest:: @@ -310,8 +310,11 @@ Each name votes on its order from the evidence it carries: of bylines may get no order suggestion: where you know a list is bylines, set ``name_order=FAMILY_FIRST`` yourself. - **A lowercase particle** first or before the last word. -- **A common romanized Chinese, Korean or Vietnamese surname** as the - first or last word. +- **A common surname** as the first or last word: a romanized + Chinese, Korean or Vietnamese one, or one that researchers rarely + write as a given name (``García``, ``Quispe``, ``Popov``), most of + them Spanish. A name with a listed surname at both ends casts no + surname vote. - **A common given name that is rarely a surname** (``Emily``, not ``Taylor``) as the first or last word. @@ -407,7 +410,9 @@ The names' own order votes come before the table in two cases: - **They decide a family-first order.** The rule never overrides it: the list gets the rule with that order, under which the rule - reorders no name. + reorders no name. A ``FAMILY_FIRST_GIVEN_LAST`` base gets + ``FAMILY_FIRST`` there, since its own order would read the + patronymic as the given name (``Popov Ivan Ivanovich``). - **They decide given-first under a** ``FAMILY_FIRST`` **base.** The second row does not apply, and the list gets ``GIVEN_FIRST`` with the rule. @@ -657,14 +662,14 @@ and how it varies, and will differ for every dataset. - **A list written in the base's own order** keeps it in at least 95% of groups from 2 to 2,000 names, and 97% for nearly every kind, save - the two kinds of list below. + the three kinds of list below. - **A list written the other way round** takes more names to move the base, from 5 for Chinese, Taiwanese, Korean, Czech, Polish and - Italian names to 50 for Russian and Indian ones. A group whose votes - fall short of the thresholds keeps the base rather than guess - (:ref:`suggest-deciding`). + Italian names to 50 for Russian and Indian ones and 200 for + Bangladeshi ones. A group whose votes fall short of the thresholds + keeps the base rather than guess (:ref:`suggest-deciding`). -Two kinds of list keep their order less often: +Three kinds of list keep their order less often: - **Given names in capitals** (``ANNA Smith``) have their capitals read as a family name, and such a list is suggested ``capitals_as_family`` @@ -677,6 +682,10 @@ Two kinds of list keep their order less often: but two or three joined initials (``AM Hoy``) kept it in just under 95% of groups of 50 and 93% of groups of 100. Where you know how such a list is written, set ``name_order`` yourself. +- **Given names that are common surnames elsewhere** (``Cooper``, + ``Burke``, ``Moreno``) are read as surnames. A list of nothing but + such given names is read the wrong way round; mixed into a longer + list, they are outvoted. ``capitals_as_family`` was suggested in at least 95% of groups from 4 names for researchers who typed their family name in capitals, and diff --git a/nameparser/_parser.py b/nameparser/_parser.py index ff82edecb..9c7a7e328 100644 --- a/nameparser/_parser.py +++ b/nameparser/_parser.py @@ -348,16 +348,19 @@ def suggest(self, names: Iterable[str]) -> Suggestion: A group decided East Slavic gets the rule and reads given-first, the order the rule reorders each name under, unless its names' own votes decide family-first, which the rule - never overrides. One case keeps a declared order instead: under - a ``FAMILY_FIRST`` parser whose names' votes do not decide + never overrides: there a ``FAMILY_FIRST_GIVEN_LAST`` parser gets + ``FAMILY_FIRST``, under which the patronymic is not read as the + given name (``Popov Ivan Ivanovich``). One case keeps a + declared order instead: under a ``FAMILY_FIRST`` parser whose names' votes do not decide given-first, where more of the names carrying the patronymic write it last (``Sidorov Ivan Petrovich``) than in the middle (``Ivan Petrovich Sidorov``), the group keeps that order and gets the rule alone, which reorders no name there and fills the ``patronymic`` view; the names written the other way get no given-first order, and the patronymic evidence's note counts - them. A tie, and a ``FAMILY_FIRST_GIVEN_LAST`` parser, - get the given-first order with the rule. A Turkic group + them. A tie, and a ``FAMILY_FIRST_GIVEN_LAST`` parser whose + names' votes do not decide family-first, get the given-first + order with the rule. A Turkic group gets the rule alone, its order decided by its names' own votes. ``initials_as_family`` (rules/O8) is turned on where one run of letters ends at least two names and at least half of the names @@ -388,11 +391,11 @@ def suggest(self, names: Iterable[str]) -> Suggestion: bare str, bytes, a mapping or a non-str item raises TypeError. Measured 2026-11-10, re-taken 2026-11-11, 2026-11-12, - 2026-11-14, 2026-11-15 and 2026-11-16, with + 2026-11-14, 2026-11-15, 2026-11-16 and 2026-11-19, with tools/differential/suggest_measure.py on groups drawn from real names written in a known order, 300 groups a size - (decisions/group-suggestion's 2026-11-16 ORDER FLOOR entry holds - the table): a group written in this parser's own order kept it + (decisions/group-suggestion's 2026-11-19 #1364 entry holds + the sizes): a group written in this parser's own order kept it in at least 97% of groups at every size from 2 to 2,000 names, under either base order, save three lists. ORCID holders who typed their given name in capitals (``ANNA Smith``), which the @@ -403,19 +406,22 @@ def suggest(self, names: Iterable[str]) -> Suggestion: (``AM Hoy``) kept it in at least 97% of groups at every size measured, to 500 names (it holds 644), but 50 and 100 names, where it kept it in 94.7% and 93.3%, the name tables voting on - a few of its names; ORCID's bylines of - every writing kept it in 95.3% and 96.7% at 100 and 200 names - and at least 97% at every other size. + a few of its names. And a list of nothing but given names that + ORCID's holders type as surnames (``Cooper``, ``Burke``) fell + below 95% at every size and was read wrong in every group from + 5 names, the surname table voting on each of them (that file's + 2026-11-19 #1364 entry). Moving the base takes more names, and how many depends on what the names carry: groups of Chinese, Taiwanese, Korean, Czech, Polish or Italian names (the romanized surnames and the common given names) were read right in 95% of groups from 5 names; German, Dutch, Spanish, British, French, - Romanian and Vietnamese from 10; US, Japanese, Turkish, - Nigerian and Brazilian from 20; and Russian and Indian from - 50. A group whose votes fall short of the thresholds keeps - the base rather than guess, so a smaller group moves it in fewer - of the draws. ``capitals_as_family``, measured 2026-11-12 + Romanian, Vietnamese and Japanese from 10; US, Turkish, + Nigerian and Brazilian from 20; Russian and Indian from 50; + PatentsView's Philippine inventors from 100; and PSC's + Bangladeshi filers from 200. A group whose votes fall short of + the thresholds keeps the base rather than guess, so a smaller + group moves it in fewer of the draws. ``capitals_as_family``, measured 2026-11-12 (decisions/group-suggestion's CAPITALS entry): ORCID holders who typed their family name in capitals were suggested it in at least 95% of groups from 4 names, and from 10 where many of the diff --git a/nameparser/_suggest.py b/nameparser/_suggest.py index 89fc0ea1e..dd053a395 100644 --- a/nameparser/_suggest.py +++ b/nameparser/_suggest.py @@ -34,7 +34,8 @@ decided East Slavic rule reorders each name itself, and reorders none under a family-first order, so it decides the order as given-first, unless the names' own votes decide family-first, which it never -overrides, or the base reads ``FAMILY_FIRST`` and the patronymics are +overrides (a ``FAMILY_FIRST_GIVEN_LAST`` base then gets ``FAMILY_FIRST``), +or the base reads ``FAMILY_FIRST`` and the patronymics are mostly written last, whose order it keeps (decisions/group-suggestion). Before either it decides ``initials_as_family`` (rules/O8) from the runs of letters ending the @@ -81,10 +82,11 @@ apply_patch, initials_as_family_may_move, ) from ._types import ( - ADDED_IN, FAMILY_FIRST, GIVEN_FIRST, ReadingSource, Role, + ADDED_IN, FAMILY_FIRST, FAMILY_FIRST_GIVEN_LAST, GIVEN_FIRST, + ReadingSource, Role, _guarded_getstate, _guarded_setstate, ) -from .config._order_names import COMMON_GIVEN_NAMES, ROMANIZED_SURNAMES +from .config._order_names import COMMON_GIVEN_NAMES, SURNAMES if TYPE_CHECKING: from ._parser import Parser @@ -128,8 +130,9 @@ class Signal(StrEnum): TRAILING_INITIAL = "trailing-initial" #: A lowercase particle first or before the last word. PARTICLE = "particle" - #: A common romanized Chinese, Korean or Vietnamese surname as the - #: first or last word. + #: A common surname as the first or last word: a romanized Chinese, + #: Korean or Vietnamese one, or one ORCID's holders rarely type as a + #: given name (``García``, #1364). SURNAME = "surname" #: A common given name that is rarely a surname (``Emily``, not #: ``Taylor``) as the first or last word. @@ -238,13 +241,13 @@ def _listed(word: str, table: frozenset[str]) -> bool: def _a_listed_name(word: str) -> bool: """A word the name tables list: name evidence, which is never read past as a title or a post-nominal (`Law`, a Cantonese surname and a - listed title). The given-name table holds no listed suffix since - #1357, and the surname table's (`ma`, `meng`) are acronyms that may - be a name, which are not read past bare with or without this test, - so the post-nominal half acts on no shipped word; it holds for a - table built otherwise.""" - return (_listed(word, ROMANIZED_SURNAMES) - or _listed(word, COMMON_GIVEN_NAMES)) + listed title). The given-name and ORCID surname tables hold no + listed suffix or title (their builder refuses them), and the + romanized surname table's suffixes (`ma`, `meng`) are acronyms that + may be a name, which are not read past bare with or without this + test, so the post-nominal half acts on no shipped word; it holds for + a table built otherwise.""" + return _listed(word, SURNAMES) or _listed(word, COMMON_GIVEN_NAMES) def _is_leading_title(word: str, lexicon: Lexicon) -> bool: @@ -426,9 +429,9 @@ def _read(text: str, lexicon: Lexicon # (#1397) silent = _opens_in_short_capitals(words) or ( _ends_in_short_capitals(words) - and _listed(words[-1], ROMANIZED_SURNAMES)) + and _listed(words[-1], SURNAMES)) tables = () if silent else ( - (Signal.SURNAME, ROMANIZED_SURNAMES, FAMILY_FIRST, GIVEN_FIRST),) + (Signal.SURNAME, SURNAMES, FAMILY_FIRST, GIVEN_FIRST),) for signal, table, first_order, last_order in ( *tables, (Signal.GIVEN_NAME, COMMON_GIVEN_NAMES, GIVEN_FIRST, FAMILY_FIRST)): @@ -1239,7 +1242,11 @@ def _decide_order(tally: _Tally, base_order: tuple[Role, Role, Role], decided East Slavic rule decides the order as given-first, since the rule reorders each name and reorders none under a family-first order, unless the names' own votes decide family-first: a decided - order is never overridden, and the rule then reorders no name. A + order is never overridden, and the rule then reorders no name. There + a ``FAMILY_FIRST_GIVEN_LAST`` base gets ``FAMILY_FIRST``, whose + reading the rule leaves as written (`Popov Ivan Ivanovich`, given + `Ivan`); its own spelling would read the patronymic as the given name + (decisions/group-suggestion, 2026-11-19 #1364). A rule that keeps a ``FAMILY_FIRST`` base's order (`_keeps_family_first`) is not passed here: the order is then the votes' or the base's.""" @@ -1262,6 +1269,8 @@ def _decide_order(tally: _Tally, base_order: tuple[Role, Role, Role], # the order tally holds orders alone order = base_order if _end(base_order) == end else cast( "tuple[Role, Role, Role]", end) + if rule_needs_given_first and order == FAMILY_FIRST_GIVEN_LAST: + order = FAMILY_FIRST fields: dict[str, object] = ( {} if order == base_order else {_NAME_ORDER: order}) return (tally.evidence(_NAME_ORDER, order, True, diff --git a/nameparser/config/_order_names.py b/nameparser/config/_order_names.py index 4df02c075..73e020cf4 100644 --- a/nameparser/config/_order_names.py +++ b/nameparser/config/_order_names.py @@ -1,6 +1,7 @@ -"""Romanized Chinese, Korean and Vietnamese surnames, and common given -names, for the group -suggester only (``Parser.suggest``); no parse reads this module. +"""Romanized Chinese, Korean and Vietnamese surnames, common given +names, and surnames ORCID's holders rarely type as a given name, for +the group suggester only (``Parser.suggest``); no parse reads this +module. Each name is read on its own: a listed surname at one end of the name and not at the other is evidence that the name writes the family name @@ -32,15 +33,25 @@ typed at least 3 times there, that pass the filter: no full stop, written in the family-name box at most 10% of the 20 or more times ORCID's holders wrote it (5% until #1357, which left out ``John``, - ``David`` and ``Robert``), not a surname this table lists, not a + ``David`` and ``Robert``), not a romanized surname, not a word the default lexicon reads as a title outside ``titles_ambiguous``, not a title it lists as an abbreviation (``gen``) and not a word it lists as a suffix (``md``, which ends a name as a credential). See tools/vocab/order_names.py. -The given-name table excludes every surname listed here, so the two -tables never share a spelling (the tool refuses a run where they do). -Only the surname lists share spellings, with each other: ``lee`` and +- ``_COMMON_SURNAMES`` (generated below, ``COMMON_SURNAMES``): from + the same ORCID file, every word its holders typed in the family-name + box at least 100 times and in the given-name box at most 5% of the + times they typed it in either, not a word the other two tables list, + not a title or suffix the given names refuse, not a particle, + conjunction, bound given name, maiden marker or Hangul surname the + default lexicon lists, and not a Turkic patronymic marker (#1364). + Mostly Spanish surnames. See tools/vocab/order_names.py. + +The given-name table excludes every romanized surname, and the ORCID +surnames exclude every word the other two tables list, so no two +tables share a spelling (the tool refuses a run where they do). +Only the romanized surname lists share spellings, with each other: ``lee`` and ``lim`` are written in Chinese and in Korean, ``ho`` and ``tang`` in Chinese and in Vietnamese, ``ha`` in Korean and in Vietnamese, and many hand-listed spellings are pinyin too. The tables list spellings, not @@ -1122,3 +1133,85 @@ # -- END generated: COMMON_GIVEN -- COMMON_GIVEN_NAMES: frozenset[str] = frozenset(_COMMON_GIVEN) + +# -- BEGIN generated: COMMON_SURNAMES; edit tools/vocab/order_names.py, not this block -- +_COMMON_SURNAMES = ( + "abbasi", "abdullayev", "abdullayeva", "acevedo", "acosta", "acuna", "aguila", "aguilar", + "aguilera", "aguirre", "agvero", "ahmadi", "akbari", "alali", "alanazi", "alarcon", + "alcantara", "aleman", "alghamdi", "alharbi", "aliaga", "aliyeva", "almutairi", "alomari", + "alotaibi", "alqahtani", "alshammari", "altamirano", "alvarado", "alvarenga", "alvarez", "alzahrani", + "alzoubi", "andersen", "apaza", "aponte", "aquino", "arancibia", "arango", "arce", + "arellano", "arenas", "argueta", "arias", "arroyo", "arteaga", "atencio", "avendano", + "avila", "aviles", "babic", "ballesteros", "banerjee", "barrantes", "barria", "barrientos", + "barrios", "bauer", "bazan", "becerra", "bedoya", "benavides", "benitez", "berger", + "bermudez", "blanco", "bohorquez", "bonilla", "bravo", "briones", "bueno", "buitrago", + "burgos", "burke", "bustamante", "byrne", "caballero", "cabezas", "cabral", "cabrera", + "cadena", "caicedo", "calero", "calle", "camacho", "canales", "cano", "carbajal", + "carballo", "cardenas", "cardozo", "carneiro", "carpio", "carranza", "carrasco", "carreno", + "carrera", "carrillo", "carrion", "carvajal", "casanova", "casas", "castaneda", "castano", + "castellanos", "castellon", "castillo", "cedeno", "cerda", "cervantes", "cespedes", "cevallos", + "chacon", "chamorro", "chavez", "chirinos", "choque", "christensen", "cifuentes", "cisneros", + "clarke", "cohen", "colque", "conde", "condori", "contreras", "cooper", "cordero", + "cordova", "cornejo", "coronado", "coronel", "cortes", "cortez", "crespo", "cuellar", + "cuenca", "cueva", "cuevas", "daza", "delgado", "diaz", "diez", "dimitrov", + "dimitrova", "djordjevic", "dominguez", "dube", "duenas", "duque", "duran", "ebrahimi", + "echeverria", "eriksson", "escalona", "espinal", "espino", "espinola", "espinosa", "espinoza", + "esteves", "estrada", "fajardo", "falcon", "farfan", "farkas", "fernandez", "ferrari", + "ferrer", "filipovic", "fischer", "flores", "forero", "frias", "fuentes", "galeano", + "galindo", "gallardo", "gallego", "gallegos", "gallo", "galvez", "gamarra", "gamboa", + "gamez", "garces", "garcia", "garrido", "garzon", "georgiev", "georgieva", "gimenez", + "giron", "godoy", "gomez", "gonzales", "gonzalez", "grigoryan", "guaman", "guerra", + "guerrero", "guevara", "guillen", "guliyeva", "gutierrez", "haddad", "hall", "hasanov", + "hasanova", "hashemi", "henriquez", "heredia", "hernandez", "herrera", "hinojosa", "horvat", + "hosseini", "hoyos", "huaman", "huamani", "huanca", "huerta", "hughes", "hurtado", + "huseynov", "huseynova", "ibanez", "iglesias", "ilic", "infante", "ismayilova", "ivanovic", + "izquierdo", "jafari", "jaimes", "jankovic", "jaramillo", "jensen", "jimenez", "johansson", + "johnston", "jonsson", "jorgensen", "jovanovic", "juarez", "jurado", "kaplan", "karimov", + "karimova", "karlsson", "khoury", "klein", "knezevic", "kobayashi", "kostic", "kovac", + "kovacevic", "kovacs", "kristensen", "krstic", "lagos", "lamichhane", "ledesma", "lemus", + "leyva", "lezcano", "linares", "londono", "lopez", "lozada", "lugo", "lukic", + "luque", "lynch", "lyu", "macias", "madrid", "madsen", "mahmoudi", "maldonado", + "mamani", "mammadov", "mammadova", "manzano", "marcano", "maric", "markovic", "marquez", + "marroquin", "martinez", "mayorga", "mccarthy", "mejia", "melgar", "mendez", "mendoza", + "meneses", "mercado", "merino", "mesa", "meza", "milosevic", "milovanovic", "mitrovic", + "mohammadi", "mojica", "molina", "molnar", "moncada", "monroy", "monsalve", "montalvo", + "montano", "montero", "montes", "monzon", "moore", "moradi", "morales", "moreno", + "morillo", "moscoso", "mosquera", "mousavi", "moya", "moyo", "mukherjee", "munoz", + "murphy", "mvller", "nakamura", "naranjo", "narvaez", "navarrete", "navas", "nazari", + "ndiaye", "ndlovu", "nemeth", "nepal", "nielsen", "nieto", "nikolic", "nikolova", + "nilsson", "noguera", "nunez", "o'brien", "o'connor", "o'neill", "o'sullivan", "obando", + "obeidat", "obregon", "ochoa", "ojeda", "ordonez", "orellana", "orozco", "ortega", + "ortiz", "osorio", "oviedo", "ozdemir", "oztvrk", "pacheco", "padilla", "padron", + "paez", "palacio", "palacios", "palomino", "paniagua", "pantoja", "papadopoulos", "papp", + "pardo", "paredes", "parra", "pathak", "patino", "paucar", "paudel", "pavlovic", + "pedersen", "pelaez", "pena", "peralta", "perdomo", "pereyra", "perez", "petersen", + "petrova", "petrovic", "phiri", "pimentel", "pineda", "pinzon", "pizarro", "plaza", + "polanco", "poma", "ponce", "popov", "popova", "popovic", "poudel", "pozo", + "prieto", "pulido", "quesada", "quevedo", "quezada", "quinones", "quintana", "quintanilla", + "quintero", "quiroga", "quispe", "ramirez", "rasmussen", "restrepo", "rezaei", "rincon", + "rios", "riquelme", "rivas", "rivero", "riveros", "roca", "rodas", "rodriguez", + "rojas", "romero", "rondon", "rosas", "rosero", "rueda", "ruiz", "russo", + "saavedra", "sadeghi", "saenz", "saez", "salas", "salazar", "salcedo", "saldana", + "salehi", "salinas", "salvatierra", "samaniego", "samudio", "sanabria", "sanchez", "santamaria", + "santillan", "sanz", "saravia", "sarmiento", "sato", "saucedo", "savic", "schmid", + "schmidt", "schneider", "segovia", "segura", "sepulveda", "serrano", "simic", "solano", + "soler", "solis", "soltani", "sorensen", "soria", "soriano", "sotelo", "soto", + "stankovic", "stevanovic", "stojanovic", "suarez", "suazo", "suzuki", "takahashi", "tamayo", + "tapia", "tellez", "tenorio", "teran", "ticona", "todorova", "todorovic", "toledo", + "tomic", "toro", "torre", "torres", "torrez", "toth", "toure", "trejo", + "tripathi", "trujillo", "turner", "uribe", "urrutia", "vaca", "valderrama", "valdes", + "valdez", "valdivia", "valenzuela", "valero", "valladares", "vallejo", "vallejos", "valverde", + "varela", "varga", "vargas", "vasquez", "vazquez", "velasquez", "velez", "veliz", + "vergara", "vila", "vilca", "vilchez", "villa", "villalba", "villanueva", "villar", + "villarroel", "villegas", "vivas", "vukovic", "walsh", "watanabe", "weber", "weiss", + "white", "wood", "wright", "yamada", "yamamoto", "yanez", "yepez", "yoshida", + "zambrano", "zapata", "zarate", "zavala", "zelaya", "zivkovic", "zuniga", +) +# -- END generated: COMMON_SURNAMES -- + +COMMON_SURNAMES: frozenset[str] = frozenset(_COMMON_SURNAMES) + +#: Every surname the suggester looks up: the romanized table and the +#: ORCID one, which share no spelling (the tool refuses a run where they +#: do). +SURNAMES: frozenset[str] = ROMANIZED_SURNAMES | COMMON_SURNAMES diff --git a/tests/v2/test_layering.py b/tests/v2/test_layering.py index 3082845fe..8935b824e 100644 --- a/tests/v2/test_layering.py +++ b/tests/v2/test_layering.py @@ -915,15 +915,18 @@ def test_the_check_finds_a_tool_read_through_an_alias( #: `sets =` binding and the two suffix sets it reads (the given names #: refusing a listed suffix, #1357), 25 -> 28 (`listed_titles` #: reading `title_abbreviations` too adds none, that set being no -#: field of `_VOCAB_FIELDS`); and tools/pt_given_names.py reading the +#: field of `_VOCAB_FIELDS`); tools/pt_given_names.py reading the #: default's particles, a family word after one not counted (#1453), -#: 28 -> 29. 4i-a's own count was 114 (on +#: 28 -> 29; and order_names.py's `listed_name_pieces`, its `sets =` +#: binding and the five sets it reads (the surnames refusing a particle, +#: conjunction, bound given name, maiden marker or listed Hangul +#: surname, #1364), 29 -> 35. 4i-a's own count was 114 (on #: that tree's sources), two of them `getattr`s in #: `_parser._apply_choice`, which read the sets through #: `_lexicon._fields_of` from 4i-b until 4i-c retired it. #: A reader added through `_sets` moves these, and they are re-taken #: then: they count what the check would refuse with the move undone. -_UNGUARDED_READS = {"library": 198, "tools": 29} +_UNGUARDED_READS = {"library": 198, "tools": 35} def test_the_check_refuses_every_read_4i_a_moved() -> None: diff --git a/tests/v2/test_order_names_tool.py b/tests/v2/test_order_names_tool.py index 41b58b2bb..f60c468d0 100644 --- a/tests/v2/test_order_names_tool.py +++ b/tests/v2/test_order_names_tool.py @@ -460,3 +460,135 @@ def test_a_table_below_its_floor_or_overlapping_is_refused( tool.check_tables(pinyin, given) tool.check_tables({f"p{i}" for i in range(150)}, {f"g{i}" for i in range(5000)}) + + +# -- #1364: the surname table, the given-name recipe's mirror --------------- +def _surnames(tool: ModuleType, given: dict[str, int], + family: dict[str, int], *, + exclude: frozenset[str] = frozenset()) -> set[str]: + # the share and the floor are the tool's own constants, so a test of + # the cut fails when one moves + from collections import Counter + return tool.common_surnames( # type: ignore[no-any-return] + Counter(given), Counter(family), min_uses=tool.MIN_SURNAME_USES, + max_given_share=tool.MAX_GIVEN_SHARE, exclude=set(exclude)) + + +@needs_checkout +def test_the_given_share_cut_is_five_percent(tool: ModuleType) -> None: + # a surname typed in the given box 10 times in 200 is kept, 11 in + # 200 is not; the share counts both boxes, as the given-name table's + # does + got = _surnames(tool, {"zzfive": 10, "zzsix": 11, "zznone": 0}, + {"zzfive": 190, "zzsix": 189, "zznone": 100}) + assert got == {"zzfive", "zznone"} + + +@needs_checkout +def test_the_floor_counts_the_family_box_alone(tool: ModuleType) -> None: + # 100 uses in the family box is the floor; 99 there and any number in + # the given box is under it + got = _surnames(tool, {"zzunder": 1}, {"zzat": 100, "zzunder": 99}) + assert got == {"zzat"} + + +@needs_checkout +def test_a_one_letter_word_a_dotted_word_and_an_excluded_one_never_enter( + tool: ModuleType) -> None: + family = {"z": 500, "zz.qq": 500, "zzgiv": 500, "zzsur": 500} + got = _surnames(tool, {}, family, exclude=frozenset({"zzgiv"})) + assert got == {"zzsur"} + + +@needs_checkout +def test_a_name_piece_is_refused(tool: ModuleType) -> None: + # typed into the family box beside the surname it belongs to + pieces = tool.listed_name_pieces() + assert {"von", "der", "de", "da", "van", "y", "abou", "nee"} <= pieces + # the Hangul census surnames, which the parse reads by their script + assert tool.fold("김") in pieces + assert not pieces & _order_names.COMMON_SURNAMES + + +@needs_checkout +def test_the_surnames_refuse_every_other_table_and_listed_word( + tool: ModuleType) -> None: + got = tool.surname_refusals({"zzpinyin"}, {"zzgiven"}) + assert {"zzpinyin", "zzgiven", "lee", "nguyen", "prof", "phd", "filho", + "von"} <= got + + +@needs_checkout +def test_the_surname_table_is_built_without_listed_words( + tool: ModuleType, monkeypatch: pytest.MonkeyPatch, + tmp_path_factory: pytest.TempPathFactory) -> None: + # the refusals as the build applies them, on a planted corpus: each + # word is typed in the family box 120 times and never in the given + # box. `Filho` is a listed suffix, `Prof` a listed title, `von` a + # particle, `кызы` a Turkic + # patronymic marker refused by its shape, `Zzgiv` a given name of + # this run + from ._differential_fixtures import own_cache + cache = own_cache(monkeypatch, tmp_path_factory) + _plant_orcid(cache, [ + {"given": "Zzanna", "family": word} + for word in ("Zzsur", "Filho", "von", "кызы", "Zzgiv", "Prof") + for _ in range(120)]) + assert tool.load_common_surnames( + tool.surname_refusals(set(), {"zzgiv"})) == {"zzsur"} + + +@needs_checkout +def test_the_shipped_surname_table_is_what_the_tool_writes( + tool: ModuleType) -> None: + from nameparser import locales + cache = tool.name_usage.cache_dir() + orcid = cache / "local" / "orcid-researchers" / "raw.jsonl" + if not orcid.exists(): + pytest.skip("the ORCID local corpus is not cached") + readings = _cached_pinyin(tool) + singles = [s for s in locales.ZH.lexicon._sets.surnames if len(s) == 1] + pinyin = tool.pinyin_surnames(singles, readings) + given = tool.load_common_given(tool.surname_exclusions(pinyin)) + words = tool.load_common_surnames(tool.surname_refusals(pinyin, given)) + tool.check_tables(pinyin, given, words) + block = tool.render_block("COMMON_SURNAMES", words) + text = Path(_order_names.__file__).read_text(encoding="utf-8") + assert tool.rewrite(text, "COMMON_SURNAMES", block) == text + assert _order_names.COMMON_SURNAMES == frozenset(words) + assert not words & (_order_names.ROMANIZED_SURNAMES + | _order_names.COMMON_GIVEN_NAMES) + assert (_order_names.SURNAMES + == _order_names.ROMANIZED_SURNAMES | _order_names.COMMON_SURNAMES) + + +@needs_checkout +@pytest.mark.parametrize("surnames, fragment", [ + ({f"s{i}" for i in range(399)}, "399 surnames, below the floor of 400"), + ({f"s{i}" for i in range(400)} | {"g1"}, "both tables: g1"), + ({f"s{i}" for i in range(400)} | {"p1"}, "both tables: p1"), + # a hand-listed romanized surname is in the surname table too + ({f"s{i}" for i in range(400)} | {"nguyen"}, "both tables: nguyen"), +]) +def test_a_surname_table_below_its_floor_or_overlapping_is_refused( + tool: ModuleType, surnames: set[str], fragment: str) -> None: + pinyin = {f"p{i}" for i in range(150)} + given = {f"g{i}" for i in range(5000)} + with pytest.raises(ValueError, match=fragment): + tool.check_tables(pinyin, given, surnames) + tool.check_tables(pinyin, given, {f"s{i}" for i in range(400)}) + + +def test_the_three_tables_share_no_spelling_and_are_folded() -> None: + # read from the shipped module, so it runs where the ORCID cache is + # absent (CI): a hand-listed romanized spelling added later that a + # generated table holds would vote both ways + from nameparser._suggest import fold + surnames = _order_names.COMMON_SURNAMES + romanized = _order_names.ROMANIZED_SURNAMES + given = _order_names.COMMON_GIVEN_NAMES + assert not surnames & romanized + assert not surnames & given + assert not romanized & given + assert all(fold(w) == w and len(w) >= 2 for w in surnames) + assert _order_names.SURNAMES == surnames | romanized diff --git a/tests/v2/test_suggest.py b/tests/v2/test_suggest.py index 58b4e5e26..e069e6e4d 100644 --- a/tests/v2/test_suggest.py +++ b/tests/v2/test_suggest.py @@ -543,7 +543,7 @@ def test_a_group_with_no_trailing_initial_carries_no_note_of_one() -> None: def test_the_patronymic_evidence_says_what_its_share_counted() -> None: - s = Parser().suggest(_EAST_SLAVIC + ["Popov Ivan I.", "Orlov Oleg P."]) + s = Parser().suggest(_EAST_SLAVIC + ["Zorvov Ivan I.", "Orlov Oleg P."]) note = _patronymic_evidence(s).note assert ("2 names whose only vote was a set-aside trailing initial " "count among the names casting a vote") in note @@ -551,7 +551,7 @@ def test_the_patronymic_evidence_says_what_its_share_counted() -> None: assert "set-aside" not in _patronymic_evidence(plain).note # a set-aside name with another vote left is no name of the count capitals = Parser().suggest( - _EAST_SLAVIC + ["Popov Ivan I.", "SMITH John A."]) + _EAST_SLAVIC + ["Zorvov Ivan I.", "SMITH John A."]) assert ("1 name whose only vote was a set-aside trailing initial " "counts among") in _patronymic_evidence(capitals).note # and with no patronymic vote in the group it explains nothing @@ -564,7 +564,7 @@ def test_a_set_aside_name_still_counts_in_the_patronymic_share() -> None: # evidence, so the rule holds 5 of 7 voting names, under four in # five, and decides nothing (it decided East Slavic, 5 of 5, while # a set-aside name left the denominator) - s = Parser().suggest(_EAST_SLAVIC + ["Popov Ivan I.", "Orlov Oleg P."]) + s = Parser().suggest(_EAST_SLAVIC + ["Zorvov Ivan I.", "Orlov Oleg P."]) assert not _patronymic_evidence(s).decided assert s.patch == PolicyPatch() @@ -936,8 +936,11 @@ def test_the_rule_comes_with_capitals_as_family_under_a_given_last_base( names = _written("LAST", 0, 5) base = Parser(policy=Policy(name_order=FAMILY_FIRST_GIVEN_LAST)) s = base.suggest(names) + # the capitals votes decide family-first, so the base's given-last + # spelling gives way to FAMILY_FIRST (2026-11-19 #1364) assert s.patch == PolicyPatch( - patronymic_rules=_EAST_SLAVIC_RULE, capitals_as_family=True) + name_order=FAMILY_FIRST, patronymic_rules=_EAST_SLAVIC_RULE, + capitals_as_family=True) assert _wholly_right(s.parser, names) == 5 assert [s.parser.parse(n).patronymic for n in names] == _FATHERS[:5] @@ -2182,12 +2185,160 @@ def test_a_title_abbreviation_at_either_end_is_no_given_name() -> None: [f"Gen. Zorvan {name}" for name in names]).patch == PolicyPatch() +# -- #1364: the ORCID surname table ---------------------------------------- +# `García` and `Quispe` are listed (a family word ORCID holders rarely +# type in the given box), `Wang` romanized, `Emily` a given name, `Lyu` +# a listed surname of three letters; the other words are invented and +# listed nowhere. Run with the ORCID table emptied, as on 6560abde, every +# row fails but `García Quispe`, `Zorvan LYU`, `García LYU`, `AM García` +# and `García, Zorvan`, which cast nothing there either. +@pytest.mark.parametrize("text, votes", [ + ("García Zorvan", {Signal.SURNAME: FAMILY_FIRST}), + ("Zorvan García", {Signal.SURNAME: GIVEN_FIRST}), + # written as a keyboard writes it, the fold reads it the same + ("GARCIA Zorvan", {Signal.SURNAME: FAMILY_FIRST, + Signal.CAPITALS: FAMILY_FIRST}), + # listed at both ends, from one table or from two: no surname vote + ("García Quispe", {}), + ("Wang García", {}), + ("García Wang", {}), + # beside a listed given name, the two signals agree + ("Emily García", {Signal.SURNAME: GIVEN_FIRST, + Signal.GIVEN_NAME: GIVEN_FIRST}), + # a trailing initial beside the surname: both vote family-first + ("García Z", {Signal.SURNAME: FAMILY_FIRST, + Signal.TRAILING_INITIAL: FAMILY_FIRST}), + # #1397: a short capitals word ending a mixed-case name that is a + # listed surname silences the signal, the new table's `lyu` + # included: `Wang LYU` is the witness, which votes family-first by + # `Wang` with the table emptied; `Zorvan LYU` is a control, and + # `García LYU` is listed at both ends and casts nothing anyway + ("Zorvan LYU", {}), + ("Wang LYU", {}), + ("García LYU", {}), + # a listed surname written with a full stop is a name, never the + # title rules/H2's shape reads at the head (`_a_listed_name`) + ("García. Zorvan", {Signal.SURNAME: FAMILY_FIRST}), + ("Zorvan García.", {Signal.SURNAME: GIVEN_FIRST}), + # post-nominals are read past; a comma name states its own order + ("Zorvan García, PhD", {Signal.SURNAME: GIVEN_FIRST}), + ("Zorvan García Jr.", {Signal.SURNAME: GIVEN_FIRST}), + ("García, Zorvan", {}), + # #1355: a short capitals word opening a mixed-case name silences + # it, the listed surname at the other end included + ("AM García", {}), + # a title in front of a listed surname is read past, as before + ("Dr. García Zorvan", {Signal.SURNAME: FAMILY_FIRST}), +]) +def test_an_orcid_surname_votes_by_one_end_and_not_the_other( + text: str, votes: dict[Signal, object]) -> None: + assert name_votes(text, L) == votes + + +@pytest.mark.parametrize("base_order", [ + GIVEN_FIRST, FAMILY_FIRST, FAMILY_FIRST_GIVEN_LAST]) +@pytest.mark.parametrize("family_first", [True, False]) +def test_a_list_of_orcid_surnames_decides_its_order_on_every_base( + base_order: tuple[Role, Role, Role], family_first: bool) -> None: + # two names, the given names invented and listed nowhere: on + # 6560abde no name voted and every base stood. The whole name is + # read right, given and family, under the suggestion + pairs = [("Zorvan", "García"), ("Qelliot", "Quispe")] + names = [f"{f} {g}" if family_first else f"{g} {f}" for g, f in pairs] + s = Parser(policy=Policy(name_order=base_order)).suggest(names) + want = FAMILY_FIRST if family_first else GIVEN_FIRST + if base_order[0] is want[0]: + # the base already writes the family at that end: kept + assert s.patch == PolicyPatch() + else: + assert s.patch == PolicyPatch(name_order=want) + assert [(n.given, n.family) for n in map(s.parser.parse, names)] == pairs + + +@pytest.mark.parametrize("surnames, base_order, order", [ + # three of five family names listed (`Popov`, `Popova`, `Petrova`): + # the names' votes decide family-first, which the East Slavic rule + # never overrides; a FAMILY_FIRST_GIVEN_LAST base gets FAMILY_FIRST, + # under which the patronymic stays the middle name. On 6560abde no + # name voted, and every base got GIVEN_FIRST or kept FAMILY_FIRST + (["Popov", "Popova", "Petrova", "Zorvov", "Qelova"], + FAMILY_FIRST_GIVEN_LAST, FAMILY_FIRST), + (["Popov", "Popova", "Petrova", "Zorvov", "Qelova"], + GIVEN_FIRST, FAMILY_FIRST), + (["Popov", "Popova", "Petrova", "Zorvov", "Qelova"], + FAMILY_FIRST, FAMILY_FIRST), + # the control: no name votes, and the rule brings its given-first + # order to a FAMILY_FIRST_GIVEN_LAST base, as before + (["Zorvov", "Qelova", "Plughov", "Xyzzova", "Frotzov"], + FAMILY_FIRST_GIVEN_LAST, GIVEN_FIRST), +]) +def test_an_east_slavic_list_voting_family_first_reads_its_patronymics( + surnames: list[str], base_order: tuple[Role, Role, Role], + order: tuple[Role, Role, Role]) -> None: + given = [("Ivan", "Ivanovich"), ("Anna", "Petrovna"), + ("Olga", "Sergeevna"), ("Pavel", "Ivanovich"), + ("Maria", "Olegovna")] + names = [f"{f} {g} {p}" for f, (g, p) in zip(surnames, given)] + s = Parser(policy=Policy(name_order=base_order)).suggest(names) + assert s.parser.policy.name_order == order + assert s.parser.policy.patronymic_rules == frozenset( + {PatronymicRule.EAST_SLAVIC}) + assert [(n.given, n.family) for n in map(s.parser.parse, names)] == [ + (g, f) for f, (g, _) in zip(surnames, given)] + + +@pytest.mark.parametrize("capitals_base", [False, True]) +@pytest.mark.parametrize("surnames", [ + ["POPOV", "POPOVA", "PETROVA", "ZORVOV", "QELOVA"], # all in capitals + ["POPOV", "POPOVA", "PETROVA", "ZORVOV", "Qelova"], # but one + ["Popov", "Popova", "Petrova", "Zorvov", "Qelova"]]) # none +def test_an_east_slavic_list_under_a_given_last_base_reads_every_name( + surnames: list[str], capitals_base: bool) -> None: + # FAMILY_FIRST reads the patronymic where it is written whatever the + # switch, while the given-last spelling reads it as the given name in + # a name the switch does not read (one with no family in capitals), + # so the base gives way whether capitals_as_family is suggested, on + # in the base, or off (2026-11-19 #1364) + given = [("Ivan", "Ivanovich"), ("Anna", "Petrovna"), + ("Olga", "Sergeevna"), ("Pavel", "Ivanovich"), + ("Maria", "Olegovna")] + names = [f"{f} {g} {p}" for f, (g, p) in zip(surnames, given)] + s = Parser(policy=Policy(name_order=FAMILY_FIRST_GIVEN_LAST, + capitals_as_family=capitals_base)).suggest(names) + assert s.parser.policy.name_order == FAMILY_FIRST + assert s.parser.policy.patronymic_rules == frozenset( + {PatronymicRule.EAST_SLAVIC}) + assert [(n.given, n.family) for n in map(s.parser.parse, names)] == [ + (g, f) for f, (g, _) in zip(surnames, given)] + + +def test_no_orcid_surname_is_read_as_a_title_or_a_suffix() -> None: + # as the given names are held (above): the suffix sets, the title + # abbreviations, the particles and the conjunctions hold none of the + # surnames' folded spellings, and by the parse's own + # reading no surname is a title or a suffix at either end of a name + from nameparser.config._order_names import COMMON_SURNAMES + sets = L._sets + assert not COMMON_SURNAMES & ( + sets.suffix_acronyms | sets.suffix_words | sets.title_abbreviations + | sets.particles | sets.conjunctions) + parser = Parser() + read = [] + for word in sorted(COMMON_SURNAMES): + for cased in (word.upper(), word.capitalize()): + names = [f"Zorvan Qelliot {cased}", f"Zorvan Qelliot {cased}.", + f"{cased} Zorvan Qelliot"] + read += [name for name in names + if (parsed := parser.parse(name)).title or parsed.suffix] + assert read == [] + + @pytest.fixture def _invented_tables(monkeypatch: pytest.MonkeyPatch) -> None: # the decision rule, read with tables of invented words, so no # shipped table's contents decides a test from nameparser import _suggest - monkeypatch.setattr(_suggest, "ROMANIZED_SURNAMES", + monkeypatch.setattr(_suggest, "SURNAMES", frozenset({"zzsur", "zzfam"})) monkeypatch.setattr(_suggest, "COMMON_GIVEN_NAMES", frozenset({"zzgiv", "zzfirst"})) @@ -2237,6 +2388,7 @@ def test_the_group_rule_reads_invented_tables() -> None: ("Hasanova Afət Əbil qızı", Signal.PATRONYMIC, PatronymicRule.TURKIC), ("Иванов Иван Сергеевич", Signal.PATRONYMIC, PatronymicRule.EAST_SLAVIC), ("Nguyễn Minh", Signal.SURNAME, FAMILY_FIRST), + ("Zorvan García", Signal.SURNAME, GIVEN_FIRST), ]) def test_a_decomposed_name_votes_as_its_composed_twin( text: str, signal: Signal, value: object) -> None: diff --git a/tests/v2/test_suggest_measure.py b/tests/v2/test_suggest_measure.py index 96a4f3424..d75234d78 100644 --- a/tests/v2/test_suggest_measure.py +++ b/tests/v2/test_suggest_measure.py @@ -237,19 +237,77 @@ def _plant_patentsview(cache: Path, lines: list[dict[str, object]]) -> None: path.write_bytes(gzip.compress(body.encode("utf-8"))) +# reads the tables from the checkout's nameparser/config/_order_names.py +# (`_script_tables`), which an installed-package layout does not hold +@needs_checkout def test_patentsview_reads_the_country_whatever_the_key_order( _cache: Path) -> None: + # every line carries the people it stands for, as the fetch writes + # it: the box index pv-surname-given reads counts them _plant_patentsview(_cache, [ - {"country": "JP", "family": "Tanaka", "given": "Hiroshi"}, + {"country": "JP", "family": "Tanaka", "given": "Hiroshi", "people": 1}, {"family": "Sato", "given": "Yuki", "country": "JP", "people": 2}, {"given": "Kenji", "people": 1, "family": "Ito", "country": "JP"}, - {"country": "ZZ", "family": "Nobody", "given": "Anyone"}]) + {"country": "ZZ", "family": "Nobody", "given": "Anyone", "people": 1}]) keep = tool._Reservoir(1) tool._patentsview(keep) assert sorted(keep.pools["pv-JP"]) == [ ("Hiroshi", "Tanaka"), ("Kenji", "Ito"), ("Yuki", "Sato")] +# reads the tables from the checkout's nameparser/config/_order_names.py +# (`_script_tables`), which an installed-package layout does not hold +@needs_checkout +def test_surname_given_holds_a_given_name_written_mostly_as_a_family_name( + _cache: Path, monkeypatch: pytest.MonkeyPatch) -> None: + # #1364: `Zzcruz` is written in the family box by more people than in + # the given box, its spellings counted together under the fold + # (`Zzcrúz`); `Zzana` is not; `Lee` is, but the romanized table + # lists it; a Japanese inventor is left out whatever the word; and a + # record whose family box opens with a listed given name (`Emily`) + # is left out of both populations, its boxes likely swapped + monkeypatch.setattr(tool, "SURNAME_GIVEN_USES", 2) + _plant_patentsview(_cache, [ + {"country": "MX", "family": "Zzlopez", "given": "Zzcruz Ana", + "people": 1}, + {"country": "US", "family": "Zzcruz", "given": "Zzmary", "people": 9}, + {"country": "MX", "family": "Zzlopez", "given": "Zzcrúz", "people": 1}, + {"country": "MX", "family": "Zzcruz", "given": "Zzana", "people": 1}, + {"country": "US", "family": "Zzsmith", "given": "Lee", "people": 2}, + {"country": "US", "family": "Lee", "given": "Zzjohn", "people": 9}, + {"country": "JP", "family": "Zzsato", "given": "Zzcruz", "people": 2}, + {"country": "MX", "family": "Zzpardo", "given": "García Ana", + "people": 1}, + {"country": "US", "family": "Emily", "given": "Zzcruz", "people": 1}, + {"country": "US", "family": "Emily", "given": "García", "people": 1}, + # the swap test reads the family box's first word only + {"country": "US", "family": "Zzpardo Emily", "given": "Zzcruz", + "people": 1}, + {"country": "US", "family": "Emily Zzpardo", "given": "Zzcruz", + "people": 1}, + # at both boundaries: given 2 (the floor), family 2 (as often) + {"country": "MX", "family": "Zzpardo", "given": "Zzedge", "people": 2}, + {"country": "US", "family": "Zzedge", "given": "Zzmary", "people": 2}, + # under the floor of uses: given 1, family 5 + {"country": "MX", "family": "Zzpardo", "given": "Zzunder", + "people": 1}, + {"country": "US", "family": "Zzunder", "given": "Zzmary", "people": 5}, + # over the floor only with its two spellings summed under the fold + {"country": "MX", "family": "Zzpardo", "given": "Zzchávez", + "people": 1}, + {"country": "MX", "family": "Zzpardo", "given": "Zzchavez", + "people": 1}, + {"country": "US", "family": "Zzchavez", "given": "Zzmary", "people": 3}]) + keep = tool._Reservoir(1) + tool._patentsview(keep) + assert sorted(keep.pools["pv-surname-given"]) == [ + ("Zzchavez", "Zzpardo"), ("Zzchávez", "Zzpardo"), + ("Zzcruz", "Zzpardo Emily"), ("Zzcruz Ana", "Zzlopez"), + ("Zzcrúz", "Zzlopez"), ("Zzedge", "Zzpardo")] + # `García` is in the ORCID surname table + assert keep.pools["pv-listed-given"] == [("García Ana", "Zzpardo")] + + @needs_checkout def test_orcid_bylines_keep_only_a_byline_the_boxes_confirm( _cache: Path, monkeypatch: pytest.MonkeyPatch) -> None: @@ -329,7 +387,7 @@ def test_an_orcid_file_holding_no_byline_gets_a_note( def test_a_wanted_population_that_yields_no_names_gets_a_note( _cache: Path, capsys: pytest.CaptureFixture[str]) -> None: _plant_patentsview(_cache, [ - {"country": "JP", "family": "Tanaka", "given": "Hiroshi"}]) + {"country": "JP", "family": "Tanaka", "given": "Hiroshi", "people": 1}]) out = _run(capsys) # patentsview is present but holds no US name, and the planted PSC # rows hold no Polish one @@ -425,3 +483,21 @@ def test_a_stale_or_edited_local_corpus_stops_the_run( def test_the_turkic_truth_reads_a_three_word_marker_name_whole( dataset: str, name: str, truth: str) -> None: assert tool._turkic_truth(dataset, name) == truth + + +# reads the tables from the checkout's nameparser/config/_order_names.py +# (`_script_tables`), which an installed-package layout does not hold +@needs_checkout +def test_the_populations_read_the_scripts_own_tables( + _cache: Path, monkeypatch: pytest.MonkeyPatch) -> None: + # a --base child imports another tree's nameparser; pv-listed-given + # is drawn from the table in this script's checkout, not from the + # imported module, so both sides of a comparison draw it alike + from nameparser.config import _order_names + monkeypatch.setattr(_order_names, "COMMON_SURNAMES", frozenset({"zzzz"})) + _plant_patentsview(_cache, [ + {"country": "MX", "family": "Zzpardo", "given": "García Ana", + "people": 1}]) + keep = tool._Reservoir(1) + tool._patentsview(keep) + assert keep.pools["pv-listed-given"] == [("García Ana", "Zzpardo")] diff --git a/tools/differential/README.md b/tools/differential/README.md index de5fb3290..c0dbef8d4 100644 --- a/tools/differential/README.md +++ b/tools/differential/README.md @@ -420,7 +420,7 @@ 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, 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), and `orcid-byline-joined`'s given-first row at 50 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), 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). ``` uv run python tools/differential/suggest_measure.py diff --git a/tools/differential/suggest_measure.py b/tools/differential/suggest_measure.py index cdfd11bdf..77f2061cc 100644 --- a/tools/differential/suggest_measure.py +++ b/tools/differential/suggest_measure.py @@ -39,7 +39,18 @@ are two or three letters, `orcid-famcaps-short` the ones whose family box is one word of two or three letters (`Zhi LI`, a list with no longer surname in capitals beside it), and `orcid-givcaps` the given -box (`ANNA Smith`, the convention's other writing). A population keeps at most +box (`ANNA Smith`, the convention's other writing), and +`pv-surname-given`, PatentsView's inventors of PV_COUNTRIES less China, +Taiwan, Korea and Japan whose given box opens with a word the source's +own boxes write as a family name at least as often (`Cruz`, `Moreno`; +not a romanized surname, `Lee`, whose cost is as old as its table), and +`pv-listed-given`, the same inventors whose given box opens with a word +of the ORCID surname table, each read from this script's checkout and +less a record whose family box opens with a listed given name (boxes +likely swapped): the lists a surname table moves the wrong way (#1364; the +Spanish- and Portuguese-speaking countries and filers, the Filipino, +Bangladeshi, Pakistani and Turkish ones, joined the populations with +it). A population keeps at most POOL_CAP names, drawn by a seeded reservoir. A source not fetched is left out with a note, as is one present that yields no names and each population a present source yields none of; one present but unreadable @@ -57,8 +68,10 @@ base and size: the anti-goal (decisions/group-suggestion) is the two same-order rows, which must not fall below 95%, save orcid-givcaps' two, which the capitals signal reads the wrong way round by design, -and orcid-byline-joined's given-first row at 50 names (and at 200 -until #1357), where +pv-listed-given's two, whose every given name is a surname the ORCID +table lists, read the wrong way round, a cost left open (2026-11-19 +#1364), and orcid-byline-joined's given-first row at 50 and 100 names, +where the few names the name tables still vote on decide a large group (decisions/group-suggestion, 2026-11-14 #1355). Under each population, the groups that decided the East Slavic rule and the groups that decided @@ -144,6 +157,7 @@ from collections.abc import Callable, Iterator from concurrent.futures import ProcessPoolExecutor from pathlib import Path +from types import ModuleType from typing import TYPE_CHECKING, Any if TYPE_CHECKING: @@ -165,9 +179,20 @@ #: The names each population's signal counts read. SIGNAL_NAMES = 3_000 PV_COUNTRIES = ("US", "DE", "FR", "CN", "JP", "KR", "IN", "IT", "ES", "RU", - "BR", "TW", "NL") + "BR", "TW", "NL", "MX", "AR", "CO", "PH", "PT", "TR") PSC_NATIONALITIES = ("British", "Romanian", "Indian", "Chinese", "Polish", - "Nigerian", "Turkish", "Spanish") + "Nigerian", "Turkish", "Spanish", "Filipino", + "Portuguese", "Bangladeshi", "Pakistani", "Brazilian") +#: `pv-surname-given`: the inventors of PV_COUNTRIES less these whose +#: given box opens with a word PatentsView's own boxes write in the +#: family box at least as often as in the given box, by at least +#: SURNAME_GIVEN_USES inventors in the given box; `pv-listed-given`: +#: those whose given box opens with a word of the ORCID surname table +#: (#1364). +SURNAME_GIVEN_SKIPPED = frozenset({"CN", "TW", "KR", "JP"}) +SURNAME_GIVEN_USES = 20 +SURNAME_GIVEN_LABEL = "pv-surname-given" +LISTED_GIVEN_LABEL = "pv-listed-given" GF, FF, FFGL = "GF", "FF", "FFGL" #: The thresholds --set may override. SETTABLE = ("_MIN_VOTES", "_MIN_SHARE", "_MIN_PATRONYMIC_SHARE", @@ -312,6 +337,9 @@ def _patentsview(keep: _Reservoir) -> None: if not path.exists(): raise FileNotFoundError(2, "not fetched", str(path)) wanted = frozenset(PV_COUNTRIES) + from nameparser._suggest import fold + tables = _script_tables() + surname_given = _surname_given_words(fold, tables) with gzip.open(path, "rt", encoding="utf-8", newline="\n") as lines: if json.loads(next(lines)).get("release") != local_patentsview.PV_RELEASE: raise ValueError(f"{path} is not an extract of the " @@ -322,14 +350,74 @@ def _patentsview(keep: _Reservoir) -> None: if country not in wanted: continue label = f"pv-{country}" - if (at := keep.slot(label)) is None: + at = keep.slot(label) + if at is None and country in SURNAME_GIVEN_SKIPPED: continue record = json.loads(line) if record.get("country") != country: raise ValueError(f"{path}: a line read as {country} is not: " f"{line[:60]!r}") - keep.put(label, at, record.get("given", ""), - record.get("family", "")) + given, family = record.get("given", ""), record.get("family", "") + if at is not None: + keep.put(label, at, given, family) + if country in SURNAME_GIVEN_SKIPPED: + continue + first = [fold(w) for w in local_corpora.words(given)[:1]] + if not first or _swapped(family, fold, tables): + continue + if first[0] in surname_given: + keep.add(SURNAME_GIVEN_LABEL, given, family) + if first[0] in tables.COMMON_SURNAMES: + keep.add(LISTED_GIVEN_LABEL, given, family) + + +def _script_tables() -> ModuleType: + """The name tables of the checkout this script stands in, loaded by + path, so a `--base` child, which imports another tree's nameparser, + draws the same `pv-surname-given` and `pv-listed-given` as the head: + the populations are the script's, the suggester the tree's. The + module is data and imports nothing internal.""" + import importlib.util + path = REPO_ROOT / "nameparser" / "config" / "_order_names.py" + spec = importlib.util.spec_from_file_location("_script_order_names", path) + assert spec is not None and spec.loader is not None + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +def _swapped(family: str, fold: Callable[[str], str], tables: ModuleType) -> bool: + """Whether a record's family box opens with a listed given name, a + record the filer likely typed with its boxes swapped (`Diaz` given, + `Angel` family): such a record's written order is unknown, so the + two populations about given names that are surnames leave it out.""" + first = local_corpora.words(family)[:1] + return bool(first) and fold(first[0]) in tables.COMMON_GIVEN_NAMES + + +def _surname_given_words(fold: Callable[[str], str], tables: ModuleType + ) -> frozenset[str]: + """The given names PatentsView's inventors write in the family box + at least as often as in the given box, written in the given box by + SURNAME_GIVEN_USES or more, each counted under the suggester's fold + (`santiago` 546 and 284 do not count, `cruz` 173 and 916 does, and + `chávez` counts with `chavez`), summed over every country: a given + name that is a surname elsewhere, found from the source's own boxes, + so a surname table that lists it shows its cost there (#1364). A + word the romanized table lists is left out (`Lee`, `Kim`): its cost + is as old as the table (decisions/group-suggestion, 2026-11-10 + THRESHOLDS), and with it in, the list's given-first row read under + 95% from four names on 6560abde, whatever a new table did.""" + index = local_corpora.cached_box_index("patentsview-inventors") + given: Counter[str] = Counter() + family: Counter[str] = Counter() + for counts, box in ((given, index.given), (family, index.family)): + for word, by_country in box.items(): + counts[fold(word)] += sum(by_country.values()) + return frozenset( + word for word, uses in given.items() + if uses >= SURNAME_GIVEN_USES and family[word] >= uses + and word not in tables.ROMANIZED_SURNAMES) def _psc(keep: _Reservoir) -> None: @@ -423,7 +511,8 @@ def _orcid_byline(keep: _Reservoir, r: dict[str, Any]) -> None: #: The populations each source is read for. -WANTED = {"patentsview-inventors": tuple(f"pv-{c}" for c in PV_COUNTRIES), +WANTED = {"patentsview-inventors": (*(f"pv-{c}" for c in PV_COUNTRIES), + SURNAME_GIVEN_LABEL, LISTED_GIVEN_LABEL), "psc-individuals": tuple(f"psc-{n}" for n in PSC_NATIONALITIES), "cz-candidates": ("cz",), "uit-vinames": ("vi",), "orcid-researchers": ("orcid-byline", "orcid-byline-joined", diff --git a/tools/vocab/order_names.py b/tools/vocab/order_names.py index 674da6eff..dd1a2c033 100644 --- a/tools/vocab/order_names.py +++ b/tools/vocab/order_names.py @@ -50,6 +50,22 @@ nothing where a block falls below its floor (``MIN_PINYIN``, ``MIN_GIVEN``) or a word lands in both tables. +The third generated block, ``COMMON_SURNAMES``, is the mirror of the +second (#1364): every word ORCID's holders typed in the family-name box +at least ``MIN_SURNAME_USES`` times, anywhere in the box, and in the +given-name box at most ``MAX_GIVEN_SHARE`` of the times they typed it +in either, with two or more letters and no full stop, less every word +of the other two tables, every title and suffix the +given names refuse, every word the default lexicon reads as a piece of +a name (:func:`listed_name_pieces`: a particle, a conjunction, a bound +given name, a maiden marker, its Hangul surnames) and every Turkic +patronymic marker. The suggester reads it beside the romanized +surnames, as one surname signal. Most of it is Spanish, because ORCID's +sample holds many more Spanish-speaking holders than the use floor +needs (decisions/group-suggestion, 2026-11-19 #1364). The run writes +nothing where the block falls below ``MIN_SURNAMES`` or a word lands in +two tables. + Wikidata's answer is cached outside the repository ($NAMEPARSER_TOOLS_CACHE or ~/.cache/nameparser-tools), and asked again where the cache did not ask about every character the run reads. @@ -83,6 +99,13 @@ #: names at a family share of 10%, #1357). MIN_PINYIN = 150 MIN_GIVEN = 5_000 +#: The surname table (#1364): a word ORCID holders typed in the +#: family-name box at least ``MIN_SURNAME_USES`` times, and in the +#: given-name box at most ``MAX_GIVEN_SHARE`` of the times they typed it +#: in either. ``MIN_SURNAMES`` is its floor (2026-11-19 #1364: 559 words). +MIN_SURNAME_USES = 100 +MAX_GIVEN_SHARE = 0.05 +MIN_SURNAMES = 400 MODULE = Path(__file__).parents[2] / "nameparser" / "config" / "_order_names.py" PINYIN_FILE = "wikidata_chinese_surname_pinyin.json" @@ -346,15 +369,85 @@ def load_common_given(exclude: set[str]) -> set[str]: exclude=exclude | listed_titles() | listed_suffixes()) -def check_tables(pinyin: set[str], given: set[str]) -> None: - """Refuse a generated block below its floor, and a given name that - is a surname too.""" - for words, floor, what in ((pinyin, MIN_PINYIN, "pinyin surnames"), - (given, MIN_GIVEN, "given names")): +def common_surnames(given: Counter[str], family: Counter[str], *, + min_uses: int, max_given_share: float, + exclude: set[str]) -> set[str]: + """The mirror of :func:`common_given` (#1364): every word typed in + ORCID's family-name box ``min_uses`` times or more, anywhere in the + box, and in the given-name box at most ``max_given_share`` of the + times it was typed in either, with two or more letters, no full stop + and not in ``exclude``. No ranking per country: the holders state + the country they work in, which says little about where a surname + is from, and the use floor alone sets the size.""" + def passes(word: str) -> bool: + total = given[word] + family[word] + return (len(word) > 1 and "." not in word and word not in exclude + and family[word] >= min_uses + and given[word] / total <= max_given_share) + + return {word for word in family if passes(word)} + + +def listed_name_pieces() -> set[str]: + """The words the default lexicon reads as a piece of a name rather + than a name, folded: a particle (``der``, ``von``), a conjunction, a + bound given name (``abou``), a maiden marker, and its own surnames, + the Hangul census list the parse splits unspaced names on (rules/W1) + and reads family-first by its script (rules/W4), which the + suggester's tables do not hold. A particle, a conjunction or a bound + given name is typed into ORCID's family box with the surname it + belongs to (``von Berg``, ``Abou Zeid``) + and rarely into the given box, so the surname recipe would admit + it; as a table word it would vote where it stands at an end of a + name, which a particle does in a family written first (``von Berg + Anna``, read by the particle signal already) and a given-first + name's last word never is.""" + from nameparser import Lexicon + sets = Lexicon.default()._sets + return {fold(w) for w in (sets.particles | sets.conjunctions + | sets.bound_given_names | sets.maiden_markers + | sets.surnames) + if " " not in w} + + +def surname_refusals(pinyin: set[str], given: set[str]) -> set[str]: + """Every word the surname table must not hold: the romanized + surnames and the given names this run writes (so no word is in two + tables), the listed titles, suffixes and name pieces.""" + return (surname_exclusions(pinyin) | given | listed_titles() + | listed_suffixes() | listed_name_pieces()) + + +def load_common_surnames(exclude: set[str]) -> set[str]: + """The surname table, refusing ``exclude`` and a Turkic patronymic + marker (``кызы``, ``oglu``), which rules/O2 reads as the end of a + patronymic and ORCID holders type into the family box.""" + from nameparser._pipeline._vocab import is_patronymic_marker + given, family, _ = orcid_box_counts( + name_usage.cache_dir().joinpath(*ORCID_RAW)) + words = common_surnames(given, family, min_uses=MIN_SURNAME_USES, + max_given_share=MAX_GIVEN_SHARE, exclude=exclude) + return {w for w in words if not is_patronymic_marker(w)} + + +def check_tables(pinyin: set[str], given: set[str], + surnames: set[str] | None = None) -> None: + """Refuse a generated block below its floor, and a word in two + tables.""" + floors = [(pinyin, MIN_PINYIN, "pinyin surnames"), + (given, MIN_GIVEN, "given names")] + if surnames is not None: + floors.append((surnames, MIN_SURNAMES, "surnames")) + for words, floor, what in floors: if len(words) < floor: raise ValueError(f"the run found {len(words)} {what}, below the " f"floor of {floor}: an input is cut or changed") - if both := pinyin & given: + tables = [pinyin | surname_exclusions(pinyin), given, surnames or set()] + both = set() + for i, one in enumerate(tables): + for other in tables[i + 1:]: + both |= one & other + if both: raise ValueError("a word is in both tables: " + ", ".join(sorted(both))) @@ -376,16 +469,18 @@ def main(argv: list[str] | None = None) -> int: file=sys.stderr) words = pinyin_surnames(singles, readings) given = load_common_given(surname_exclusions(words)) - check_tables(words, given) - block = render_block("PINYIN", words) - given_block = render_block("COMMON_GIVEN", given) - print(block) - print(given_block) + surnames = load_common_surnames(surname_refusals(words, given)) + check_tables(words, given, surnames) + blocks = {"PINYIN": render_block("PINYIN", words), + "COMMON_GIVEN": render_block("COMMON_GIVEN", given), + "COMMON_SURNAMES": render_block("COMMON_SURNAMES", surnames)} + for block in blocks.values(): + print(block) if args.write: text = MODULE.read_text(encoding="utf-8") - text = rewrite(text, "PINYIN", block) - MODULE.write_text(rewrite(text, "COMMON_GIVEN", given_block), - encoding="utf-8") + for name, block in blocks.items(): + text = rewrite(text, name, block) + MODULE.write_text(text, encoding="utf-8") print(f"wrote {MODULE}", file=sys.stderr) return 0