From 74f58a2c5b6b6d2b4a3c43d2912d5cb71314612a Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Thu, 19 Nov 2026 14:12:31 -0800 Subject: [PATCH 1/4] Divide a family of two surnames by its own words, behind a comma too (#1456, #1479) Under two_family_names the surname1/surname2 views now divide a family of two surnames however it was read: before a family comma, where a particle chain made it, behind a given name a particle completes (rules/P10), and the family O9's capitals named. One function, _post_rules._divide_family, decides for every path, O6's take included: P1's fold units over the family in written order, a bound given-name word counted with the word it completes, exactly two marked, a first unit of particles alone, a connective, a shared name and a Turkic father's name with its marker left whole. No field moves; nothing moves with the switch off. rules/O6, R10, R11, P10, O7 and O9 amended, with dated decisions entries; the connective and the one-word hyphen question stays open in decisions/R10. Case rows gain an optional views mapping. Co-Authored-By: Claude Opus 5.5 --- docs/design/decisions/O6-two-family-names.md | 15 + .../O9-words-in-capitals-as-the-family.md | 1 + .../P10-given-name-a-particle-completes.md | 1 + .../decisions/R10-second-surname-view.md | 2 + .../decisions/R11-first-surname-views.md | 2 + docs/design/decisions/vocabulary-model.md | 2 +- docs/design/rules/O6-two-family-names.md | 39 ++- docs/design/rules/O7-two-given-names.md | 4 - .../O9-words-in-capitals-as-the-family.md | 3 +- .../P10-given-name-a-particle-completes.md | 7 +- docs/design/rules/R10-second-surname-view.md | 17 +- docs/design/rules/R11-first-surname-views.md | 12 +- docs/design/vocabulary-model-rfc.md | 2 +- docs/languages.rst | 4 + docs/migrate.rst | 29 ++ docs/policy.rst | 22 +- docs/release_log.rst | 1 + docs/usage.rst | 10 +- nameparser/AGENTS.md | 2 + nameparser/_pipeline/_post_rules.py | 182 +++++++++--- nameparser/_pipeline/_state.py | 12 +- nameparser/_policy.py | 10 +- nameparser/_types.py | 9 +- tests/v2/cases.py | 74 ++++- tests/v2/pipeline/test_post_rules.py | 267 +++++++++++++++++- tests/v2/rules_doc.py | 3 + tests/v2/test_cases.py | 2 + tests/v2/test_types.py | 71 +++-- .../differential/cldr_agreement_locales.json | 22 -- tools/differential/corpus_rules.jsonl | 12 + tools/differential/snapshot.jsonl | 12 + 31 files changed, 723 insertions(+), 128 deletions(-) diff --git a/docs/design/decisions/O6-two-family-names.md b/docs/design/decisions/O6-two-family-names.md index 4cc657e5e..fbc9ca76c 100644 --- a/docs/design/decisions/O6-two-family-names.md +++ b/docs/design/decisions/O6-two-family-names.md @@ -10,6 +10,7 @@ - Both family names stay in `family` through 2.x; a second-surname field is the RFC's Phase 4 output model (docs/design/vocabulary-model-rfc.md, "The rules a pack can choose"), and a pack may later switch this rule on — 2026-10-24 #754; landed as the `surname2` view, `family` keeping both, 2026-10-29 #754, sub-phase 4d. - The family's words are counted as P1's fold counts them, a connective join and a hyphen counting as their words, so a family already holding two keeps what it has; the word taken must count as one, a hyphenated word counting as one there unless it writes given names (each part a listed given name or an initial), and be no initial written alone — 2026-10-24 #754; 2026-11-03 #959 (Derek). - A name its script (W4) reads in an order other than the declared `name_order` is left alone; where the two agree it is read like any other — 2026-10-24 #754. +- A family is divided into its two units by its own words, one function every path calls, so the two writings of one name give the same units wherever they give the same family: P1's fold units over the family in written order, divided where there are exactly two, after the rule takes a word, where the family already held two words (a particle chain, the family a P10 phrase leaves), where O9's capitals named it, and before a family comma where no word from after the comma joined it and its script sets no other order. A family opening with a particle divides after the particles and the one word they attach to; one of three units or more, a connective's, a name written `shared`, one whose first unit is particles alone and, under the Turkic rule, the father's name and its marker stay whole; a bound given-name word counts with the word it completes; no given-name list vetoes a word before a comma — 2026-11-19 #1456, #1479. - Under a family-first order the first two name words are the family, the remainder laid out as the positions after a family — 2026-10-24 #754. - Under a family-first order a particle chain after the family is cut where P1's family-first fold cuts its own run, its particles and the one name word they attach to taken, so `Pérez de la Vega Juan` reads family 'Pérez de la Vega', given 'Juan'; without the switch, or under the default order, the chain stays whole — 2026-11-03 #1024. - The switch runs before `middle_as_family` and is not refused beside it: given-first, the two together read as `middle_as_family` alone — 2026-10-24 #754. @@ -258,3 +259,17 @@ - **On names as written.** Over the 848,351 names of `tse-donors` (Brazilian candidates' donors as filed), `locales.PT_BR` against the pack as it stood (a `pt-BR` choice, no list, no patch) moves 500,485, every one into the family: 418,432 take a word the list's build holds mostly as a family word (`alves`, `pereira`, `silva`, `ferreira`, `rodrigues`, `santos`), 66,222 a word the build's boxes never hold (`donizeti`, `assuncao`, `trajano`), 15,249 a word it holds mostly as a given word but under the cut (`cezar`, `tadeu`, `bernardo`, `raimundo`, `mauricio`, `donizete`, `mateus`; ORCID's holders write `mateus` and `bernardo` as surnames in about a third of their uses), and 491 an initial or a connective written in one case (`e`). Over the 7,644 committed corpus names it moves 1,543, nearly all names of three words or more outside Portuguese, the switch's declared cost (rules/O6's Accepted). CLDR's `pt` file, which the locale view reads with `locales.PT_BR`: its native given-first renderings read as before; two foreign ones (`Zäzilia Hamish Stöber`, given first and surname first) newly disagree, and three that disagreed already now disagree in the family: in the two surname-first ones (the native `da Silva Sr. José Pedro Eduardo Jr., MP` and a foreign one) a title written after the family (`da Silva Sr.`) is taken as the second surname, as `locales.ES` under `FAMILY_FIRST` reads it already, and in the foreign given-first one (`Prof. Dr. Mary Lou Cesare Martín von Brühl …`) the given name `Martín` is taken as the first surname, as in `Zäzilia Hamish Stöber` (`cldr_agreement_locales.json`, re-recorded). The default parse and `locales.PT` move nothing: `snapshot.jsonl` gains one rule example's text, rules/S11's `JOSE CARLOS F`, and changes no reading. - **Not decided here:** a census source for Portugal's or Brazil's given names, which may replace the list; a rule for a family of three or more surnames (#1482); the words under the cut that Brazilian data writes as given names (`mateus`, `bernardo`, `tadeu`). Measured 2026-11-19 on master at 6560abde and the branch, Python 3.11, ORCID's extract of 2026-10-27, PatentsView's and PSC's caches as fetched, tse-donors as fetched. Recompute: `uv run python tools/pt_given_names.py --min-uses M --share S [--countries PT|BR]` prints a list (`awk '$1 ~ /^[0-9]+$/ || $1 == "c" {print $2}'` keeps the words); score it as `expr:parser_for(Locale(code="x", lexicon=Lexicon(given_names=open("LIST").read().split()), policy=locales.PT_PT.policy, languages=frozenset({"pt-PT"})))` beside `default` with `config_diff.py score --cap 3000 --group PT --group BR`, the comparator `default`, never the list measured; the per-country table is `config_diff.py score default plain:PT plain:PT_BR plain:PT_PT --cap 3000 --min 50` with `--group` each of PT, BR, CV, ST, GW, TL, AO, MZ, and `Portuguese`, `Brazilian`, `Angolan` for PSC, fixed and broken read from each configuration's `score_rows` counts against `default`; the shapes classify each record `local_agreement.read` marks wrong under `locales.PT_BR` by the family box's name words (particles and `e` not counted) against the parse's and by the first word the parse took, looked up in `tools/pt_given_names.py`'s `tally`; the tse-donors and committed moves are `config_diff.py diff 'expr:parser_for(Locale(code="old", lexicon=Lexicon.empty(), languages=frozenset({"pt-BR"})))' plain:PT_BR --local tse-donors --readings FILE` (and `--committed`), the expression being the pack as it shipped in 3.1. +- 2026-11-19 #1456, #1479 — ONE DIVISION FOR BOTH WRITINGS: A FAMILY OF TWO UNITS IS DIVIDED BY ITS OWN WORDS, BEHIND A FAMILY COMMA, A PARTICLE CHAIN AND A GIVEN NAME A PARTICLE COMPLETES. Decided on the two issues, to be built as one change (each issue's last comment): the two writings of one name return the same units wherever they yield the same family; the division is a function of the family's words alone, which the comma path and the comma-less path both call, and the units are marked by this rule, never read again inside the view. Questions this entry answers, the decisions taken on the issues restated only as far as the code needed them: + 1. **One place.** `_post_rules._divide_family` divides, and nothing else marks O6's units: after the take (which marked the two units it joined directly before), for a family that already held two words, for the family O9's capitals named (decisions/O9's entry of the same date), and, through `_divide_comma_family`, for the part before a family comma. The units are P1's fold units over the family in written order, `unit_ends(chain=False)`; exactly two are marked. The one obstacle to a text-order function was P6's particle attached at the end of a family-first name (`Beethoven Ludwig Maria van`), which belongs to the first unit though written last: the function sets an attached word aside and gives it to the first unit, so it is one place after all. + 2. **The comma.** The part before a family comma is divided only where it is the family's words alone: P1's fold and P6's attachment can take words from after the comma into the family (`Smith, de Mesnil Jean`), and those families are left whole. A part whose script sets an order other than the declared one (W4) is left whole, as the comma-less name is. No given-name list vetoes a word before the comma, the writer having marked both words as family (`Jorge Flores, Ana` divides under `locales.ES`, where `Ana Jorge Flores` keeps `Jorge` a middle name: the families differ, so the principle does not bind). A part of three name words is left whole. + 3. **A family opening with a particle: the particles and the one word they attach to, then the next word.** Measured before the rule was chosen, on the Spanish-speaking ORCID holders of #1479's recipe (`orcid-researchers`, holders in AR, BO, CL, CO, CR, CU, DO, EC, ES, GT, HN, MX, NI, PA, PE, PR, PY, SV, UY and VE with both boxes filled, 276,027 records, read under `parser_for(locales.ES)`), whose counts reproduce to within 4 (P10 shape 3,204 against #1479's 3,200, particle-led with two name words 1,756 exactly, with three or four 37 against 36; the hyphen and connective classes differ by how a hyphenated word is counted). Of the 1,756, 250 drawn at random (seed 1479) were read by hand: none is one surname of three words, every one a particle surname and a second surname (the commonest first units `de la Cruz` 171, `de León` 120, `da Silva` 54, `dos Santos` 50, `de la Rosa` 46); 3 hold a lone initial as the second unit (`de León C`), divided as `Gallegos G.` already was. The vocabulary chains a saint particle with its word, so `Santa Cruz` and `San Martín` are one unit (26 and 24 first units among the 1,756, and `San Martin` 13 more), and `de la Santa Cruz`, holding one name word, is never divided. What the rule gets wrong is a compound surname written with a particle and two name words, `de la Torre Ugarte`, which reads `de la Torre` and `Ugarte` (rules/R10's Accepted); none was in the sample. + 4. **Three name words behind a particle** (37 records) are left whole, as a plain family of three is: three units. + 5. **The family-first orders.** The take's family-first cut already divided a chain after a family-first family (2026-11-03 #1024); the comma form divides alike under all three orders, which `test_both_writings_of_one_family_read_the_same_units` holds. + 6. **The P10 shape was a defect**, not a decision: decisions/P10's entry of the same date. + 7. **A family ending in a standalone patronymic marker under the Turkic rule is left whole**: O2 reads the father's name and the marker of a three-word name as the family and R9 as the patronymic, one unit by decisions/O2's 2026-11-12 #1187 entry, which dividing a family that already held two words would have undone (`Ali Hasan oglu`, and `Hasan oglu, Ali`). The take built the same family in a five-word name and master divided it (`Ali Ahmad Vali Hasan oglu` gave surname1 `Hasan`, surname2 `oglu`); it is whole now too. + 8. **What moved that the issues did not ask.** Routing the take through the same function leaves whole a family the take built that it does not divide as two units: a lone particle as the first unit under a family-first order (`Del Piero Ortega` read `Del`, `Piero`, which rules/O6 and R11 accepted as an error; one unit now, and their Accepted clauses are reworded and deleted), a lone connective taken as a unit (`Carod i Rovira`), and, under a family-first order, a bound given-name word and the unit it completes (`Abd El Kader Haddou` read `Abd`, `El Kader`). Each was a wrong division on master; keeping master's marks there would have needed a second marking path. A first unit of particles alone is refused wherever it arises, not only after a take: `bin Abd Rahman`, whose suffix-tagged `Abd` stops the particle run, would otherwise read `bin` and `Abd Rahman`. A first unit is bare only where a word the vocabulary also lists as a suffix stops the particle run, so the refusal's reach is that shape: `de V, Ali`, which the branch's first build read `de` | `V`, and a particle before a credential under a family-first order (`VAN MD Ali`), whole again; a fix-commit review counted it over a grid of particles before every suffix word and bound word. + 9. **A bound given-name word counts with the word it completes**, whether or not it is also a particle and whether or not group kept P12's phrase tag on it, which it keeps only where it joined the pair (code review): `عبد الله حسن` divides `عبد الله` | `حسن` before a comma as without one, and `Abu Bakr Siddiq` alike, and `abdul Rahman Khan` before a comma (comma-less, `Ali abdul Rahman Khan` keeps the pair a middle name, O6 taking no bound pair, so its families differ); a bound pair behind a particle is the particle's one word (`de Umm Ali Hasan` divides `de Umm Ali` | `Hasan`, in both writings). `_family_word_count`, which decides whether O6 takes a word, still counts a bound pair as one only by P12's phrase tag, so `Juan abdul Rahman Khan` takes nothing and reads family `Khan` while `abdul Rahman Khan, Juan` divides: the families differ, so the two writings are not held to one division there. Given-first, `Abd El Kader Haddou` reads given `Abd` and family `El Kader Haddou`, which now divides (`El Kader` | `Haddou`), whole on master. + 10. **A hyphenated word is one unit beside a second surname**, as the take already counted it (`Andrés Sánchez-Cid Torres`, 2026-11-03 #959), so a family holding one beside a plain word divides where it is read without a take; a family that is one hyphenated word stays whole, the hyphen question decisions/R10 holds open. Seven ORCID families moved so: `de la Rubia Gómez-Moran`, `Aldámiz-Echevarría Iraurgui`, `Saint-Hilaire Tavares`, `Garciarena- Pedroso`, `-Acuña Hernández`, `Aguilar -G` (a stray hyphen read as a word) and `De la cruz-La rosa`, the last cut inside what its writer meant as two hyphen-joined surnames (`De la cruz` | `La rosa` read `De la cruz-La` | `rosa`), accepted as the writer's spacing. + - **Measured** 2026-11-19 on the branch against a checkout of `6560abde`, the master it was cut from (the final tree rebased onto `4b0b9441`, #1480, which reads every name of this population as `6560abde` does, the design-docs review re-running the dump on both), both trees parsing 296,151 names (every committed corpus name, every `tests/v2/cases.py` text, and the ORCID names and credit names above) under 13 configurations: the default; and the bare switch, `locales.ES`, the switch with `capitals_as_family` and the switch with `middle_as_family`, each under the three orders. No field, no ambiguity report and no `str()` moved in any configuration, and nothing moved under the default. The views moved, under `locales.ES` given-first, for 6,672 names: 3,270 behind a P10 given name, 2,312 particle-led, 1,028 before a family comma, all filled, and 62 emptied by item 8; under FAMILY_FIRST for 1,117 (1,018 before a comma, 6 particle-led, 93 emptied) and under FAMILY_FIRST_GIVEN_LAST for 1,116. The bare switch moved 6,671, 1,141 and 1,140; with `capitals_as_family` given-first 536 names moved that the bare switch did not move (a set difference), O9's family divided. On the ORCID records, the families read as the holder's box with two name words or more that are divided rose from 166,695 to 171,654; the P10 shape fell from 3,204 to 7 (each with three name words behind the phrase) and the particle-led two-word shape from 1,756 to 0. Of the credit names written with one comma whose two-word head is the holder's family box, 566 of 625 divide (0 before); in the other 59 either the comma is not read as a family comma (`González Ruiz, MA` reads `MA` as a credential) or the head is one unit (`Dos Santos, Priscila`). `local_agreement.py orcid-researchers --base` under the default matches the base; `cldr_agreement.py` matches every default record, and under the ES pack two `sorting` renderings now agree (`Pablo Pérez, Sr. Miguel Ángel Juan Antonio`), re-recorded. The principle's grid (`tests/v2/pipeline/test_post_rules.py`) holds 1,659 pairs whose two writings read one family, none disagreeing; with the comma's division switched off 1,241 disagree, and on `6560abde` 941. Frames per warm parse (`sys.setprofile` call events, py3.11): the default unchanged (the reference row 196, `Smith, John` 98, `Gabriel García Márquez` 159); under `locales.ES` `Gabriel García Márquez` 198 to 202, `García Márquez, Gabriel` 165 to 175, `Juan de la Vega Ruiz` 176 to 187, `María del Carmen García López` 256 to 264 and `Smith, John` 99 to 100, the cost being the marked words' copies. + - Recompute: the ORCID shape classes count a family's name words as the words that are no particle and no connective, each hyphen-joined part a word, with the parse's own tags (so a family `García-López` is a hyphen class of two name words, 16,630 undivided on `6560abde` and 16,623 now, where #1479's table, counting a hyphenated word as one, held 17); in each tree (the base imported with `PYTHONSAFEPATH=1` from outside the worktree, its `nameparser.__file__` asserted), parse every text of `tools/differential/corpus*.jsonl`, `tests/v2/cases.py` and the ORCID records named above with their credit names under each configuration, and compare the seven fields, the ambiguity kinds, `str()`, `surname1` and `surname2` name by name; a move is attributed to a shape by the parse's own roles (a family word before the first comma, a middle opening with a particle, a family opening with one). + - Open: whether a family a connective or a hyphen joins reads as two units, held by decisions/R10. diff --git a/docs/design/decisions/O9-words-in-capitals-as-the-family.md b/docs/design/decisions/O9-words-in-capitals-as-the-family.md index 698d45f53..117f25a45 100644 --- a/docs/design/decisions/O9-words-in-capitals-as-the-family.md +++ b/docs/design/decisions/O9-words-in-capitals-as-the-family.md @@ -36,3 +36,4 @@ Open: [#1402](https://github.com/derek73/python-nameparser/issues/1402) (a bare - **2026-11-12 #659, the FOURTH REVIEW — THE PEEL COMES BEFORE THE RUN IS CHOSEN, AND A MARKER IS NO CAPITALS WORD.** (A marker excluded in any position superseded by the FIFTH REVIEW entry, which excludes it only where another capitals word is left to be the family.) An independent code review of PR #1363 at 8b3ca491 (switch off byte-identical to the base over 591,210 rows) found three defects, each reproduced on that head. The run chosen was the last, and the peel worked inside it, so a credential a name word cut off from the family became the family (`DUPONT Marie MBA` read given `DUPONT`, family `MBA`; `DUPONT Marie JR`, `Marie DUPONT Jr. MBA`, `Marie DUPONT M.D. PHD` and `Marie DUPONT Esq. MBA` the same): the suffix slot is now read from the end before any run is chosen, past a suffix written otherwise, peeling a listed credential, generation or numeral in capitals wherever a capitals word that is no particle is left, and the last run of the words left is the family. Under a patronymic rule a marker written in capitals joined the family while the patronymic view claimed it (`ALIYEV Ilham Heydar OGLU` under `locales.TR_AZ` read family `OGLU`, patronymic `Heydar OGLU`; `Mehriban Arif QIZI PAŞAYEVA` family `QIZI PAŞAYEVA`; `ИВАНОВ Иван ИВАНОВИЧ` under the East Slavic rule family `ИВАНОВИЧ`): a word the rule in force reads as its marker is no capitals word, and a grid test holds that the switch moves no such word into the family. The invariant the review proposed, that the family and the patronymic view never share a word, does not hold with the switch off: R9 reads a Turkic marker with the word before it whatever field that word is in, and 5,648 of the grid's three-word rows share one with the switch off (measured 2026-11-12), which is R9's own reading. And `_assign`'s `order` report, which stands down for `initials_as_family`, survived where this rule acted (`Anna Q. MD`, `Vega Y. JR`): the THIRD REVIEW entry's drop covers it. The review's scaling finding: a quadratic in one run's length passed the row of four-word runs, so a long-run row holds one run's length at a base of 3,200 units, where a planted copy per word read 7.50x against the tree's 4.39x (the shared base of 800 let it pass at 4.83x), and the leading-conjunction trim no longer pops from the front. Recorded as accepted rather than changed: a lowercase conjunction chained into a unit beside the given name (`MARTIN y Ana Maria` → given `y Ana`, `MARTIN y Ana` → given `Ana`); a capitals word with any letters glued in front, a capital among them or not (`Jean-PIERRE`, `DuPONT`, `eBAY`); an empty part before a comma read by nothing (`, DUPONT Marie`); and shapes no list writes (`MARY III Smith`, `Mary AND AND AND SMITH`, `Anna Y MD Mary`, `de Marie DUPONT`'s initials `d. M. D.`). - **2026-11-12 #659, the FIFTH REVIEW — A MARKER STAYS THE FAMILY WHERE NOTHING ELSE CAN BE, AND A CONJUNCTION IS NO NAME WORD FOR THE PEEL.** An independent review of 39bf6d34 (switch off byte-identical to its parent over 893,256 parses) found three defects and a rule-text error. The FOURTH REVIEW's marker exclusion tested the spelling in any position, so a surname spelled like a marker lost the family where R9 reads no patronymic (`ABRAMOVICH Roman` and `АБРАМОВИЧ Роман` under the East Slavic rule read given `ABRAMOVICH`; `Ivan PETROVICH Smith` family `Smith`; `OGLU Ahmed` under the Turkic rule given `OGLU`): a marker is now left out of the run only where another capitals word that is no particle, conjunction or marker is left to be the family, and the grid test holds both directions. The peel's count of capitals words it must leave counted a conjunction, which the run then trims, so the switch stood down (`Hugo AND LAC` read given `Hugo AND LAC`; `Marie AND CPA`, `Anna OF MA`, `Marie THE LAC` the same; `John Smith AND MD` family `Smith AND`, suffix `MD`): it now passes a conjunction over by the same predicate the runs use. The peel tested membership against its list of peeled words, a quadratic (`Ann DUPONT` + `MBA` × N read 8.22x for 4x at 3,200): a set now, and a scaling row of trailing credentials holds it. The rule text that scoped S6's, S11's and O9's precedence to "the only word of its run" was wrong once the peel crosses the name (`DUPONT Marie MA`, `DUPONT Marie KC`, `DUPONT Jean FILS` read suffix): the scope is the only capitals word before the first comma that is no particle, conjunction or marker. Recorded as accepted: a lowercase joining word the parse read as a suffix ends the peel (`Ivan FAN R IVANOV MD de` → family `IVANOV MD`); `SIR John MD` → family `SIR`, suffix `MD`; a capitals word right before a marker in other case is both the family and the patronymic view's father's name (`AHMED Kyzy` under the Turkic rule, present in the parent too), so O9's precedence sentence now says the view is read over the words in their written order; and a joining word before a letter leaves the reports and the given-middle split to the order (`ALLIOT-MARIE Anna y V PhD`, present in the parent too). After this entry the rule is frozen for the first PR: a further unwritten shape is recorded, not handled. - **2026-11-12 #659, the RECORDED SHAPES — FOUR UNWRITTEN SHAPES KEPT AS THEY READ, AND THE PRECEDENCE SCOPE CORRECTED.** With the rule frozen, the shapes found after the FIFTH REVIEW are recorded in rules/O9's Accepted bullets rather than handled, the readings taken from the tree at c61f64b9: under the East Slavic rule `ABRAMOVICH Roman MBA` reads given `ABRAMOVICH`, middle `Roman`, family `MBA`, the marker exclusion asking whether another capitals word is left before the peel takes the credential (`ABRAMOVICH Roman, MBA` and `IVANOV Roman MBA` read family `ABRAMOVICH` and `IVANOV`); under the Turkic rule, with O2's three-word reading merged from #1187, `Aidai MEDERBEK kyzy` reads family `MEDERBEK`, middle `kyzy`, and `Aidai Mederbek KYZY` family `KYZY`, middle `Mederbek`, where the switch off reads family `MEDERBEK kyzy` and `Mederbek KYZY` (the four-word `ALIYEV Ali Ahmad oglu` is unchanged, family `ALIYEV`); `Hugo AND LAC` reads given `Hugo AND`; `Ivan PETROVICH IVANOVICH` under the East Slavic rule reads family `PETROVICH IVANOVICH` and no patronymic; and `DR ABRAMOVICH Roman` reads family `DR`, given `ABRAMOVICH` under that rule and family `DR ABRAMOVICH` without it. None is written in any cached list (the parliaments' Turkic names are four words, the family in capitals). The first two are pinned by test rows stating the accepted reading. The FIFTH REVIEW's scope for S6's, S11's and O9's precedence, "the only capitals word before the first comma that is no particle, conjunction or marker", misdescribed two shapes: a numeral after the word is no capitals word the peel must leave (`Jean Pierre FILS III` → family `FILS`, suffix `III`), and of two listed credentials ending the name the first is the family where nothing before it can be (`Marie MA MBA` → family `MA`, suffix `MBA`). The scope now reads: the word ending the name is the family where no other capitals word before it and before the first comma can be, the listed credentials and numerals after it coming off first. No reading moved. +- 2026-11-19 #1456, #1479 — O6 DIVIDES THE FAMILY THE CAPITALS NAMED. With both switches on, O6 still takes no word into a family this rule named, and now divides that family by its own words where it holds two units (`Ana GARCÍA LÓPEZ` gives surname1 `GARCÍA`, surname2 `LÓPEZ`), as it divides every family since decisions/O6's 2026-11-19 #1456, #1479 entry: the division is a function of the family's words, so it does not ask which rule read them. No field moves. Where this rule misreads given names in capitals as the family (`ABRAHAM ELEAZAR Quipuscoa Jiménez`), the division divides them too. diff --git a/docs/design/decisions/P10-given-name-a-particle-completes.md b/docs/design/decisions/P10-given-name-a-particle-completes.md index 726a783d7..f4b1804c6 100644 --- a/docs/design/decisions/P10-given-name-a-particle-completes.md +++ b/docs/design/decisions/P10-given-name-a-particle-completes.md @@ -49,3 +49,4 @@ Open: Catalan `dels` (`Maria dels Àngels Puig`). decisions/O7 kept it out of `c - **The strict Portuguese readings.** `pt.toml` gains its own reading of the words `es.toml` marks that pass on the Portuguese-speaking countries' names, scored under `parser_for(locales.PT, strict=True)` with and without the reading: `fátima` 479 to 88 (84%), `fatima` 134 to 36 (79%), `socorro` 149 to 24 (86%), `lourdes` 149 to 16 (90%), `maria` 21 to 6 (78%). The first draft scored them under the default's particles and also marked `carmen` (35 to 0) and `pilar` (20 to 3), whose names there are Spanish `del Carmen` and `del Pilar`: under the strict choice, which holds no `del`, they score 1 to 0 and 0 to 2, and `angeles` (10 to 0 by default, `de los Angeles`) 1 to 0 (found by the design-docs review). Still failing under it: `rocio` 16 to 9, `rosario` 6 to 8, `jesús` 6 to 3. A word may hold a `given` reading in two files: a name reading triggers no preference between them, and the build refuses it only beside a `mul.toml` reading (check 13). Weighed: leaving it, a strict choice reading only the files it names, against the readings, chosen, since the words are Portuguese names' too and the counts that mark them are Portuguese. - **Measured** (2026-11-06, the tree against `origin/master` `b1d3d210` read with `--base`, py3.11). ORCID's capped corpus by default: 24 fixed, 6 broken, 12 changed agreeing in neither; under `--locale pt_br`: 0 fixed, 1 broken (`Karina | de Kassia Abreu`, `kassia` unmarked). PSC: 6 fixed (`Francisco | Da Graca | Geraldes`), 1 broken (`Angelita | Da Graca Brenzink`), 1 changed. `snapshot.py --local tse-donors --base` moves 1,187 of 854,531 names, in family and middle alone (`ADRIANA DAS GRACAS LIMA`, `AMANDA DE CASSIA LOPES`). The committed snapshot moves the rule's two default examples, and the `da Piedade` examples join it. - Recompute: for each word, the ORCID extract's records (`local_orcid.extract_path()`) from BR PT AO MZ CV GW ST TL, and from ES MX AR CO CL PE VE EC UY BO PY CR GT CU DO HN SV NI PA PR AD, with both boxes filled, whose `given family`, NFC lower case with edge periods and commas stripped, holds the word behind a word of `Lexicon.default()._sets.particles`; each parsed with `Lexicon.default()` and with `.remove(word, kind="given")` (for the pack words, `parser_for(locales.PT).lexicon` and its removal; for the strict readings, the Portuguese-speaking countries alone, `parser_for(locales.PT, strict=True)`, its lexicon's particles, and its lexicon with `.remove(word, kind="given")`, or `.add(word, kind="given", after_particle=True)` for a word it does not mark, each beside its policy), a parse agreeing where its given and middle joined equal the given box and its family the family box, case-folded; fixed where only the reading's parse agrees, broken where only the other's. The rows with the commands above, `--base` a `git archive` export of `b1d3d210`. +- 2026-11-19 #1479 — THE FAMILY A PHRASE LEAVES IS DIVIDED AS ANY FAMILY IS. #1479 asked whether the second surname missing behind a P10 phrase (`María del Carmen García López` under `two_family_names`, surname2 '') was a defect or a decision. Neither this file nor decisions/O6 or decisions/R10 recorded a decision: the Accepted clause it rested on described how the parse got there, P2's chain `del Carmen García López` leaving O6 a family of two words that O6 took nothing into and so marked nothing in, and gave no reason to want it. A defect, then, fixed with #1456 by dividing every family by its own words (decisions/O6's 2026-11-19 #1456, #1479 entry): the family gives surname1 `García`, surname2 `López`. Measured on Spanish-speaking ORCID holders under `locales.ES`, the shape held 3,204 records whose family the parser read as the holder's family box, all but 7 (three name words behind the phrase) divided now. The clause is replaced by an example under the rule's O6 Precedence. diff --git a/docs/design/decisions/R10-second-surname-view.md b/docs/design/decisions/R10-second-surname-view.md index 61b5f0b13..5b177f195 100644 --- a/docs/design/decisions/R10-second-surname-view.md +++ b/docs/design/decisions/R10-second-surname-view.md @@ -4,6 +4,7 @@ - `ParsedName.surname2` holds the family's second name unit where rules/O6 read the family as two (and, since 2026-11-06 #845, where rules/W5 reads a Han surname pair, decisions/W5), and is empty otherwise; it is a view, not a role, so `family`, `surnames`, `as_dict()`, `replace()`'s fields and the repr are unchanged, item 5 of decisions/vocabulary-model's 2026-10-28 #754 output-model entry — 2026-10-29 #754, sub-phase 4d. - O6's mark is a private tag that assemble drops, carried out on `Reading.second_surname`, a field `Token.reading`'s readings gained and that is not compared, where the RFC had a stable tag: a published tag would make an O6 parse unequal to its own 2.x pickle — 2026-10-29 #754, sub-phase 4d. +- The view is filled wherever O6 divides the family into two units, and O6 divides a family by its own words however it was read: before a family comma, where a particle chain made it, and behind a given name a particle completes, as without them; a family a connective joins, or a hyphen makes one word, stays one unit (Open), where a hyphenated word beside a plain word is a unit of its own and divides, as the take always counted it (decisions/O6's entry of the same date, item 10) — 2026-11-19 #1456, #1479. Elsewhere: why the second surname is a view of `family` rather than a role, the ORCID measurements behind it, and the `surnames` redefinition declined, decisions/vocabulary-model's 2026-10-28 #754 entry, item 5; how O6 counts a family's words and which names it declines, decisions/O6; the first unit's views, `surname1` and its particles and base, decisions/R11 (#1022). @@ -17,3 +18,4 @@ Open: whether a family a connective or a hyphen joins (`Ortega y Gasset`, `Garc 3. **The word keeps the reading it took**, the mark set on it, so a patronymic run in the second unit reads in both views (`Ali Hassan bin Ahmad` gives surname2 and patronymic `bin Ahmad`), as does a word P6's attached patronymic particle makes the parent's name (`Mohamad Ali Mahathir bin` under FAMILY_FIRST). Assemble reads the word as it reads without the mark, so no reading's kind, source or files moves: over 1,296 parses of 36 names under each order, with and without `middle_as_family`, `two_family_names` and the RU and TR_AZ packs, tokens, tags and readings match the base apart from the new field. 4. **The view stays out of `as_dict()`, `--json`, `comparison_key()` and the repr**, as R8's and R9's do, and is a `render()` key and an assertable field of a rule's example lines, whose grammar now takes a digit in a field name. The snapshot records it where it is not empty (`tools/differential/snapshot.py`'s `SURNAME2_VIEW`), which no row is, since the snapshot parses the default policy; `tools/differential/cldr_agreement.py` scores it on its own beside the merged `family`, as its PENDING_ROLES were written to. - Measured 2026-10-29 on the 4d branch over `8a1e6f5f`. The committed snapshot's 6,601 readings of the base: no row moves and none gains the key; the header names `surname2` among the recorded views, and rules/R10's examples add two names, 6,603 readings in all. The agreement records gain only `surname2` entries, each a second surname stated and not read, the default never reading one: CLDR 117 (`cldr_agreement.json`, most of them the `foreignFull` samples' two-word second surnames, `González Domingo`) and 22 more lines in the locale record, Wikidata 330 (its `surname2-es` 150, `surname2-mx` 100, `surname2-co` 80), conventions 2. With `two_family_names` on and each rendering's order kept, the view agrees on 263 of Wikidata's 330 (es 97, mx 91, co 75), on 7 of CLDR's 117 and on neither conventions row, and `family` on 318 of Wikidata's 330 against 55 under the default. The switch's cost on the renderings stating none: of each source's renderings whose expected `surname2` is empty, it gives one to CLDR 700 of 2,523 (`Prof. dr. Cornelia Margarita Sofia Aletta van den Berg jnr., MBChB PhD` reads 'van den Berg'), 102 of them the 252 renderings of a name CLDR states a second surname for that leave it out, Wikidata 160 of 338 (its patronymic strata, `Любовь Митрофановна Шуляк` reading 'Шуляк'), GND 107 of 801, the native-script source 39 of 1,027 and conventions 15 of 28. Recompute: for each row of a fields file, parse its text with `cldr_agreement._parser(None, shape)` and with the same parser's policy given `two_family_names=True`; where `expected_roles(...)` states a `surname2`, compare `.surname2` and `.family` with it by `same`, and where it states none, count the renderings whose `.surname2` is not empty. Frames per parse (`sys.setprofile` call events, a warm parse): the reference row `Dr. Juan0001 de la Vega III` 310.1 and `Gabriel García Márquez` 258 on both trees under the default policy; under `two_family_names`, `Gabriel García Márquez` 284 to 286 and `Juan Pérez de la Vega` 330 to 334, one copy per marked word and one for the marking call, and `García Márquez Gabriel` under FAMILY_FIRST 291 on both. A first draft that rebuilt each marked token at the end of assemble, and read the word with the mark among its tags, cost 13 frames for one word and 35 for three. +- 2026-11-19 #1456, #1479 — THE VIEW FOLLOWS ONE DIVISION, WHICHEVER WAY THE FAMILY WAS WRITTEN. Decided on the two issues (each issue's last comment): the two writings of one name return the same units wherever they yield the same family. The two Accepted clauses that left the view empty go: "a family comma marks nothing", and the particle chain in "where a connective, a hyphen or a particle chain already joins two family names". The connective and the hyphen that makes two names one word (`García-López`) stay, as the Open line asks, decided apart (a hyphenated word beside a plain one, `Sánchez-Cid Torres`, is a unit of its own and divides, decisions/O6's entry of the same date, item 10): both are written by the writer with the switch off too, and neither was measured here beyond its count in #1479's table (95 records with a connective, 17 with a hyphen beside other words, a hyphenated word counted as one; decisions/O6's entry of the same date counts the hyphen class otherwise, by its parts, and gives that recipe). How the family is divided and what was measured: decisions/O6's 2026-11-19 #1456, #1479 entry. The view itself is unchanged: it still reads the mark O6 leaves, and no reading of the family's words happens inside it. diff --git a/docs/design/decisions/R11-first-surname-views.md b/docs/design/decisions/R11-first-surname-views.md index 19bf7cffa..0c20dee09 100644 --- a/docs/design/decisions/R11-first-surname-views.md +++ b/docs/design/decisions/R11-first-surname-views.md @@ -7,6 +7,7 @@ - `initials()` keeps reading the whole family's base — 2026-11-03 #1022 (Derek), THE FIRST SURNAME GETS VIEWS OF ITS OWN. - The views are `render()` keys and assertable fields of a rule's examples, and stay out of `as_dict()`, `--json`, `comparison_key()`, the repr and the snapshot — 2026-11-03 #1022 (Derek), THE FIRST SURNAME GETS VIEWS OF ITS OWN. - O6 marks the first unit's words as it marks the second's, and where O6 marked none O3 marks the family it folds into, carried out on `Reading.first_surname`, a field not compared — 2026-11-03 #1022 (Derek), THE FIRST SURNAME GETS VIEWS OF ITS OWN; 2026-11-03 #1022 (Derek), FOLLOW-UP TO QUESTION 2. +- A family whose first word is a lone particle and whose second is the word after it, under a family-first order, is one unit, the division counting the particle with the word after it; 3.0 and 3.1 read the particle as a first unit of its own with an empty base — 2026-11-19 #1456, #1479. Elsewhere: the second unit's view and how O6 marks it, decisions/R10; what CLDR's person-name fields are and the render patterns a pack may carry, the vocabulary-model RFC's render-pattern table; how O6 counts a family's words, decisions/O6. @@ -20,3 +21,4 @@ Elsewhere: the second unit's view and how O6 marks it, decisions/R10; what CLDR' - **How the first unit is known.** O6 runs after P6 and before O3, so the family words it does not mark second are exactly the first unit when it marks; it now marks them too (`vocab:first-surname`, private, dropped at assemble) and `Reading.first_surname` carries the mark out, `ADDED_IN` 3.0.0 and not compared, as `Reading.second_surname` does. The view could not tell O3's fold from P6's attachment on a finished parse otherwise: both carry `FOLDED_TAG`, and P6's `ATTACHED_TAG` is dropped at assemble, a published tag making a parse unequal to its 2.x pickle (decisions/R10's 2026-10-29 entry, item 1). A word's reading kind does not tell them apart either, an O3-folded middle particle reading `particle` as P6's does. - 2026-11-03 #1022 (Derek), FOLLOW-UP TO QUESTION 2 — A FOLD'S MIDDLES ARE LEFT OUT OF THE FIRST SURNAME WHERE O6 READ ONE UNIT TOO. As first built, the views left O3's folded middles out only where O6 had marked two units, and read the whole family elsewhere, so `García López, Ana María` under `two_family_names` and `middle_as_family` gave surname1 'María García López', and `Ana María García López` under `middle_as_family` alone 'María García López'; the prototype question 2 was measured on had left them out everywhere, so the recipe as first written gave 262 where the entry said 264 (the design-docs review). Decided: left out always, the first surname being the family as it stood before the fold — 'García López' and 'López' (the family before that fold is `López`, `García` being a middle name; the question as put named 'García López', in error). Where O6 marked no units, O3 marks the family it folds into with the first-unit mark before folding, a copy per family word on a parse that folds a middle and on no other. Measured on the shipped views, the figures of question 2 are as stated. - 2026-11-03 #1022, A FIRST UNIT OF A LONE PARTICLE SPLITS AS THE FAMILY DOES; READING IT AS ITS OWN BASE WAS TRIED AND BACKED OUT. Under a family-first order O6 reads `van Gogh Vincent` as family 'van Gogh', first unit 'van', which splits as particles 'van' and base '' (the code review). Reading such a unit's words as name words, as rules/R2 reads an all-particle part, was built and backed out the same day (the fix review): the family view reads `van` as a working particle, the family not being all particles, so the units' particles and bases stopped adding up to the family's (`von Brühl González Domingo Ada Cornelia` family-first under `two_family_names`: family_particles 'von', family_base 'Brühl', against surname1_particles '' and surname1_base 'von'), and over CLDR 48's renderings parsed under `locales.ES` it moved 31 (29 `von`, one `bin`, one `da`), each now disagreeing on `surname1_particles` where it had agreed (agreement 165 to 134 of 369), `surname1_base` unchanged at 125. The misreading is O6's, which splits a particle from the name it precedes; rules/R11's Accepted records the empty base. Also accepted there: a fold into a family a family comma left empty (`, John Paul` under `middle_as_family`, family 'Paul'), where nothing is marked and the folded word is the views. Frame cost of the O3 mark (fix review, py3.11): +5 to +10 frames on a `middle_as_family` parse that folds a middle (`Ana María García López` 305 to 311), nothing on any other; no guard covers `middle_as_family`. +- 2026-11-19 #1456, #1479 — THE FIRST UNIT IS O6'S ONE DIVISION, BEHIND A COMMA TOO. The first-surname views read the mark O6's division leaves (decisions/O6's 2026-11-19 #1456, #1479 entry), so they divide the part before a family comma (`Pérez de la Vega, Juan` gives surname1 `Pérez`, surname1_base `Pérez`, where 3.0 and 3.1 gave `Pérez de la Vega` and `Pérez Vega`) and a family a particle chain or a P10 phrase left. The Accepted clause on a first unit of a lone particle is deleted, the shape no longer read: the division counts a particle with the word it attaches to, so `Van Gogh Vincent` under FAMILY_FIRST with the switch gives surname1 `Van Gogh`, base `Gogh`, where 3.0 and 3.1 gave `Van` with an empty base. And the clause naming a family comma among what leaves the views the family's is narrowed to a connective and a hyphen. diff --git a/docs/design/decisions/vocabulary-model.md b/docs/design/decisions/vocabulary-model.md index 44bc7538a..ac0e46103 100644 --- a/docs/design/decisions/vocabulary-model.md +++ b/docs/design/decisions/vocabulary-model.md @@ -305,7 +305,7 @@ Open: [#1145](https://github.com/derek73/python-nameparser/issues/1145), the dis 2. **`Token.reading`, the reading each token took**, a `Reading` (decisions/A1's type), `None` for a token `replace()` builds, with `ADDED_IN` metadata so a 2.x pickle loads, and left out of comparison so `==` keeps its 2.x meaning. `Reading` gains `languages`, the files holding the reading, filled from phase 3's reading index (3a) and empty where no file holds it; `ReadingKind` gains `PATRONYMIC`. The views read it. It carries out the 2026-10-23 #752 entry's item 13 and the 2026-10-26 phase 2m entry's deferral of the languages. 3. **A `patronymic` view, filled by a word or a rule that says patronymic, with `family` and `middle` unchanged.** The default fills it from the vocabulary's `patronymic` particles (`bin`, `binti`, `ibn`, `bint`, `bar`, `bat` and the native-script forms) with the name they introduce (`Mahathir bin Mohamad` → family `bin Mohamad`, as today, and patronymic `bin Mohamad`); RU's and TR_AZ's rules fill it where a caller turns them on (`Ivan Ivanovich Ivanov` under RU → middle `Ivanovich` and patronymic `Ivanovich`); an Icelandic ending rule fills it under an `is` pack only, since the default cannot tell `-dóttir` and `-son` from Swedish surnames (ORCID's Swedish records end their family box in `-son` or `-dóttir` in 2,184 of 20,000). A matronymic, written the same way, fills it too. SUPERSEDES: the RFC's earlier statement of decision 8's value, that `family` can be empty for a name with a patronymic. Measured: filers put an Icelandic patronymic in the family box (ORCID 1,647 of 2,583 Icelandic records, PatentsView 535 of 722, PSC 101 of 125), and CLDR's `is` file's 3 Icelandic samples put it in `surname` or `surname-core` in all 9 of their renderings (its one foreign sample puts a `-dóttir` word in `surname2`), while Wikidata's `patronymic-is` and `patronymic-my` strata record 108 names with a patronymic and no family name, of which the parse puts the patronymic in `family` 107 times. An East Slavic patronymic stands in the given part: CLDR's 2 `ru` samples put it in `given2` in all 6 renderings; PatentsView's Russian given boxes end in one 8,423 times of 20,000, and the parse reads such a word as the middle 10,902 times of 10,962; 90 of the 112 Russian nationals in PSC who filled the middle-name box wrote one there. A `family` that keeps it and a `patronymic` that names it agree with both kinds of source. Weighed against: emptying `family` where the patronymic is recognized, which moves the field the fielded sources fill and changes `family` for every Icelandic and nasab name, a behavior change of a frozen property; and a neutral parent-names name for the view, which buys nothing the view can detect, since a matronymic and a patronymic are written alike. 4. **`generation` and `credentials` are views that partition `suffix` (#326)**, not roles, `generation` the tokens read as a generation or an agnomen, `credentials` the rest, the post-nominals that are neither (`Esq.`, the honorifics after a name) falling in `credentials`, CLDR's catch-all, with `Token.reading.kind` telling them apart for a caller who needs it. Measured: of the 1,054 committed corpus entries with a suffix, 33 hold a generation (or agnomen) and a listed credential together, 77 a generation beside any other suffix word, and 64 only listed post-nominals of other kinds (each suffix word classified by the RFC's Phase 4 recipe, joined tokens merged); of the 615 CLDR renderings with either field, the 75 whose suffix holds exactly CLDR's words split into CLDR's `generation` and `credentials` by the vocabulary's reading kind in all 75. Weighed against: two new `Role` members (item 1), and a third view for the honorifics, left open since CLDR has none. - 5. **a `surname2` view, the family's second unit where rules/O6 read the family as two**, marked by a new stable tag where O6 takes its word, empty otherwise; `family` keeps both units as O6 makes it, and a family comma alone marks nothing (`Lloyd Webber, Andrew`). Measured: a two-word family box in ORCID's records from Spain 48.0%, Mexico 64.7%, Colombia 72.8% and Chile 50.5%, against 3.9% from the United States. Left open: a view for the first unit and its name, `surname` standing close to the `surnames` view that exists. Declined: redefining `surnames` as the two units, which would repeat `family`, the family holding both where O6 reads two, and lose what `surnames` does today, joining `middle` and `family` so that a double surname the default splits (`Gabriel García Márquez` → middle `García`) reads whole, the view rules/P2 names for that reading. + 5. **a `surname2` view, the family's second unit where rules/O6 read the family as two**, marked by a new stable tag where O6 takes its word, empty otherwise; `family` keeps both units as O6 makes it, and a family comma alone marks nothing (`Lloyd Webber, Andrew`; superseded by decisions/O6's 2026-11-19 #1456, #1479 entry, which divides the part before a family comma as the comma-less family is). Measured: a two-word family box in ORCID's records from Spain 48.0%, Mexico 64.7%, Colombia 72.8% and Chile 50.5%, against 3.9% from the United States. Left open: a view for the first unit and its name, `surname` standing close to the `surnames` view that exists. Declined: redefining `surnames` as the two units, which would repeat `family`, the family holding both where O6 reads two, and lose what `surnames` does today, joining `middle` and `family` so that a double surname the default splits (`Gabriel García Márquez` → middle `García`) reads whole, the view rules/P2 names for that reading. 6. **The render defaults follow the order the name was read in, a behavior change of the output rather than a break of the API.** `ParsedName` gains `order` (an addition, `ADDED_IN`, a 2.x pickle rendering as today, left out of comparison, which lets two equal names render differently, a cost accepted 2026-10-28: a 2.x pickle of `김민준` renders `'민준 김'` and a fresh parse `'김민준'`, and the two compare equal); the default `str()` and `render()` spec put the family first where `order` does, and join two words that stand one directly after the other, in the same order, in the original and the rendering with the kind of separator that stood between them there, normalized, decided 2026-10-28 (nothing; one ASCII space for any whitespace, the ideographic space U+3000 included (`山田 太郎` → `'山田 太郎'`, where today gives `'太郎 山田'`); an interpunct or a nakaguro the parse read as a separator alone, a spaced interpunct being a name word, rules/T3; one comma the parse reads as `, ` if ASCII, `، ` if Arabic and alone if full-width, since a full-width comma carries its own width in CJK text, a reason for the comma the rendering keeps and not for the whitespace it normalizes (the Japanese comma U+3001 is no comma to the parse, a parser question outside this design), so `John Smith ,Jr.` renders `'John Smith, Jr.'`; the written whitespace staying in `ParsedName.original` and the token spans), the spec's decoration between the two words' fields standing instead (the nickname's quotes, the `) ` after a maiden name), and any other pair or separator (a delimiter, a consumed marker word, two or more commas, a hyphen, a slash, a zero-width or directional mark) taking the spec's own joiner; `initials()` gives nothing for a word in a script with no initials. A name with a family comma or written given-first keeps today's word order and its separators by the same rule, a suffix comma alone leaving a family-first name family-first (`威廉·莎士比亚` keeps its dot; 20 of the 36 names whose interpunct `str()` drops are read given-first). A family comma is never kept, the rendering reversing its pair (`Smith, John` → `'John Smith'`), and one directly between the family and its suffix is, decided 2026-10-28 (`John Smith, Jr.` → `'John Smith, Jr.'`, today `'John Smith Jr.'`; 214 of the 1,003 committed corpus entries whose suffix follows the family write one there). Accepted with it: `Smith, John, Jr.`, whose suffix the rendering moves away from the given name before it, keeps `'John Smith Jr.'`, so two writings of one name render differently. Measured over the committed corpus's distinct entries, the counts reading the ASCII comma (the RFC gives the full-width and Arabic ones: 36 of the 728 hold a family comma the parse reads and keep today's word order): 728 without a comma read family-first, `str()` renders all 728 differently from their text (`김민준` → `'민준 김'`), 150 of them with the family's last word touching the given name's first, and it drops the U+00B7 interpunct from 36 of the 41 holding one. This carries out decisions/3-0-reevaluations' render-default clean slate. Decided with it on 2026-10-28 (the RFC's Phase 4 Render defaults): `render(spec: str | None = None)`, `None` the order-aware default `str()` passes and a caller's spec rendering exactly as written, so `render("{given} {family}")` keeps its 2.x meaning and a caller passing 2.x's default string keeps given-first output. Decided too: a family-first layout with the title first, the suffix last and the name roles in `order`'s sequence, each with its decoration, a family-comma name keeping a given-first `order`. The signature is a change, not an addition as the freeze defines one (no working call changes meaning, `render(None)` raising today, but the default's introspection and a subclass override typed `spec: str` do), Derek taking it as worth that and waiving its 2.x warning (decisions/3-0-reevaluations, THE RENDER SIGNATURE). The title stays first though 50 of CLDR's 70 surnameFirst renderings with a title put it after the surname, because the default renders only an order the parse reads back, and under a family-first order the parse reads a bare title only at the front (`Wang Dr Xiaoming` → given `Dr`, `Wang Xiaoming Senator` → middle `Senator`); reading a title where CLDR writes it is a parser question, #938, and the default may follow it (#938 declined 2026-10-30, real family-first names writing the title in front: decisions/H5's 2026-10-30 #938 entry). Apart from that signature, no signature changes, but `str()`'s output changes for every name read family-first, every name whose words are written with nothing, an interpunct or a nakaguro between two words the rendering keeps side by side, and every name with one comma directly between its family and its suffix, and no 2.x release can warn about a `str()` result, so it is taken as an improvement for 3.0's release notes, not a break needing a warning. 7. **`middle` keeps its meaning (#704)**, every word of the given part after the given name, the given name one unit unless a rule joins words into it, as rules/P5 already does (`Abdul Aziz Tariq` → given `Abdul Aziz`); a compound given name is a `[rules]` rule a caller or a pack turns on, CLDR's `given2` is `middle`, and `Kaur` stays in `middle`, as under FAMILY_FIRST does an English name after a Chinese one (`Lim Mei Ling Jessica` → middle `Ling Jessica`), an accepted cost. Measured: in PSC, whose form has a middle-name box, 2,499 of 1,040,708 forename boxes hold two or more words, and of 6,101 Spanish nationals 25 do while 2,621 fill the middle box; ORCID's and PatentsView's given box holds middles too, so it cannot separate the two. The `Maria do Carmo` shape, a particle inside a given box of three or more words with a family box filled, reads the given box's words into the family in 1,812 of 1,923 ORCID records and 1,165 of 1,219 PatentsView records from Brazil, Portugal, Spain, Mexico, Argentina, Colombia, Chile and Italy, which is that rule's case. Weighed against: #704's option (b), one given unit by default, which changes `middle` for every English name of three words. 8. **A language file's `[rules]` compiles into its shipped `Locale`'s policy patch**, each rule kind a `Policy` field (an addition), so RU and TR_AZ are rebuilt from their files and `Locale` gains no field for rules. With it, **phase 3's open API dependency is answered**: its design (the 2026-10-27 #753 entry, item 1) carries a choice of languages on `Locale.languages`, assuming `Locale` and `Policy` keep their 2.x shape after the facade's removal, and the 2026-10-28 freeze keeps them so. The rest of that design, strict as an argument of the whole choice included, stays phase 3's to decide; its RFC section records the dependency as answered. diff --git a/docs/design/rules/O6-two-family-names.md b/docs/design/rules/O6-two-family-names.md index 74feae671..5a64f9a2f 100644 --- a/docs/design/rules/O6-two-family-names.md +++ b/docs/design/rules/O6-two-family-names.md @@ -1,6 +1,6 @@ # O6 — two family names -**When:** two-family-name handling is active and a name with no family comma has three or more name words, as in "Gabriel García Márquez". +**When:** two-family-name handling is active and a name with no family comma has three or more name words, as in "Gabriel García Márquez", or the family read, with or without a family comma, holds two name units. **Then:** the family name takes the name word beside it, so the last two name words are the family — the first two under a family-first order. @@ -36,6 +36,24 @@ "Gabriel García Márquez" two_family_names → surname2="Márquez" "García Márquez Gabriel" family-first+two_family_names → surname2="Márquez" ``` +- **A family is divided by its own words, however it was read**: counted as P1's fold counts a unit, a particle run with the one name word it attaches to and a bound given-name word with the word it completes, and divided where it holds exactly two, a first unit of particles alone being no first surname, whether the rule took a word into it, it already held two words, or a family comma named it, so the two writings of one family give the same units. + ``` + "Juan de la Vega Ruiz" two_family_names → surname2="Ruiz" + "Juan de la Vega Ruiz" two_family_names → surname1="de la Vega" + "María del Carmen García López" two_family_names → surname2="López" + "García Márquez, Juan" two_family_names → surname2="Márquez" + "de la Vega Ruiz, Juan" two_family_names → surname2="Ruiz" + "Juan de la Vega Ruiz Soto" two_family_names → surname2="" + "عبد الله حسن, علي" two_family_names → surname2="حسن" + "bin Abd Rahman, Ahmad" two_family_names → surname2="" + "García Márquez, Juan" → surname2="" · boundary + ``` +- **A family ending in a standalone patronymic marker under the Turkic patronymic rule is one unit**: the father's name and the marker, which O2 reads as the family of a three-word name and R9 as the patronymic, before a comma too. + ``` + "Ali Hasan oglu" two_family_names+turkic → surname2="" + "Hasan oglu, Ali" two_family_names+turkic → surname1="Hasan oglu" + "Hasan oglu, Ali" two_family_names → surname2="oglu" · boundary + ``` - **Titles, suffixes and nicknames are no name words**, and a comma that sets off only suffixes leaves the name before it to this rule. ``` "Gabriel García Márquez Jr." two_family_names → family="García Márquez" @@ -53,7 +71,7 @@ **Except:** -- **A family that already holds two words keeps what it has**: words a connective joins count as their words, a hyphen joins two words without making them one, and a particle chain counts the words it chained. +- **A family that already holds two words keeps what it has**: words a connective joins count as their words, a hyphen joins two words without making them one, and a particle chain counts the words it chained. Nothing is taken, and the family is divided by its own words (above), a connective's and a hyphenated word's left whole. ``` "José María Ortega y Gasset" two_family_names → family="Ortega y Gasset" "Ana María García-López" two_family_names → family="García-López" @@ -61,10 +79,14 @@ "Ana María García-López" two_family_names → family="García-López" "Ana María de la Vega Rodríguez" two_family_names → family="de la Vega Rodríguez" ``` -- **A family comma decides by itself**, so the part before it is the whole family. +- **A family comma decides by itself**, so the part before it is the whole family, divided as a family is (above) where nothing after the comma joined it: no given name the caller lists vetoes a word there, the writer having marked both as family, and a part of three name words is left whole. ``` "López, Ana García" two_family_names → family="López" "García López, Ana" two_family_names → family="García López" + "García López, Ana" two_family_names → surname2="López" + "Martín López, Ana" two_family_names+es_given_names → surname1="Martín" + "García Márquez López, Juan" two_family_names → surname2="" + "Smith, de Mesnil Jean" two_family_names → surname2="" ``` - **A family comma with nothing before it still names no family** (C15), and the name after it reads as the default reads it. ``` @@ -88,9 +110,10 @@ "Pérez de la Vega" family-first+two_family_names → family="Pérez" "Pérez de la Vega y Santos Juan" family-first+two_family_names → given="de la Vega y Santos Juan" ``` -- **A given name a particle completes stays where it is**: given-first, a particle run and the word behind it that the vocabulary names a given name written that way (P10), standing beside a given name of one word, are the given name's second, not a surname. Under a family-first order the unit after the family completes no given name, and is taken as before. +- **A given name a particle completes stays where it is**: given-first, a particle run and the word behind it that the vocabulary names a given name written that way (P10), standing beside a given name of one word, are the given name's second, not a surname. Under a family-first order the unit after the family completes no given name, and is taken as before. The family the phrase leaves behind is divided as a family is (above). ``` "María del Carmen de la Vega" two_family_names → middle="del Carmen" + "María del Carmen García López" two_family_names → surname1="García" "Ana de Miguel de la Vega" two_family_names → family="de Miguel de la Vega" · boundary "Juan Antonio del Valle de la Vega" two_family_names → family="del Valle de la Vega" · boundary "García del Valle María" family-first+two_family_names → family="García del Valle" · boundary @@ -139,10 +162,12 @@ ``` "Petrov Ivan Sergeevich" family-first+two_family_names → family="Petrov Ivan" ``` -- A lone particle the declared order left as the family counts as one word, R2 reading it as an ordinary name word, so the word after it joins, and so does a particle chain after it, cut as the family-first bullet cuts one: one surname written with two particles reads as two. +- A lone particle the declared order left as the family counts as one word, R2 reading it as an ordinary name word, so the word after it joins, and so does a particle chain after it, cut as the family-first bullet cuts one. The family is then divided by its own words, where the particle attaches to the word after it, so it is one unit, and a second surname written after a surname opening with a particle that may be a given name, written with a capital (`Van`, `Del`), falls to the given name. ``` "Van Gogh Ana María" family-first+two_family_names → family="Van Gogh" - "Van der Merwe Jan" family-first+two_family_names → surname2="der Merwe" + "Van Gogh Ana María" family-first+two_family_names → surname2="" + "Van der Merwe Jan" family-first+two_family_names → family="Van der Merwe" + "Van Gogh Pérez Ana" family-first+two_family_names → given="Pérez" ``` - Where a name's script order and the declared one agree, nothing tells the two apart, so under a declared family-first order a spaced Han or Hangul name is read like any other. ``` @@ -165,5 +190,5 @@ - The rule reports nothing: the caller declared the convention, as a declared order is followed without a report, and a report on most names of three words or more would teach the caller to ignore the field. --- -**Signal:** none in the name + position: a caller switch, the family's words and the taken word's shape read as written to see whether the family already holds two; and the word standing where the family would take one, looked up in the caller's given-name list, a vocabulary signal tagged by where the word stands as P1's is, as are a given name written behind a particle and a name a community gives every member, which the family's own words are looked up for too +**Signal:** none in the name + position: a caller switch, the family's words and the taken word's shape read as written to see whether the family already holds two and where it divides; and the word standing where the family would take one, looked up in the caller's given-name list, a vocabulary signal tagged by where the word stands as P1's is, as are a given name written behind a particle and a name a community gives every member, which the family's own words are looked up for too, with the bound given-name words and, under the Turkic patronymic rule, the father's-name marker **history:** decisions/O6 · **implemented:** nameparser/_pipeline/_post_rules.py diff --git a/docs/design/rules/O7-two-given-names.md b/docs/design/rules/O7-two-given-names.md index ad37a6f46..567662358 100644 --- a/docs/design/rules/O7-two-given-names.md +++ b/docs/design/rules/O7-two-given-names.md @@ -111,10 +111,6 @@ ``` "Maria do Carmo Silva" two_given_names → family="do Carmo Silva" ``` -- The family a particle phrase leaves behind keeps the words it was written with, so with both switches on it holds two words as one unit and gives no second-surname view. - ``` - "María del Carmen García López" two_family_names+two_given_names → surname2="" - ``` - Where the declared order and a name's script agree, nothing tells the two apart, so under a declared family-first order a spaced Han or Hangul name is read like any other, as O6 reads it. ``` "王 小 明" family-first+two_given_names → given="小 明" diff --git a/docs/design/rules/O9-words-in-capitals-as-the-family.md b/docs/design/rules/O9-words-in-capitals-as-the-family.md index 861399165..42e6730b0 100644 --- a/docs/design/rules/O9-words-in-capitals-as-the-family.md +++ b/docs/design/rules/O9-words-in-capitals-as-the-family.md @@ -149,9 +149,10 @@ "DUPONT Mary Ann" family-first-given-last+capitals_as_family → given="Mary" ``` - **Against the post rules that move words** (H1, M4, P1, P6, O1, O2): this rule reads after them and lays the name out by its capitals, so their moves never undo it. -- **Against two-family-name handling and letters ending the name** (O6, O8): the capitals named the family, so those rules stand down where this one read the name. +- **Against two-family-name handling and letters ending the name** (O6, O8): the capitals named the family, so those rules stand down where this one read the name, save that O6 divides the family the capitals named as it divides any family, by its own words. ``` "Lucie Anne MARTIN" capitals_as_family+two_family_names → family="MARTIN" + "Ana GARCÍA LÓPEZ" capitals_as_family+two_family_names → surname2="LÓPEZ" "Lakshmi R S DUPONT" capitals_as_family+initials_as_family → family="DUPONT" ``` - **Against a declared order, the given name and the middle names**: "under every order" holds for the family; where a joining word chained into a unit by its neighbours ends up beside the given name, how the words outside the run divide between the given and the middle names can follow the unit and the order (below). diff --git a/docs/design/rules/P10-given-name-a-particle-completes.md b/docs/design/rules/P10-given-name-a-particle-completes.md index d111e6187..323bb4c2a 100644 --- a/docs/design/rules/P10-given-name-a-particle-completes.md +++ b/docs/design/rules/P10-given-name-a-particle-completes.md @@ -75,9 +75,10 @@ ``` "María del Carmen García" two_given_names → given="María del Carmen" ``` -- **Against two-family-name handling** (O6): this rule reads first, and O6 leaves the phrase where it stands. +- **Against two-family-name handling** (O6): this rule reads first, and O6 leaves the phrase where it stands and divides the family behind it as it divides any family. ``` "María del Carmen de la Vega" two_family_names → middle="del Carmen" + "María del Carmen García López" two_family_names → surname2="López" ``` **Accepted:** @@ -86,10 +87,6 @@ ``` "Pedro del Valle Llufrio" → middle="del Valle" ``` -- The family a phrase leaves behind keeps the words P2 chained into one unit, so two-family-name handling reads no second surname in it. - ``` - "María del Carmen García López" two_family_names → surname2="" - ``` - The rule reports nothing: the vocabulary says which reading the word takes, and a report on every such name would teach the caller to ignore the field. --- diff --git a/docs/design/rules/R10-second-surname-view.md b/docs/design/rules/R10-second-surname-view.md index 6ba06a780..6751365fe 100644 --- a/docs/design/rules/R10-second-surname-view.md +++ b/docs/design/rules/R10-second-surname-view.md @@ -17,10 +17,13 @@ "Gabriel García Márquez Jr." two_family_names → surname2="Márquez" "Gabriel García Márquez, PhD" two_family_names → surname2="Márquez" "Ana García (Anita) López" two_family_names → surname2="López" +"Juan de la Vega Ruiz" two_family_names → surname2="Ruiz" +"María del Carmen García López" two_family_names → surname2="López" +"García López, Ana" two_family_names → surname2="López" +"Lloyd Webber, Andrew" two_family_names → surname2="Webber" "Gabriel García Márquez" → surname2="" · boundary +"Lloyd Webber, Andrew" → surname2="" · boundary "Ana García" two_family_names → surname2="" -"Lloyd Webber, Andrew" two_family_names → surname2="" -"García López, Ana" two_family_names → surname2="" ", Ana García López" two_family_names → surname2="" ``` @@ -38,13 +41,17 @@ **Accepted:** -- A family O6 leaves whole is one unit to the view, so where a connective, a hyphen or a particle chain already joins two family names the name has two and the view is empty, as O6 counts them. +- A family O6 leaves whole is one unit to the view, so where a connective joins two family names, or a hyphen makes them one word, the name has two and the view is empty, as O6 counts them, with or without a family comma; a hyphenated word beside a plain one is a unit of its own. ``` "José María Ortega y Gasset" two_family_names → surname2="" "Ana María García-López" two_family_names → surname2="" - "Ana María de la Vega Rodríguez" two_family_names → surname2="" + "Ortega y Gasset, José" two_family_names → surname2="" + ``` +- A family of two units is divided whatever wrote them as one: a compound surname written as two words before a family comma, as without one, and one written with a particle and two name words, whose particle the vocabulary does not chain to both. + ``` + "Lloyd Webber, Andrew" two_family_names → surname1="Lloyd" + "Ana de la Torre Ugarte" two_family_names → surname2="Ugarte" ``` -- A family comma marks nothing, even where the part before it holds two family names, since nothing in it tells them from one compound name. - Where O6 reads a given name into the family, the family's own name is the view: the shape the switch cannot tell from the one it is for (O6's Accepted). ``` "Juan Carlos Pérez" two_family_names → surname2="Pérez" diff --git a/docs/design/rules/R11-first-surname-views.md b/docs/design/rules/R11-first-surname-views.md index 0f3fd178d..523480cd4 100644 --- a/docs/design/rules/R11-first-surname-views.md +++ b/docs/design/rules/R11-first-surname-views.md @@ -21,7 +21,8 @@ "Juan de la Vega" two_family_names → surname1_base="Vega" "Juan de la Vega" → surname1="de la Vega" · boundary "Juan de la Vega" → surname1_particles="de la" -"Pérez de la Vega, Juan" two_family_names → surname1_base="Pérez Vega" +"Pérez de la Vega, Juan" two_family_names → surname1_base="Pérez" +"Pérez de la Vega, Juan" → surname1_base="Pérez Vega" ``` **Except:** @@ -31,7 +32,7 @@ "Ana María García López" two_family_names+middle_as_family → surname1="García" "Ana María García López" two_family_names+middle_as_family → family="María García López" "Ana María García López" middle_as_family → surname1="López" - "García López, Ana María" two_family_names+middle_as_family → surname1="García López" + "García López, Ana María" two_family_names+middle_as_family → surname1="García" ``` - **A particle attached at the end of a family-first name belongs to the first unit**, the family it was attached to (P6), and stands before it there as it does in the family. ``` @@ -45,16 +46,13 @@ ``` "Juan Pérez de la Vega" two_family_names → initials="J. P. V." ``` -- A family O6 leaves whole is one unit, so where a connective, a hyphen or a family comma already joins two family names the views are the family's, as the second-surname view is empty there (R10's Accepted). +- A family O6 leaves whole is one unit, so where a connective or a hyphen already joins two family names the views are the family's, as the second-surname view is empty there (R10's Accepted), and so where a lone particle and the word after it make the family under a family-first order. ``` "Ana María García-López" two_family_names → surname1="García-López" "José María Ortega y Gasset" two_family_names → surname1_base="Ortega y Gasset" + "Van Gogh Vincent" family-first+two_family_names → surname1_base="Gogh" ``` - A family word with no reading, one that `replace()` or `Parser.revise()` wrote or in a name unpickled from 2.x, is in no unit, so such a family reads as one and the views are the family's. -- A first unit of a lone particle, which O6 leaves where it reads a particle and a name word after a family-first family as two surnames, splits as the family does, the particle working there, so its base is empty; the misreading is O6's, and the two units' particles and bases still add up to the family's. - ``` - "Van Gogh Vincent" family-first+two_family_names → surname1_base="" - ``` - A fold into a family the name left empty, behind a family comma with nothing before it (C15), has no first unit to keep apart from the folded words, so they are the views. ``` ", John Paul" middle_as_family → surname1="Paul" diff --git a/docs/design/vocabulary-model-rfc.md b/docs/design/vocabulary-model-rfc.md index 92ff084d5..37490cc62 100644 --- a/docs/design/vocabulary-model-rfc.md +++ b/docs/design/vocabulary-model-rfc.md @@ -401,7 +401,7 @@ What decides a view is the reading each token took, so `Token.reading` comes fir - **`Token.reading`**: a `Token` field holding the `Reading` the parse took, the same type `Ambiguity.alternative` holds the reading not taken in (decisions/A1), `None` for a token `replace()` or `revise()` builds. Its `kind` says what the word was read as, its `source` why, and a `languages` field, added to `Reading`, names the language files holding that reading, filled from phase 3's reading index (3a) and left empty for a reading no file holds (a word a caller's own `Lexicon` adds that no file holds in that category, a shape, position alone, and the Korean surname list, which stays outside the per-word files); it too takes `ADDED_IN` and is not compared, `Reading` having shipped in 2.7. The field takes `ADDED_IN` metadata, so a 2.x pickle loads with `None` (the pickle guard as widened in 2.7), and is left out of comparison (`compare=False`), so `==` between two `ParsedName`s means what it means in 2.x. `ReadingKind` gains `PATRONYMIC`, its docstring already allowing new kinds. - **Generation and credentials** (#326): `generation`, the suffix tokens whose reading is a generation or an agnomen (`Jr.`, `III`, `Filho`), and `credentials`, the rest of the suffix (`PhD`, `Esq.`, the honorifics after a name), so the two partition `suffix` and `suffix` is unchanged. CLDR has only these two buckets; the post-nominals that are neither (`Esq.`, the CJK and Hebrew honorifics, `Rinpoche`) fall in `credentials`, CLDR's catch-all, and a caller who wants them apart reads `Token.reading.kind`, which says `post-nominal` (since 2026-11-03 the honorifics have a view of their own, `honorifics`, and read `honorific`, decisions/R8's #326 entry). Measured 2026-10-28 on `c8357e74`, over the committed corpus's 6,533 distinct entries (`snapshot.corpus_entries()`) each parsed under its declared order: of the 1,054 with a suffix, 33 hold a generation (or agnomen) and a listed credential together, 77 a generation beside any other suffix word, and 64 only listed post-nominals of other kinds. Of the 615 CLDR renderings with a generation or credentials field, 75 parse with exactly CLDR's suffix words, and in all 75 a split by the vocabulary's reading kind gives CLDR's `generation` and `credentials` both; the other 540 differ in which words the suffix holds, a parse question the split cannot fix. Recompute: classify each suffix word (a token tagged `joined` merged into the one before it) by the kinds of its suffix readings in nameparser/vocab/, matched lowercased with its periods and spaces removed, skipping `default = false` readings, a generation or agnomen reading winning over a credential and a credential over the other kinds, an unlisted roman numeral `i` to `x` a generation and any other unlisted word unlisted; over the corpus entries above, and over `cldr_fields.jsonl` for CLDR. - **A patronymic** (decision 8): `patronymic`, the tokens whose reading is `PATRONYMIC`, in whichever role the parse put them, with `family` and `middle` unchanged. What fills it is a word or a rule that says patronymic, never a guess from position: the vocabulary's `patronymic` particles (`bin`, `binti`, `ibn`, `bint`, Hebrew `bar` and `bat` and the native-script forms) with the name after them, in the default, so `Mahathir bin Mohamad` reads family `bin Mohamad` as today and patronymic `bin Mohamad` beside it; the East Slavic and Turkic rules where RU or TR_AZ turns them on, so `Ivan Ivanovich Ivanov` under RU keeps middle `Ivanovich` and adds patronymic `Ivanovich`; and an Icelandic ending rule an `is` pack would turn on, the default unable to tell `Karlsdóttir` from the Swedish surname `Johansson`. The name `patronymic` is kept for a matronymic too, which is written the same way and cannot be told from one. **`family` is not emptied** by recognizing a patronymic, revising what this section said before: the people filling in the fielded corpora put the patronymic in the family box (below), as CLDR's samples put an Icelandic patronymic in `surname` or `surname-core` (CLDR's `is` file's 3 Icelandic samples, in all 9 of their renderings; its one foreign sample puts a `-dóttir` word in `surname2`) and a Russian one in `given2` (its 2 `ru` samples, in all 6 renderings), our `middle`, while Wikidata records an Icelandic name as a patronymic with no family name; a `family` that keeps it and a `patronymic` that names it satisfy both. A caller writing "Mr. {family}" reads `patronymic` to see that the family is one. -- **A second surname**: `surname2`, the family's second name unit where a rule has read the family as two (rules/O6, which a caller or an `es` pack turns on), and empty otherwise, `family` keeping both units as O6 makes it today. O6 already knows which unit it took, so it marks the second one's words, a private tag that the published reading carries as `Reading.second_surname` (a stable tag, as first written here, would make an O6 parse unequal to its 2.x pickle, `Token` comparing its tags; decisions/R10); a family comma alone marks nothing, since `Lloyd Webber, Andrew` is not two surnames, and a hyphenated family is one token and stays whole. The first unit's views, `surname1`, `surname1_particles` and `surname1_base`, were a value question here and were decided 2026-11-03 (decisions/R11, #1022), the family views keeping the whole family. `surnames` keeps its meaning, `middle` and `family` joined, the reading of a double surname the default splits. +- **A second surname**: `surname2`, the family's second name unit where a rule has read the family as two (rules/O6, which a caller or an `es` pack turns on), and empty otherwise, `family` keeping both units as O6 makes it today. O6 already knows which unit it took, so it marks the second one's words, a private tag that the published reading carries as `Reading.second_surname` (a stable tag, as first written here, would make an O6 parse unequal to its 2.x pickle, `Token` comparing its tags; decisions/R10); a family comma alone marks nothing, since `Lloyd Webber, Andrew` is not two surnames (superseded by decisions/O6's 2026-11-19 #1456, #1479 entry: the part before a family comma is divided as the comma-less family is), and a hyphenated family is one token and stays whole. The first unit's views, `surname1`, `surname1_particles` and `surname1_base`, were a value question here and were decided 2026-11-03 (decisions/R11, #1022), the family views keeping the whole family. `surnames` keeps its meaning, `middle` and `family` joined, the reading of a double surname the default splits. - **`middle`** (#704): keeps its meaning, every word of the given part after the given name, and the given name is one name unit unless a rule joins words into it, as rules/P5 already does (`Abdul Aziz Tariq` → given `Abdul Aziz`). A compound given name (`Maria do Carmo`, `María José`) is the `[rules]` rule above, turned on by a caller or a pack, moving its words into `given` only under that rule: built in 4g as `Policy.two_given_names` (rules/O7), the given name taking the middle unit beside it; a particle chain running to the end of the name (`Maria do Carmo Silva`) stays the family under it, which decisions/O7 leaves Open. CLDR's `given2` is `middle`, so no view is added. A Sikh `Kaur` stays in `middle`, and so, under FAMILY_FIRST, does an English name written after a Chinese one (`Lim Mei Ling Jessica` → given `Mei`, middle `Ling Jessica`), an accepted cost. **Measured in the fielded corpora** (2026-10-28, master `c8357e74`, counts only; recompute by counting each record's boxes by word count and word ending with `local_corpora.read_records`, grouped by the record's country or nationality, and the parse's role for the counted word with `parse()`. The ending tests, case-insensitive on the box's last word: an Icelandic patronymic a one-word family box ending `dóttir`, `dottir`, `sson` or `son` (the role count, `dóttir`, `dottir` or `sson`); an East Slavic patronymic `ovich`, `ovna`, `evich`, `evna`, `ichna` or their Cyrillic forms, in a given box of two or more words; nasab `bin`, `binti`, `bint`, `bte`, `bt`, `b.`, `ibn` or `ben` anywhere in the box. Other tests give other counts by a few percent): diff --git a/docs/languages.rst b/docs/languages.rst index fd2833823..7720cb641 100644 --- a/docs/languages.rst +++ b/docs/languages.rst @@ -367,6 +367,10 @@ the first surname without its particles (see :ref:`aggregate-views`): >>> vega_es = spain.parse("Juan de la Vega del Valle") >>> vega_es.surname1, vega_es.surname1_base ('de la Vega', 'Vega') + >>> spain.parse("García Márquez, Gabriel").surname2 + 'Márquez' + >>> spain.parse("María del Carmen García López").surname2 + 'López' Data from systems without the letter ñ writes ``Begoña`` as ``Begona``, so each listed name written with ñ is listed with n too, diff --git a/docs/migrate.rst b/docs/migrate.rst index de55c3eeb..f1c34af00 100644 --- a/docs/migrate.rst +++ b/docs/migrate.rst @@ -2217,3 +2217,32 @@ case, as it writes ``bin``: >>> balinese = parse("Anak Agung Made Putra") >>> balinese.given, [str(report.kind) for report in balinese.ambiguities] ('Anak', ['particle-or-given']) + +The second surname under two family names +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Under ``two_family_names``, as the ``es``, ``es_ar``, ``cs`` and ``sk`` +packs turn it on, the ``surname1`` and ``surname2`` views divide a +family of two surnames however the family was read, where 3.0 and 3.1 +left it whole: written before a family comma, opening with a particle, +and behind a given name a particle completes. No field moves: + +.. doctest:: + + >>> spanish = parser_for(locales.ES) + >>> spanish.parse("García Márquez, Gabriel").surname2 + 'Márquez' + >>> de_la_vega = spanish.parse("Juan de la Vega Ruiz") + >>> de_la_vega.surname1, de_la_vega.surname2 + ('de la Vega', 'Ruiz') + >>> spanish.parse("María del Carmen García López").surname2 + 'López' + +A family whose first unit is a lone particle under a family-first order +is one unit now (``Van Gogh Vincent`` gives ``surname1`` ``Van Gogh``), +where 3.0 and 3.1 read ``Van`` and ``Gogh`` as two, and so is a Turkic +father's name with its marker under ``PatronymicRule.TURKIC`` +(``Ali Ahmad Vali Hasan oglu`` gives ``surname1`` ``Hasan oglu``, where +3.0 and 3.1 gave ``Hasan`` and ``oglu``). With ``capitals_as_family`` +on too, the family the capitals name is divided (``Ana GARCÍA LÓPEZ`` +gives ``GARCÍA`` and ``LÓPEZ``), where 3.1 left it whole. diff --git a/docs/policy.rst b/docs/policy.rst index 0e41fc3dc..a12fc889a 100644 --- a/docs/policy.rst +++ b/docs/policy.rst @@ -543,16 +543,34 @@ one family has no ``surname2``, and its ``surname1`` is the family: >>> two_names.parse("Ana María García-López").surname2 '' +The family is divided by its own words however it was read: before a +family comma, and where it opens with a particle, the particles going +with the word they attach to. A family of three name words is left +whole: + +.. doctest:: + + >>> two_names.parse("García López, Ana").surname2 + 'López' + >>> ruiz = two_names.parse("Juan de la Vega Ruiz") + >>> ruiz.surname1, ruiz.surname2 + ('de la Vega', 'Ruiz') + >>> two_names.parse("Juan de la Vega Ruiz Soto").surname2 + '' + What it leaves alone ~~~~~~~~~~~~~~~~~~~~ - **A family that already holds two names** keeps what it has, whether a hyphen or ``y`` joins them (``"Ana María García-López"``, ``"José Ortega y Gasset"``) or a particle chain took them both (``"Ana María - de la Vega Rodríguez"`` reads family ``de la Vega Rodríguez``). + de la Vega Rodríguez"`` reads family ``de la Vega Rodríguez``); the + particle chain's family is still divided by its own words (``surname2`` + ``Rodríguez``), where the hyphen's and ``y``'s stay one unit. - **A name of two words** is unchanged. - **A comma naming the family** decides by itself, so ``"García López, - Ana"`` needs no switch at all. + Ana"`` needs no switch for its ``family``; the switch divides it into + ``surname1`` and ``surname2``. - **Kaur and Singh** stay where they stand (see :ref:`kaur-singh`). .. _two-family-names-cost: diff --git a/docs/release_log.rst b/docs/release_log.rst index 633ed4df4..213ca0da5 100644 --- a/docs/release_log.rst +++ b/docs/release_log.rst @@ -4,6 +4,7 @@ Release Log nameparser 3.2 is under development. + - **Fix the surname1 and surname2 views, which left a family of two surnames whole before a family comma, opening with a particle, or behind a given name a particle completes.** Under ``two_family_names``, as ``locales.ES``, ``ES_AR``, ``CS`` and ``SK`` turn it on, ``parser_for(locales.ES).parse("García Márquez, Gabriel")`` gives surname1 ``García``, surname2 ``Márquez``, as ``Gabriel García Márquez`` does, where 3.0.0 through 3.1.0 gave surname1 ``García Márquez``, surname2 ``''``. No field moves; a family joined by ``y`` or written as one hyphenated word stays whole, and so, where 3.0.0 through 3.1.0 divided them, do a lone particle and the word after it under a family-first order (``Van Gogh``) and a Turkic father's name with its marker; with ``capitals_as_family`` on too, the family the capitals name is divided. :issue:`1456`, :issue:`1479` - **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/usage.rst b/docs/usage.rst index cbe8a6e20..0561210b8 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -266,8 +266,10 @@ family as two: with ``two_family_names`` on (:ref:`two-family-names`), as the ``es``, ``es_ar``, ``cs``, ``sk``, ``pt_br`` and ``pt_pt`` packs turn it on (:doc:`locales`), or for a Chinese name opening with two surnames under ``zh`` (:ref:`east-asian-names`), and ``family`` -keeps both. Every other name has none, a family comma's and a -hyphenated one included: +keeps both. The family is divided by its own words, so the name written +with a family comma gives the same two, and so does a family opening +with a particle (``de la Vega`` then ``Ruiz``). Every other name has +none, a hyphenated family and one joined by ``y`` included: .. doctest:: @@ -276,6 +278,10 @@ hyphenated one included: ... "Gabriel García Márquez") >>> marquez.family, marquez.surname1, marquez.surname2 ('García Márquez', 'García', 'Márquez') + >>> marquez_comma = Parser(policy=Policy(two_family_names=True)).parse( + ... "García Márquez, Gabriel") + >>> marquez_comma.surname1, marquez_comma.surname2 + ('García', 'Márquez') >>> parse("Gabriel García Márquez").surname2 '' diff --git a/nameparser/AGENTS.md b/nameparser/AGENTS.md index daa38f078..594dd2d8c 100644 --- a/nameparser/AGENTS.md +++ b/nameparser/AGENTS.md @@ -8,6 +8,8 @@ Loaded when a session reads or edits anything under `nameparser/`: the pipeline, No comma, a FULL name before the comma, a ONE-WORD name before the comma and NOTHING before the comma are four paths, and the last two are the misses — #429, #430 and #432 are all the one-word path disagreeing with the full-name path on inputs the full-name path reads correctly, and #613's PR review found `, PhD` and `, Jr.` (an empty surname field, as CSV data writes it) read as given and title by a decision that returned early on an empty head, after two review rounds whose every grid had a name before the comma. Put a nickname-only head (`(Bob), PhD`) in every comma grid. The empty head no longer needs a row of its own in a grid that compares fields: rules/C15 reads it as a family comma naming an empty family, and `test_an_empty_head_reads_as_its_family_comma_twin` (tests/v2/test_properties.py) holds `, X` to `Smith, X` less the surname, fields and ambiguity kinds, over a grid of given parts, H1's title-and-one-name-word reading the one exception (#892). A change that breaks it gets a generic fix or an entry in decisions/C15, never code for the empty head alone; widen the test's grid with the change's own shapes instead. +A view the parse marks must read the same for the comma writing of a name, and a rule that stands down on a path takes the view with it. rules/O6 marked its two surname units only where it took a word, so `surname2` was empty for every family comma and for every family a particle chain or a P10 phrase had already made two words, and rules/R10, P10 and O7 each recorded its gap as Accepted, though no decision wanted it (#1456, #1479). When a rule marks something a view reads, compare the two writings of one name in its grid (`X Y, Given` against `Given X Y`, as `test_both_writings_of_one_family_read_the_same_units` in `tests/v2/pipeline/test_post_rules.py` does), and ask of each path the rule skips whether the view should go empty there. + ### Counting the one-word path Count the one-word path the way C3 counts, which is neither tokens nor pieces: a particle run and the one word it attaches to are one word (#575), a connective join and a bound given-name pair count as their words (#613, so `Ortega y Gasset, Dr.` is a whole name), and a suffix beside the surname counts as no name word at all -- a numeral of two or more letters (`VI` to `IX`) the trailing fork reads as the generation included, as a listed one is (#893: `Dumas VI, Jr.` lost its family where `Dumas III, Jr.` kept it). #603's review found the suffix half (`Vega y Lopez Jr., PhD Jones` lost its family where `Vega y Lopez, PhD Jones` kept it); #613 then reversed the connective half, and both now read given 'Vega', middle 'y', family 'Lopez' — so test a particle surname, a connective surname and a surname with a suffix, each before a comma. The same holds for any count INSIDE a part, not only the comma's: #886's numeral site in the family part counted pieces, and an unjoined particle there is a piece of its own, so `Smith van der V, John` and `SMITH VD V, JOHN` read suffix 'V' from 2.7.0 until #1080, the particles counted as words to spare; put a particle run in front of the word being counted, and one opening the part (`de Mesnil V, Jean`, which #1080's first fix still counted), in the grid of every count -- and a single-letter connective, which P3 leaves unjoined where the name has fewer than four root words and is a piece the same way: `Smith y V, John` read suffix 'V' until #1093. #1080's test review found it, though that fix's grid held `y`: but a grid read for what a change MOVES shows nothing about a shape it leaves wrong, so read the unmoved rows of a count's grid too. And write the connective in one case too, but don't assume what it is there: only the marked subset (`may_be_initial`, rules/P8) reads as an initial in a one-case name, while `Y` and `И` keep their connective tag, so `JOHN SMITH Y V` moved with its mixed-case twin under #1097 and #1098, after a decision had been asked on the premise that it could not. A suffix word OPENING the part is the other half, and counts as a name word where one follows it: from 2.4.0 the counts passed over it, so `JP Clancy, MD` lost its given name to initials that spell a credential and `Cem Akin, MD` to a given name a credential spells, until #1017, while `Md Rahman, PhD` had read title 'Md' or family 'Md Rahman' in every release. No comma grid had put a listed suffix word at the head, and real heads are full of them, so open a head with initials (`JP`, `A.M.`), a given name a credential spells (`Cem`, `Md`), a title/suffix dual (`Sr.`) and a split credential's member (`MB ChB`), behind a title too, and put a title behind the opening word (`Md Prof., PhD`): the first build counted it as the name word there in one count and not in the other, found by review. A bound given-name pair is the same trap from the other side: a count that passes over particles reads `Abu Bakr` as ONE word, `abu` being a particle and a bound word both, where `abdul Rahman` counts two, so a rule asking whether the given name already holds two words needs a bound pair of each spelling in its grid; #1057's grid held only `abdul` until its test review found O7 completing `Abu Bakr` (`_post_rules._one_given_word` counts it now). And C3's one name word is not one word as written: it passes over a title word (`Ashley Knight`) and reads a capitalized particle with its surname as one (`Bin Zhang`), so a rule keyed to a one-word head reads more two-word heads than it means to -- #1238's first build read `Bin Zhang, M.D.` and `Ashley Knight, M.S. BME` as initials, found by its grid and the ClinicalTrials.gov measurement; put a title-word surname and a capitalized particle head in the grid of any one-word-head rule, beside the lower-case Dutch particle (`de Waart`) it may mean to admit. A run of letters is a spelling too: `_LETTER` matches a Hangul syllable (`J.씨`, a glued honorific) and a decomposed accent's base, so a test that every letter is a capital needs a mark-free, cased letter in its grid and the NFD spelling beside it. diff --git a/nameparser/_pipeline/_post_rules.py b/nameparser/_pipeline/_post_rules.py index dd15b8abe..a6c01883d 100644 --- a/nameparser/_pipeline/_post_rules.py +++ b/nameparser/_pipeline/_post_rules.py @@ -34,7 +34,9 @@ a run and, for its peel, Lexicon.suffix_acronyms and suffix_words), Policy.two_family_names, Policy.two_given_names, Policy.name_order (O6 and O7 stand down where -the script's order differs from the declared one), +the script's order differs from the declared one, and O6 reads +Policy.script_orders for the part before a family comma, through +`_assign._effective_order`), Policy.middle_as_family, Policy.extra_suffix_delimiters (R1's entry pass, for the delimiter cores group drops); Lexicon.given_name_titles, Lexicon.given_names @@ -65,7 +67,7 @@ from nameparser._lexicon import Lexicon, _normalize, _run_addresses_by_given from nameparser._pipeline._assign import ( - _name_alt, _name_pieces, _name_positions, + _effective_order, _name_alt, _name_pieces, _name_positions, ) from nameparser._pipeline._pieces import ( is_lone_never_given_particle, is_lowercase_ambiguous_particle, @@ -634,23 +636,36 @@ def _take_trailing_initials(tokens: list[WorkToken]) -> None: tokens[j] = copy_with(tokens[j], role=Role.FAMILY) -def _take_second_family_name(state: ParseState, - tokens: list[WorkToken]) -> None: +def _take_second_family_name(state: ParseState, tokens: list[WorkToken], + capitals: bool) -> None: # rules/O6: "the family name takes the name word beside it, so # the last two name words are the family" -- the first two under # a family-first order. In place, as every post rule writes. # History: decisions/O6 (#754). + _, given, middle, family = _positions(tokens) + turkic = PatronymicRule.TURKIC in state.policy.patronymic_rules + # rules/O6: "a family comma decides by itself" -- the family is the + # part before it, divided where it holds two units (decisions/O6, + # #1456) + if state.structure is Structure.FAMILY_COMMA: + if len(family) > 1: + _divide_comma_family(state, tokens, family, turkic) + return # An order a name's script set (W4) other than the declared one is # not the caller's declaration, and no script it keys writes two # family names as separate words. Where the two agree nothing here # tells them apart, and the rule reads the name (rules/O6 Accepted). - if (state.structure is Structure.FAMILY_COMMA or state.order is None + if (not family or state.order is None or state.order != state.policy.name_order): return - _, given, middle, family = _positions(tokens) - others = sorted(given + middle) - if not family or _family_word_count(tokens, family) != 1: + # rules/O6: "a family that already holds two words keeps what it + # has", and so does one the capitals named (O9): nothing is taken, + # and the family is divided where it holds two units (decisions/O6, + # #1479) + if capitals or _family_word_count(tokens, family) != 1: + _divide_family(tokens, family, turkic) return + others = sorted(given + middle) # The rest in the units assign read them as, so a particle chain # (P2) or a bound given-name pair (P5) moves whole or not at all. units = _units(tokens, others) @@ -713,35 +728,133 @@ def _take_second_family_name(state: ParseState, if take[-1] > family[0] or any( tokens[i].role is not Role.MIDDLE for i in take): return - _mark_surname(tokens, take, FIRST_SURNAME_TAG) - _mark_surname(tokens, family, SECOND_SURNAME_TAG) - return - # family first: the unit after the family joins it, and what is - # left is a shorter name of the same order, laid out as the P1 - # fold above lays its remainder -- one family already placed. A - # particle P6 attached at the far end is family already and keeps - # its place. - if family[0] > units[0][0]: - return - # the unit taken joins the family as its second - _join_second_surname(tokens, family, units, state.order) + else: + # family first: the unit after the family joins it, and what is + # left is a shorter name of the same order, laid out as the P1 + # fold above lays its remainder -- one family already placed. A + # particle P6 attached at the far end is family already and + # keeps its place. + if family[0] > take[0]: + return + _lay_out_after_family(tokens, units, state.order) + # the unit taken joins the family, which is then divided, or moves + # in unmarked where the division declines + if not _divide_family(tokens, sorted(take + family), turkic): + for i in take: + _retag(tokens, i, Role.FAMILY) -def _join_second_surname(tokens: list[WorkToken], family: list[int], - units: list[list[int]], - order: tuple[Role, Role, Role]) -> None: - """The family-first join O6 and W5's pair share, in place: `family` - becomes the first surname and `units[0]`, the unit after it, the - second, and the units left are laid out as a shorter name of the - same order, one family already placed.""" - _mark_surname(tokens, family, FIRST_SURNAME_TAG) - _mark_surname(tokens, units[0], SECOND_SURNAME_TAG) +def _lay_out_after_family(tokens: list[WorkToken], units: list[list[int]], + order: tuple[Role, Role, Role]) -> None: + """The family-first layout O6 and W5's pair share, in place: the + units after `units[0]`, the unit joining the family, are laid out as + a shorter name of the same order, one family already placed. The + caller moves `units[0]` into the family itself: W5 marks it the + second unit, and O6 marks it through `_divide_family`, or moves it + unmarked where that declines.""" for unit, role in zip(units[1:], _name_positions( order, len(units))[1:]): for i in unit: _retag(tokens, i, role) +def _divide_family(tokens: list[WorkToken], family: list[int], + turkic: bool) -> bool: + """rules/O6: "a family is divided by its own words" -- in place, + however it was read: the one place O6 divides a family, after its + take, for a family it takes nothing into (one already holding two + words, a particle chain or the family a P10 phrase leaves, and one + O9's capitals named) and for the part before a family comma + (decisions/O6, #1456, #1479). + + The units are P1's fold units over the family's words in written + order (`unit_ends(chain=False)`): a particle run and the ONE name + word it attaches to, a connective join, a bound given-name pair, or + a plain word. Exactly two, each one word as the word O6 takes is + counted, are marked; a family of one unit or of three or more is + left whole, and so is one holding a connective (decisions/R10) or a + name a community gives every member, and so is a family ending in a + standalone patronymic marker under the Turkic rule (`turkic`): the + father's name and the marker, which O2 reads as one family and R9 + as the patronymic. The shape tests O6 asks of + the word it takes (an initial, a mark with no letter) are not asked + here: a family already read is divided as written ('Gallegos G.'). + A particle P6 attached to the family it ends is set aside and goes + with the first unit, the family it was attached to. + + True where it marked two units, each word then FAMILY. Plain loops + throughout, since every parse of a family under the switch pays for + this; no frame band guards the switch's path (`_CALL_BASELINE` + measures the default), so its cost is counted in decisions/O6.""" + if len(family) < 2: + return False + words: list[int] = [] + tags: list[frozenset[str]] = [] + attached: list[int] = [] + for i in family: + tag = tokens[i].tags + if "conjunction" in tag or SHARED_NAME_TAG in tag: + return False + if ATTACHED_TAG in tag: + attached.append(i) + else: + words.append(i) + tags.append(tag) + ends = unit_ends(tags, chain=False) + if len(ends) != 2 or (turkic and is_patronymic_marker( + tokens[words[-1]].text)): + return False + first, second = words[:ends[0]], words[ends[0]:] + # each unit one name word: a particle run counts with the word it + # attaches to, a bound given-name word with the word it completes + # whether or not it is also a particle ('abdul Rahman', 'Abu Bakr', + # and P12's phrase, whose bound word is one too, read by this test + # rather than the phrase tag group keeps only where it joined the + # pair, so not before a comma), and a unit of particles alone counts + # each of them, as `_family_word_count` counts a family; and a first + # unit of particles alone is no first surname (`bin` where a suffix + # word behind it stops the particle run, 'bin Abd Rahman') + for unit in (first, second): + named = 0 + bare = True + completes = False # the word before is a bound given-name word + for i in unit: + tag = tokens[i].tags + if "particle" not in tag: + bare = False + if not completes: + named += 1 + completes = "vocab:bound-given" in tag + if named > 1 or bare and (len(unit) > 1 or unit is first): + return False + _mark_surname(tokens, sorted(first + attached), FIRST_SURNAME_TAG) + _mark_surname(tokens, second, SECOND_SURNAME_TAG) + return True + + +def _divide_comma_family(state: ParseState, tokens: list[WorkToken], + family: list[int], turkic: bool) -> None: + """rules/O6: "the part before it is the whole family, divided" -- + where nothing after the comma joined it: the family is that part's + words alone, none taken in from after the comma (P1's fold, P6's + attachment), and the part's script sets no order other than the + declared one (W4), as the comma-less name is left alone there + (decisions/O6, #1456).""" + # the family's words in written order, so its last word is the one + # a word joined from after the comma would be + if tokens[family[-1]].span.start > state.comma_offsets[0]: + return + # every script an order can be keyed to (Script: Han, Hangul, kana, + # Cyrillic) is written from U+0400 up, so a word below it, accented + # Latin included, is in none (W4); a C-level test, no frame + if max(tokens[family[0]].text) >= "\u0400" and _effective_order( + state.policy, [tuple(family)], [0], tokens, + dot_divided=bool(state.interpunct_offsets) + ).order != state.policy.name_order: + return + _divide_family(tokens, family, turkic) + + def _read_surname_pair(state: ParseState, tokens: list[WorkToken]) -> PendingAmbiguity | None: """rules/W5: "the two surnames are the family, in two units" -- the @@ -768,7 +881,9 @@ def _read_surname_pair(state: ParseState, or SURNAME_PAIR_TAG not in tokens[units[0][0]].tags): return None first, second = family[0], units[0][0] - _join_second_surname(tokens, family, units, state.order) + _lay_out_after_family(tokens, units, state.order) + _mark_surname(tokens, family, FIRST_SURNAME_TAG) + _mark_surname(tokens, units[0], SECOND_SURNAME_TAG) after = second + 1 if (after == len(tokens) or tokens[after].span is None or tokens[after].span.start != tokens[second].span.end): @@ -913,7 +1028,8 @@ def _take_second_given_name(state: ParseState, # rules/R10: "the family's second name unit, the one written second, -# makes the second-surname view" -- whichever of the two O6 took +# makes the second-surname view" -- whichever of the two units O6 +# divides the family into, a word taken or not, or W5's pair # (decisions/R10, #754); and rules/R11: "the family's first name unit, # the one written first, makes the first-surname view" -- the other one, # marked in the same place (decisions/R11, #1022). It moves a unit into @@ -1528,8 +1644,8 @@ def post_rules(state: ParseState) -> ParseState: and _family_in_capitals(state, tokens, ambiguities)) if state.policy.initials_as_family: _take_trailing_initials(tokens) - if state.policy.two_family_names and not capitals: - _take_second_family_name(state, tokens) + if state.policy.two_family_names: + _take_second_family_name(state, tokens, capitals) if state.policy.two_given_names: _take_second_given_name(state, tokens) diff --git a/nameparser/_pipeline/_state.py b/nameparser/_pipeline/_state.py index f2a4fe452..a7ce92ae4 100644 --- a/nameparser/_pipeline/_state.py +++ b/nameparser/_pipeline/_state.py @@ -160,15 +160,17 @@ def reported_suffix_fork(ambiguities: Sequence[PendingAmbiguity], ATTACHED_TAG = "vocab:attached" #: On each word of the second name unit rules/O6 reads a family as, -#: written where O6 takes its word, and dropped from the published +#: written by `_post_rules._divide_family` wherever O6 divides a family +#: into two, a word taken or not (and by W5's surname pair), and +#: dropped from the published #: token like the kind tags above: `Reading.second_surname` carries it #: out (rules/R10, 3.0's 4d). SECOND_SURNAME_TAG = "vocab:second-surname" -#: Its twin on each word of the FIRST name unit: written where O6 reads -#: two, on the family O6 found under a family-first order (a particle -#: P6 attached included) and on the unit it took under the default one, -#: and where O6 marked none, by O3 on the family it folds middles into, +#: Its twin on each word of the FIRST name unit: written by +#: `_post_rules._divide_family` wherever O6 divides a family into two +#: (a particle P6 attached going with it), by W5's surname pair, and +#: where O6 marked none, by O3 on the family it folds middles into, #: so a folded middle is in no unit; carried out on #: `Reading.first_surname` (rules/R11, #1022). FIRST_SURNAME_TAG = "vocab:first-surname" diff --git a/nameparser/_policy.py b/nameparser/_policy.py index ffdea4001..5c984ca78 100644 --- a/nameparser/_policy.py +++ b/nameparser/_policy.py @@ -937,7 +937,10 @@ class Policy: #: the word it attaches to ("Juan Pérez de la Vega" gives family #: ``Pérez de la Vega``), a family already holding two words keeps #: what it has ("José María Ortega y Gasset", "Ana María - #: García-López", "Ana María de la Vega Rodríguez"), titles and + #: García-López", "Ana María de la Vega Rodríguez"), and is divided + #: by its own words into ``surname1`` and ``surname2`` (``de la + #: Vega``, ``Rodríguez``) unless ``y`` joins it or it is one + #: hyphenated word, titles and #: suffixes count as no name word, and a name of two name words is #: unchanged. The word taken must be one name word a family name #: could be, so an initial written alone ("Ana M. García"), hyphenated @@ -950,8 +953,9 @@ class Policy: #: script reads in an order other than name_order (a spaced Han or #: Hangul name under the default) is left alone, though under a #: declared FAMILY_FIRST, which the script agrees with, it moves. A - #: family comma decides by itself, so "García López, Ana" is - #: unaffected. A name with one family name behind two given names + #: family comma decides by itself, so "García López, Ana" keeps its + #: family, divided into ``surname1`` ``García`` and ``surname2`` + #: ``López`` as the comma-less name is. A name with one family name behind two given names #: loses one to the family ("Juan Carlos Pérez" gives family #: ``Carlos Pérez``), which is most English and Argentine names of #: three words or more and many Portuguese and Brazilian ones as diff --git a/nameparser/_types.py b/nameparser/_types.py index c1c68fae4..91657aaaf 100644 --- a/nameparser/_types.py +++ b/nameparser/_types.py @@ -1608,9 +1608,12 @@ def surname2(self) -> str: """The family's second name unit where the parse read the family as two (``Márquez`` in ``Gabriel García Márquez`` under ``two_family_names``, ``李`` in ``王李小明`` under - ``locales.ZH``), which :attr:`family` keeps; ``''`` for a - family read as one, a family comma's ("Lloyd Webber, Andrew") - and a hyphenated one included, for a name unpickled from 2.x, + ``locales.ZH``), which :attr:`family` keeps, the part before a + family comma divided alike ("García Márquez, Gabriel"); ``''`` + for a family read as one (a hyphenated one or one joined by + ``y`` included, and any family where no rule reads two, as + "Lloyd Webber, Andrew" under the default), for a name unpickled + from 2.x, and once :meth:`replace` or Parser.revise rewrites ``family``, whose words then carry no reading; rewriting another field keeps it. Added in 3.0.""" diff --git a/tests/v2/cases.py b/tests/v2/cases.py index 26bc6cdfb..6d49f56fb 100644 --- a/tests/v2/cases.py +++ b/tests/v2/cases.py @@ -139,6 +139,11 @@ class Case: #: argues otherwise. Its text still goes to corpus_cjk.jsonl, so #: the snapshot shows when its reading moves. tolerated: bool = False + #: Render views the row also asserts, view -> value, an empty one + #: included (`surname1`, `surname2`): views no field shows, which a + #: row needs where the change it pins moves a view and no field + #: (#1456, #1479). Absent views are not compared. + views: tuple[tuple[str, str], ...] = () def __post_init__(self) -> None: if self.policy is not None and self.locale is not None: @@ -474,9 +479,33 @@ def _check_cjk_shape_purity(self) -> None: "Ana María de la Vega Rodríguez", {"given": "Ana", "middle": "María", "family": "de la Vega Rodríguez"}, - policy=_TWO, classification="feat(#754)", + policy=_TWO, classification="feat(#1479)", + views=(("surname1", "de la Vega"), ("surname2", "Rodríguez")), notes="P2's chain made 'de la Vega Rodríguez' one piece, and " - "O6 counts its words, not its pieces"), + "O6 counts its words, not its pieces, taking none; the " + "family is divided by its words, the particles and the " + "word they attach to first (#1479); 3.0 and 3.1 read " + "surname2 ''"), + Case("two_family_names_divides_a_particle_led_family", + "Juan de la Vega Ruiz", + {"given": "Juan", "family": "de la Vega Ruiz"}, + policy=_TWO, classification="feat(#1479)", + views=(("surname1", "de la Vega"), ("surname2", "Ruiz")), + notes="3.0 and 3.1 read surname1 'de la Vega Ruiz', surname2 ''"), + Case("two_family_names_leaves_three_words_behind_a_particle_whole", + "Juan de la Vega Ruiz Soto", + {"given": "Juan", "family": "de la Vega Ruiz Soto"}, + policy=_TWO, classification="feat(#754)", + views=(("surname1", "de la Vega Ruiz Soto"), ("surname2", "")), + notes="three units, left whole as a plain family of three is"), + Case("two_family_names_divides_the_family_a_given_name_phrase_leaves", + "María del Carmen García López", + {"given": "María", "middle": "del Carmen", + "family": "García López"}, + policy=_TWO, classification="feat(#1479)", + views=(("surname1", "García"), ("surname2", "López")), + notes="rules/P10 reads the phrase as the middle name and leaves " + "P2's chain the family; 3.0 and 3.1 read surname2 ''"), Case("two_family_names_counts_a_connective_join_as_its_words", "José María Ortega y Gasset", {"given": "José", "middle": "María", "family": "Ortega y Gasset"}, @@ -500,7 +529,46 @@ def _check_cjk_shape_purity(self) -> None: Case("two_family_names_leaves_a_family_comma_alone", "López, Ana García", {"given": "Ana", "middle": "García", "family": "López"}, - policy=_TWO, classification="parity"), + policy=_TWO, classification="parity", + views=(("surname1", "López"), ("surname2", ""))), + Case("two_family_names_divides_the_part_before_a_family_comma", + "García Márquez, Juan", + {"given": "Juan", "family": "García Márquez"}, + policy=_TWO, classification="feat(#1456)", + views=(("surname1", "García"), ("surname2", "Márquez")), + notes="divided as 'Juan García Márquez' is; 3.0 and 3.1 read " + "surname1 'García Márquez', surname2 ''"), + Case("two_family_names_divides_a_particle_led_head_before_a_comma", + "de la Vega Ruiz, Juan", + {"given": "Juan", "family": "de la Vega Ruiz"}, + policy=_TWO, classification="feat(#1456)", + views=(("surname1", "de la Vega"), ("surname2", "Ruiz"))), + Case("two_family_names_divides_a_head_before_a_comma_family_first", + "García Márquez, Gabriel", + {"given": "Gabriel", "family": "García Márquez"}, + policy=Policy(name_order=FAMILY_FIRST, two_family_names=True), + classification="feat(#1456)", + views=(("surname1", "García"), ("surname2", "Márquez"))), + Case("two_family_names_leaves_a_connective_head_before_a_comma_whole", + "Ortega y Gasset, José", + {"given": "José", "family": "Ortega y Gasset"}, + policy=_TWO, classification="feat(#754)", + views=(("surname1", "Ortega y Gasset"), ("surname2", "")), + notes="a connective is left whole, the open question " + "decisions/R10 holds"), + Case("es_divides_the_part_before_a_family_comma", + "García Márquez, Juan", + {"given": "Juan", "family": "García Márquez"}, + locale="es", classification="feat(#1456)", + views=(("surname1", "García"), ("surname2", "Márquez"))), + Case("es_divides_a_listed_given_name_before_a_family_comma", + "Jorge Flores, Ana", + {"given": "Ana", "family": "Jorge Flores"}, + locale="es", classification="feat(#1456)", + views=(("surname1", "Jorge"), ("surname2", "Flores")), + notes="no given-name veto before the comma: the writer marked " + "both words as family, where 'Ana Jorge Flores' keeps " + "'Jorge' a middle name"), Case("two_family_names_leaves_a_two_word_name_alone", "Ana García", {"given": "Ana", "family": "García"}, policy=_TWO, classification="parity"), diff --git a/tests/v2/pipeline/test_post_rules.py b/tests/v2/pipeline/test_post_rules.py index bb57ca837..f0184b873 100644 --- a/tests/v2/pipeline/test_post_rules.py +++ b/tests/v2/pipeline/test_post_rules.py @@ -1,12 +1,16 @@ import dataclasses +import functools import json import pickle import sys +import unicodedata +from collections.abc import Sequence from pathlib import Path import pytest -from nameparser import Locale, Parser, PolicyPatch, locales, parse, parser_for +from nameparser import (Locale, ParsedName, Parser, PolicyPatch, locales, parse, + parser_for) from nameparser._lexicon import Lexicon, _normalize from nameparser._pipeline import run from nameparser._pipeline import _post_rules @@ -1415,7 +1419,7 @@ def test_two_family_names_declines_a_family_first_name_whose_family_is_not_first roles = (Role.GIVEN, Role.MIDDLE, Role.FAMILY) tokens = [copy_with(t, role=r) for t, r in zip(state.tokens, roles)] moved = copy_with(state, policy=policy, tokens=tuple(tokens)) - _take_second_family_name(moved, tokens) + _take_second_family_name(moved, tokens, capitals=False) assert [t.role for t in tokens] == list(roles) @@ -2631,3 +2635,262 @@ def test_o2_three_words_needs_the_turkic_rule() -> None: assert parse("Aidai Mederbek kyzy").family == "kyzy" # and the East Slavic rule alone does not read it assert parser_for(locales.RU).parse("Aidai Mederbek kyzy").family == "kyzy" + + +# -- one division for both writings (rules/O6, #1456, #1479) ------------ + +#: The family heads the two writings are compared over, each written +#: as the words before a family comma: a plain pair, a particle-led +#: family (P2's chain), a particle inside, two particle units, a saint +#: particle opening a unit (one surname, the vocabulary chaining it), +#: a hyphenated family of one word and a hyphen in either unit, a +#: connective (left whole, decisions/R10), +#: three words, an initial, a name a community gives every member, a +#: listed given name as the first word, a bound given-name word and +#: the word it completes (P5, P12), and one word. +_DIVISION_HEADS = ( + "García Márquez", "Vega Ruiz", + "de la Vega Ruiz", "del Río Pérez", "van der Berg Smith", + "Ruiz de la Vega", "Pérez del Valle", + "de Miguel de la Vega", + "Santa María López", "San Martín Pérez", "de la Santa Cruz", + "García-López", "Sánchez-Cid Torres", "Torres Sánchez-Cid", + "Ortega y Gasset", + "García Márquez López", "de la Vega Ruiz Soto", + "García M.", "Kaur Dhillon", + "Martín López", "Jorge Flores", + "عبد الله حسن", "حسن عبد الله", "Abu Bakr Siddiq", "abdul Rahman Khan", + "bin Abd Rahman", + "García", +) +#: The given names: plain, two words, behind a title, and the given +#: names rules/P10 completes behind a particle. +_DIVISION_GIVENS = ("Juan", "Ana María", "Dr. Juan", "María del Carmen", + "María de los Ángeles") +_DIVISION_CONFIGS = { + f"{label}-{order_name}": Parser(lexicon=base.lexicon, + policy=dataclasses.replace( + base.policy, name_order=order)) + for label, base in (("switch", Parser(policy=Policy( + two_family_names=True))), + ("es", parser_for(locales.ES))) + for order_name, order in (("gf", GIVEN_FIRST), ("ff", FAMILY_FIRST), + ("ffgl", FAMILY_FIRST_GIVEN_LAST)) +} + + +#: The spellings each pair is written in: as listed, wholly in +#: capitals, and decomposed (NFD), the spelling and encoding sweeps. +_DIVISION_SPELLINGS = (lambda text: text, str.upper, + lambda text: unicodedata.normalize("NFD", text)) + + +def _division_pairs() -> list[tuple[str, str, str]]: + """(config, comma writing, comma-less writing) for every head, + given name and spelling: the comma-less writing puts the family + where the config's order puts it, given-first at the end, else + first.""" + pairs = [] + for config, parser in _DIVISION_CONFIGS.items(): + given_first = parser.policy.name_order[0] is Role.GIVEN + for head in _DIVISION_HEADS: + for given in _DIVISION_GIVENS: + plain = (f"{given} {head}" if given_first + else f"{head} {given}") + for spell in _DIVISION_SPELLINGS: + pairs.append((config, spell(f"{head}, {given}"), + spell(plain))) + return pairs + + +#: Each head's division where its two writings read the same family: +#: the surname units, or None where the family is left whole. Every +#: head is compared at least once, so none drops out of the grid. +_DIVISION_UNITS: dict[str, tuple[str, str] | None] = { + "García Márquez": ("García", "Márquez"), + "Vega Ruiz": ("Vega", "Ruiz"), + "de la Vega Ruiz": ("de la Vega", "Ruiz"), + "del Río Pérez": ("del Río", "Pérez"), + "van der Berg Smith": ("van der Berg", "Smith"), + "Ruiz de la Vega": ("Ruiz", "de la Vega"), + "Pérez del Valle": ("Pérez", "del Valle"), + "de Miguel de la Vega": ("de Miguel", "de la Vega"), + "Santa María López": ("Santa María", "López"), + "San Martín Pérez": ("San Martín", "Pérez"), + "de la Santa Cruz": None, + "García-López": None, + "Sánchez-Cid Torres": ("Sánchez-Cid", "Torres"), + "Torres Sánchez-Cid": ("Torres", "Sánchez-Cid"), + "Ortega y Gasset": None, + "García Márquez López": None, + "de la Vega Ruiz Soto": None, + "García M.": ("García", "M."), + "Kaur Dhillon": None, + "Martín López": ("Martín", "López"), + "Jorge Flores": ("Jorge", "Flores"), + # a bound given-name word counts with the word it completes, a P12 + # phrase with or without the tag group keeps where it joined, and + # whether or not the bound word is also a particle + "عبد الله حسن": ("عبد الله", "حسن"), + "حسن عبد الله": ("حسن", "عبد الله"), + "Abu Bakr Siddiq": ("Abu Bakr", "Siddiq"), + "abdul Rahman Khan": ("abdul Rahman", "Khan"), + # a particle the suffix word behind it stops ('abd') is no first unit + "bin Abd Rahman": None, + "García": None, +} + + +_DivisionReading = tuple[str, str, str, ParsedName, ParsedName] + + +def _read_division_pairs() -> list[_DivisionReading]: + """Every pair of `_division_pairs`, both writings parsed.""" + readings = [] + for config, comma, plain in _division_pairs(): + parser = _DIVISION_CONFIGS[config] + readings.append((config, comma, plain, + parser.parse(comma), parser.parse(plain))) + return readings + + +@functools.cache +def _division_readings() -> tuple[_DivisionReading, ...]: + """The grid parsed once, for the tests that read it unpatched; the + negative control parses it again, under its patch.""" + return tuple(_read_division_pairs()) + + +def _nfc_casefold(text: str) -> str: + return unicodedata.normalize("NFC", text).casefold() + + +#: Comma heads the grid above cannot judge, each a refusal or a reading +#: whose comma-less twin reads another family, so the grid passes it +#: by: (parser, text, surname1, surname2). The refused rows read whole +#: on 6560abde too, the widened-check rule's rows; the dividing ones +#: are new (#1456). +def _switch(**policy: object) -> Parser: + return Parser(policy=Policy(two_family_names=True, **policy)) # type: ignore[arg-type] + + +_COMMA_HEAD_ROWS = [ + # a word joined to the family from after the comma: P1's fold, P6 + (_switch(), "Smith, de Mesnil", "Smith de Mesnil", ""), + (_switch(), "García López, Juan van", "van García López", ""), + # a part whose script reads another order than the declared one + # (W4) is left whole; where the two agree, or no order is keyed, it + # divides; a Cyrillic part divides unless a pack keys its order + (_switch(), "王 李, 小明", "王 李", ""), + (_switch(), "김 이, 민준", "김 이", ""), + (_switch(name_order=FAMILY_FIRST), "王 李, 小明", "王", "李"), + (_switch(name_order=FAMILY_FIRST), "김 이, 민준", "김", "이"), + (_switch(script_orders={}), "王 李, 小明", "王", "李"), + (_switch(), "Иванов Петров, Иван", "Иванов", "Петров"), + (parser_for(locales.MN, base=_switch()), "Батболд Дорж, Энх", + "Батболд Дорж", ""), + # a 间隔号 marks a transcription, so the script sets no order there + (_switch(), "王·李, 小明", "王", "李"), + # a unit of particles alone: two particles left whole, one ending + # the family its second unit, as comma-less (`Juan García de`) + (_switch(), "Smith van der, Juan", "Smith van der", ""), + (_switch(name_order=FAMILY_FIRST), "Beethoven van, Ludwig", + "Beethoven", "van"), + # a bound word counts with the word it completes, but a unit holding + # two name words besides is none (`named > 1`): the bound word + # joined to a particle surname + (_switch(), "Ahmad Abdul Rahman, Ali", "Ahmad", "Abdul Rahman"), + (_switch(), "abdul de la Vega Pérez, Juan", "abdul de la Vega Pérez", + ""), + # a bound pair behind a particle is the particle's one word, so the + # unit holds three (dcca25f4 left it whole) + (_switch(), "de Umm Ali Hasan, Smith", "de Umm Ali", "Hasan"), + # a particle a suffix-tagged word stops is no first unit (dcca25f4 + # read 'de' | 'V') + (_switch(), "de V, Ali", "de V", ""), + (_switch(), "García Márquez López, Ana", "García Márquez López", ""), + # titles, a title/suffix dual, a suffix and a title-particle head + (_switch(), "Dr. Sr. García López, Ana", "García", "López"), + (_switch(), "García Márquez Jr., Juan", "García", "Márquez"), + (_switch(), "García Márquez, Juan, Jr.", "García", "Márquez"), + (_switch(), "Freiherr von Berg Schmidt, Hans", "Freiherr von Berg", + "Schmidt"), + (_switch(), "St. John Smith, Mary", "St. John", "Smith"), + # the CS pack turns the switch on as ES does + (parser_for(locales.CS), "Novák Svoboda, Jan", "Novák", "Svoboda"), +] + + +@pytest.mark.parametrize("parser,text,surname1,surname2", _COMMA_HEAD_ROWS, + ids=[row[1] for row in _COMMA_HEAD_ROWS]) +def test_a_comma_head_divides_or_stays_whole( + parser: Parser, text: str, surname1: str, surname2: str) -> None: + name = parser.parse(text) + assert (name.surname1, name.surname2) == (surname1, surname2) + + +def test_each_head_divides_as_recorded_in_both_writings() -> None: + assert tuple(_DIVISION_UNITS) == _DIVISION_HEADS + read: dict[str, set[tuple[str, str] | None]] = {} + for _, comma, _, a, b in _division_readings(): + if a.family != b.family: + continue + seen = read.setdefault(_nfc_casefold(comma.split(",")[0]), set()) + for name in (a, b): + seen.add((_nfc_casefold(name.surname1), + _nfc_casefold(name.surname2)) + if name.surname2 else None) + expected: dict[str, set[tuple[str, str] | None]] = {} + for head, units in _DIVISION_UNITS.items(): + expected[head.casefold()] = { + None if units is None + else (units[0].casefold(), units[1].casefold())} + assert read == expected + + +def _division_disagreements(readings: Sequence[_DivisionReading], + ) -> tuple[int, list[tuple[str, ...]]]: + """How many pairs read the same family in both writings, and those + whose surname views differ there.""" + same = 0 + differ: list[tuple[str, ...]] = [] + for config, comma, plain, a, b in readings: + if a.family != b.family: + continue + same += 1 + if (a.surname1, a.surname2) != (b.surname1, b.surname2): + differ.append((config, comma, a.surname1, a.surname2, + plain, b.surname1, b.surname2)) + return same, differ + + +#: The pairs whose two writings read one family, and, the negative +#: control, how many of them disagree with the family comma's division +#: switched off (`_divide_comma_family` a no-op): the comma-less side +#: still divides, so every pair it divides disagrees. Measured on the +#: tree that added the division (#1456, #1479); on 6560abde, before +#: it, the same grid disagreed in 941 pairs, the comma-less side of a +#: particle-led and a P10 family undivided too (a dated figure). Re-take +#: the first two when the grid moves. +_DIVISION_SAME_FAMILY = 1659 +_DIVISION_UNGUARDED = 1241 + + +def test_both_writings_of_one_family_read_the_same_units() -> None: + """O6 (two family names): the two writings of one family give the + same units, with and without a family comma, wherever they read the same + family, over every head, given name, spelling, order and the bare + switch and locales.ES (#1456, #1479).""" + same, differ = _division_disagreements(_division_readings()) + assert same == _DIVISION_SAME_FAMILY + assert differ == [] + + +def test_both_writings_disagree_with_the_comma_division_off( + monkeypatch: pytest.MonkeyPatch) -> None: + # the recorded negative control for the test above + monkeypatch.setattr(_post_rules, "_divide_comma_family", + lambda state, tokens, family, turkic: None) + same, differ = _division_disagreements(_read_division_pairs()) + assert (same, len(differ)) == (_DIVISION_SAME_FAMILY, + _DIVISION_UNGUARDED) diff --git a/tests/v2/rules_doc.py b/tests/v2/rules_doc.py index 13665e3b9..0f7da835e 100644 --- a/tests/v2/rules_doc.py +++ b/tests/v2/rules_doc.py @@ -133,6 +133,9 @@ def has_boundary_or_waiver(self) -> bool: name_order=FAMILY_FIRST_GIVEN_LAST, two_family_names=True), "two_family_names+middle_as_family": Policy( two_family_names=True, middle_as_family=True), + "two_family_names+turkic": Policy( + two_family_names=True, + patronymic_rules=frozenset({PatronymicRule.TURKIC})), #: rules/O8's switch (#1254), named after its field as O6's is, #: with each order, the rule standing down under both family-first #: ones, and with the switches it reads before. diff --git a/tests/v2/test_cases.py b/tests/v2/test_cases.py index 22e8ba164..00f6fe61d 100644 --- a/tests/v2/test_cases.py +++ b/tests/v2/test_cases.py @@ -71,6 +71,8 @@ def test_case(case: Case) -> None: pn = parser.parse(case.text) actual = {f: getattr(pn, f) for f in _FIELDS if getattr(pn, f)} assert actual == case.expect, f"{case.text!r} ({case.classification})" + assert {view: getattr(pn, view) for view, _ in case.views} == dict( + case.views), f"{case.text!r} ({case.classification})" kinds = sorted(a.kind.value for a in pn.ambiguities) assert kinds == sorted(case.ambiguities), \ f"{case.text!r} ({case.classification})" diff --git a/tests/v2/test_types.py b/tests/v2/test_types.py index 5da08f17a..6d94e3784 100644 --- a/tests/v2/test_types.py +++ b/tests/v2/test_types.py @@ -1411,7 +1411,6 @@ def test_a_patronymic_parsedname_pickled_by_2_8_0_loads_equal() -> None: ("García Márquez Ana María", _FF, True, "Márquez"), ("García Márquez Ana María", _FFGL, True, "Márquez"), ("de Mesnil Jean Paul", _FF, False, "Jean"), - ("Van Gogh Ana María", _FF, False, "Gogh"), # a chain after the family is cut as P1's fold cuts it (#1024) ("Juan de la Vega Rodríguez", _FF, False, "de la Vega"), ("Pérez de la Vega Juan Carlos", _FFGL, False, "de la Vega"), @@ -1419,11 +1418,25 @@ def test_a_patronymic_parsedname_pickled_by_2_8_0_loads_equal() -> None: # P6's particle attaches to the first unit and stays out ("Beethoven Ludwig Maria van", _FF, False, "Ludwig"), ("Beethoven Ludwig Maria van", _FF, True, "Ludwig"), - # a family comma alone marks nothing, in every comma shape - ("Lloyd Webber, Andrew", _GF, False, ""), - ("García López, Ana", _GF, False, ""), - ("García López, Ana", _FF, True, ""), + # the part before a family comma is divided as the comma-less + # family is, in every order (#1456) + ("Lloyd Webber, Andrew", _GF, False, "Webber"), + ("García López, Ana", _GF, False, "López"), + ("García López, Ana", _FF, True, "López"), + ("Ruiz de la Vega, Juan", _FFGL, False, "de la Vega"), + ("de la Vega Ruiz, Juan", _GF, False, "Ruiz"), + # a family already holding two words is divided by its own words, + # a particle chain and the family a P10 phrase leaves (#1479) + ("García de la Vega López", _GF, False, "López"), + ("Ana María de la Vega Rodríguez", _GF, False, "Rodríguez"), + ("María del Carmen García López", _GF, False, "López"), + # a comma head of one word, of none, of three, a word joined from + # after the comma, a connective and a hyphen leave it whole ("López, Ana García", _GF, True, ""), + ("García Márquez López, Juan", _GF, False, ""), + ("Smith, de Mesnil Jean", _GF, False, ""), + ("Ortega y Gasset, José", _GF, False, ""), + ("García-López, Ana", _GF, False, ""), ("Ana, García López", _GF, False, ""), (", Ana García López", _GF, False, ""), (", Ana García López", _GF, True, ""), @@ -1433,8 +1446,11 @@ def test_a_patronymic_parsedname_pickled_by_2_8_0_loads_equal() -> None: ("Ana María García-López", _GF, True, ""), ("José María Ortega y Gasset", _GF, False, ""), ("Juan Pérez y Gómez", _GF, False, ""), - ("García de la Vega López", _GF, False, ""), - ("Ana María de la Vega Rodríguez", _GF, False, ""), + ("Juan de la Vega Ruiz Soto", _GF, False, ""), + # a lone particle and the word after it are one unit (rules/O6's + # Accepted; master read 'Gogh' here, the particle a unit alone) + ("Van Gogh Ana María", _FF, False, ""), + ("Van der Merwe Jan", _FF, False, ""), # O6's other declines ("Ana García", _GF, False, ""), ("Ana M.-J. López", _GF, False, ""), @@ -1586,24 +1602,27 @@ def test_reading_second_surname_is_a_bool_and_is_not_compared() -> None: ("Beethoven Ludwig Maria van", FAMILY_FIRST, False, "van Beethoven", "van", "Beethoven"), ("Ali Hassan bin Ahmad", None, False, "Hassan", "", "Hassan"), + # the part before a family comma, two units as without it (#1456) + ("Pérez de la Vega, Juan", None, False, "Pérez", "", "Pérez"), # one unit: the family's own views ("Juan de la Vega", None, False, "de la Vega", "de la", "Vega"), - ("Pérez de la Vega, Juan", None, False, "Pérez de la Vega", "de la", - "Pérez Vega"), + ("Pérez de la Vega López, Juan", None, False, "Pérez de la Vega López", + "de la", "Pérez Vega López"), ("Ana María García-López", None, False, "García-López", "", "García-López"), - # a first unit O6 leaves a lone particle splits as the family does, - # the particle working there (R11's Accepted) - ("Van Gogh Vincent", FAMILY_FIRST, False, "Van", "Van", ""), + # a lone particle and the word after it are one unit, the family's + # own views (R11's Accepted, #1479) + ("Van Gogh Vincent", FAMILY_FIRST, False, "Van Gogh", "Van", "Gogh"), # a patronymic in either unit keeps the mark where assemble # rebuilds the reading ("Mammadov Hasan Ali ibn", FAMILY_FIRST, False, "ibn Mammadov", "ibn", "Mammadov"), # O3's folded middles are in neither unit, one unit or two - ("García López, Ana María", None, True, "García López", "", - "García López"), - ("Ana María de la Vega Rodríguez", None, True, "de la Vega Rodríguez", - "de la", "Vega Rodríguez"), + ("García López, Ana María", None, True, "García", "", "García"), + ("Ana María de la Vega Rodríguez", None, True, "de la Vega", "de la", + "Vega"), + ("Ana María García-López", None, True, "García-López", "", + "García-López"), ] @@ -1656,13 +1675,21 @@ def test_the_surname1_views_leave_out_a_fold_without_two_units() -> None: patronymic_rules=frozenset({PatronymicRule.TURKIC}))).parse( "Ali Hasan oglu") assert (turkic.surname1, turkic.surname2) == ("Hasan oglu", "") - # five name words keep the positional reading, so O6 still divides - # the family it reads there (the father's name and the marker) - five = Parser(policy=Policy( + # five name words keep the positional reading and O6 takes the + # father's name into the family, which is still one unit; so is the + # family before a comma (rules/O6, #1456) + turkic_parser = Parser(policy=Policy( two_family_names=True, - patronymic_rules=frozenset({PatronymicRule.TURKIC}))).parse( - "Ali Ahmad Vali Hasan oglu") - assert (five.surname1, five.surname2) == ("Hasan", "oglu") + patronymic_rules=frozenset({PatronymicRule.TURKIC}))) + five = turkic_parser.parse("Ali Ahmad Vali Hasan oglu") + assert (five.family, five.surname1, five.surname2) == ( + "Hasan oglu", "Hasan oglu", "") + comma = turkic_parser.parse("Hasan oglu, Ali") + assert (comma.surname1, comma.surname2) == ("Hasan oglu", "") + # without the Turkic rule the marker is a word like any other + plain = Parser(policy=Policy(two_family_names=True)).parse( + "Hasan oglu, Ali") + assert (plain.surname1, plain.surname2) == ("Hasan", "oglu") def test_the_surname1_views_are_render_keys_and_not_fields() -> None: diff --git a/tools/differential/cldr_agreement_locales.json b/tools/differential/cldr_agreement_locales.json index 75fb625a1..4fa909478 100644 --- a/tools/differential/cldr_agreement_locales.json +++ b/tools/differential/cldr_agreement_locales.json @@ -424,17 +424,6 @@ }, "text": "Svoboda Josef Václav" }, - "es/foreignFull/sorting": { - "surname1_base": { - "expected": "Miller", - "got": "Miller Jones" - }, - "surname2": { - "expected": "Jones", - "got": "" - }, - "text": "von Miller Jones, Prof. Dr. Mary Sue Marie" - }, "es/foreignGGS/givenFirst": { "family": { "expected": "Jacobsen", @@ -446,17 +435,6 @@ }, "text": "Christopher Hans Jacobsen" }, - "es/nativeFull/sorting": { - "surname1_base": { - "expected": "Pablo", - "got": "Pablo Pérez" - }, - "surname2": { - "expected": "Pérez", - "got": "" - }, - "text": "Pablo Pérez, Sr. Miguel Ángel Juan Antonio" - }, "ga/foreignFull/givenFirst": { "surname1_base": { "expected": "Brühl", diff --git a/tools/differential/corpus_rules.jsonl b/tools/differential/corpus_rules.jsonl index a2652ef4b..73bdd9acb 100644 --- a/tools/differential/corpus_rules.jsonl +++ b/tools/differential/corpus_rules.jsonl @@ -112,6 +112,7 @@ "Ali Ahmad Vali oglu" "Ali Ahmad Vali oglu Jr." "Ali Ahmad oglu" +"Ali Hasan oglu" "Ali Hassan bin Ahmad" "Ali bin Ahmad Jr. Hasan" "Ali bin Ahmad bin Hasan" @@ -123,6 +124,7 @@ "Alves, Pedro Neto" "Ana Abdul-Rahman López" "Ana Fo" +"Ana GARCÍA LÓPEZ" "Ana García" "Ana García (Anita) López" "Ana J.R. García" @@ -151,6 +153,7 @@ "Ana abdul Rahman López" "Ana de María Pérez" "Ana de Miguel de la Vega" +"Ana de la Torre Ugarte" "Anak Agung Ayu, Sari" "Anak Agung Made Putra" "Andrew" @@ -426,10 +429,12 @@ "García López, Ana María" "García Márquez Ana María" "García Márquez Gabriel" +"García Márquez López, Juan" "García Márquez, Ed G.J." "García Márquez, G.J" "García Márquez, G.J." "García Márquez, G.J.R." +"García Márquez, Juan" "García Márquez, M.J., PhD" "García Márquez, MJ" "García Márquez, MJ JK" @@ -465,6 +470,7 @@ "Hans „Erster“ und “Zweiter” Müller" "Harpreet Kaur Dhillon" "Harpreet Simran Kaur" +"Hasan oglu, Ali" "Hasan, Ali bin Ahmad Jr. Smith" "Hassan Mohamad Ali" "Hassan Mohamad Ali Omar" @@ -1136,6 +1142,8 @@ "Juan de Md Rahman" "Juan de la Vega" "Juan de la Vega Rodríguez" +"Juan de la Vega Ruiz" +"Juan de la Vega Ruiz Soto" "Juan de la Vega del Valle" "Juan de y" "Juan dela Cruz Sta.Maria" @@ -1284,6 +1292,7 @@ "Marquis Johnson" "Marquis de Lafayette" "Marshal Yanda" +"Martín López, Ana" "Mary (Molly) DUPONT" "Mary ALLIOT-MARIE" "Mary Ann DUPONT" @@ -1384,6 +1393,7 @@ "Ortega y Gasset Vi" "Ortega y Gasset, Dr." "Ortega y Gasset, Ed" +"Ortega y Gasset, José" "Ortega y Gasset, MJ, PhD" "P.D. Dr. Hans Meier" "P.D. Judge Smith" @@ -1763,6 +1773,7 @@ "Van Berg Jan de" "Van Buren, Ed" "Van Gogh Ana María" +"Van Gogh Pérez Ana" "Van Gogh Vincent" "Van J. S." "Van Johnson" @@ -1836,6 +1847,7 @@ "de la Cruz Juan Carlos" "de la Torre Vega" "de la Vega" +"de la Vega Ruiz, Juan" "de la Vega y Santos Juan" "de los Santos" "dipl.-ing john smith" diff --git a/tools/differential/snapshot.jsonl b/tools/differential/snapshot.jsonl index 52f14dde0..a447d6b18 100644 --- a/tools/differential/snapshot.jsonl +++ b/tools/differential/snapshot.jsonl @@ -232,6 +232,7 @@ {"name": "Ali Ahmad Vali oglu Jr.", "given": "Ali", "middle": "Ahmad Vali", "family": "oglu", "suffix": "Jr.", "initials": "A. A. V. o.", "capitalized_force": "Ali Ahmad Vali Oglu Jr.", "generation": "Jr."} {"name": "Ali Ahmad oglu", "given": "Ali", "middle": "Ahmad", "family": "oglu", "initials": "A. A. o.", "capitalized_force": "Ali Ahmad Oglu"} {"name": "Ali Amina", "order": "FAMILY_FIRST", "given": "Amina", "family": "Ali", "initials": "A. A."} +{"name": "Ali Hasan oglu", "given": "Ali", "middle": "Hasan", "family": "oglu", "initials": "A. H. o.", "capitalized_force": "Ali Hasan Oglu"} {"name": "Ali Hassan bin Ahmad", "given": "Ali", "middle": "Hassan", "family": "bin Ahmad", "initials": "A. H. A.", "patronymic": "bin Ahmad"} {"name": "Ali Juma Hamisi", "given": "Ali", "middle": "Juma", "family": "Hamisi", "initials": "A. J. H."} {"name": "Ali Kara Oğlu", "given": "Ali", "middle": "Kara", "family": "Oğlu", "initials": "A. K. O."} @@ -275,6 +276,7 @@ {"name": "An tOll. An Dr. Brigid Aoibhe Sophia de Bhulbh", "given": "An", "middle": "tOll. An Dr. Brigid Aoibhe Sophia", "family": "de Bhulbh", "initials": "A. t. A. D. B. A. S. B.", "capitalized_force": "An Toll. An Dr. Brigid Aoibhe Sophia de Bhulbh"} {"name": "Ana Abdul-Rahman López", "given": "Ana", "middle": "Abdul-Rahman", "family": "López", "initials": "A. A. L."} {"name": "Ana Fo", "given": "Ana", "family": "Fo", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: agnomen as suffix (vocabulary)"], "initials": "A. F."} +{"name": "Ana GARCÍA LÓPEZ", "given": "Ana", "middle": "GARCÍA", "family": "LÓPEZ", "initials": "A. G. L.", "capitalized_force": "Ana García López"} {"name": "Ana García", "given": "Ana", "family": "García", "initials": "A. G."} {"name": "Ana García (Anita) López", "given": "Ana", "middle": "García", "family": "López", "nickname": "Anita", "initials": "A. G. L."} {"name": "Ana J.R. García", "given": "Ana", "middle": "J.R.", "family": "García", "initials": "A. J. R. G."} @@ -305,6 +307,7 @@ {"name": "Ana abdul Rahman López", "given": "Ana", "middle": "abdul Rahman", "family": "López", "initials": "A. a. R. L.", "capitalized_force": "Ana Abdul Rahman López"} {"name": "Ana de María Pérez", "given": "Ana", "middle": "de María", "family": "Pérez", "initials": "A. M. P."} {"name": "Ana de Miguel de la Vega", "given": "Ana", "middle": "de Miguel", "family": "de la Vega", "initials": "A. M. V."} +{"name": "Ana de la Torre Ugarte", "given": "Ana", "family": "de la Torre Ugarte", "initials": "A. T. U."} {"name": "Anak Agung Ayu, Sari", "given": "Sari", "family": "Anak Agung Ayu", "initials": "S. A. A.", "capitalized_force": "Sari anak Agung Ayu", "patronymic": "Anak Agung Ayu"} {"name": "Anak Agung Made Putra", "given": "Anak", "middle": "Agung Made", "family": "Putra", "ambiguities": ["PARTICLE_OR_GIVEN"], "alternatives": ["PARTICLE_OR_GIVEN: patronymic as family (vocabulary)"], "initials": "A. A. M. P."} {"name": "Anan ben David", "given": "Anan", "middle": "ben", "family": "David", "initials": "A. b. D.", "capitalized_force": "Anan Ben David"} @@ -1311,10 +1314,12 @@ {"name": "García López, Ana María", "given": "Ana", "middle": "María", "family": "García López", "initials": "A. M. G. L."} {"name": "García Márquez Ana María", "given": "García", "middle": "Márquez Ana", "family": "María", "initials": "G. M. A. M."} {"name": "García Márquez Gabriel", "given": "García", "middle": "Márquez", "family": "Gabriel", "initials": "G. M. G."} +{"name": "García Márquez López, Juan", "given": "Juan", "family": "García Márquez López", "initials": "J. G. M. L."} {"name": "García Márquez, Ed G.J.", "given": "Ed", "middle": "G.J.", "family": "García Márquez", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: credential as suffix (vocabulary)", "SUFFIX_OR_NAME: credential as suffix (shape)"], "initials": "E. G. J. G. M."} {"name": "García Márquez, G.J", "given": "G.", "middle": "J", "family": "García Márquez", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: credential as suffix (shape)"], "initials": "G. J. G. M."} {"name": "García Márquez, G.J.", "given": "G.", "middle": "J.", "family": "García Márquez", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: credential as suffix (shape)"], "initials": "G. J. G. M."} {"name": "García Márquez, G.J.R.", "given": "García", "family": "Márquez", "suffix": "G.J.R.", "initials": "G. M."} +{"name": "García Márquez, Juan", "given": "Juan", "family": "García Márquez", "initials": "J. G. M."} {"name": "García Márquez, M.J., PhD", "given": "García", "family": "Márquez", "suffix": "M.J., PhD", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: name as given (position)"], "initials": "G. M."} {"name": "García Márquez, MJ", "given": "MJ", "family": "García Márquez", "initials": "M. G. M.", "capitalized_force": "Mj García Márquez"} {"name": "García Márquez, MJ JK", "given": "García", "family": "Márquez", "suffix": "MJ JK", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: name as given (position)"], "initials": "G. M."} @@ -1465,6 +1470,7 @@ {"name": "Harpreet Kaur Dhillon", "given": "Harpreet", "middle": "Kaur", "family": "Dhillon", "initials": "H. K. D."} {"name": "Harpreet Simran Kaur", "given": "Harpreet", "middle": "Simran", "family": "Kaur", "initials": "H. S. K."} {"name": "Harrieta Keōpūolani Nāhiʻenaʻena", "given": "Harrieta", "middle": "Keōpūolani", "family": "Nāhiʻenaʻena", "initials": "H. K. N."} +{"name": "Hasan oglu, Ali", "given": "Ali", "family": "Hasan oglu", "initials": "A. H. o.", "capitalized_force": "Ali Hasan Oglu"} {"name": "Hasan, Ali bin Ahmad Jr. Smith", "given": "Ali", "middle": "bin Ahmad", "family": "Hasan", "suffix": "Jr. Smith", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: name as middle (position)"], "initials": "A. A. H.", "generation": "Jr.", "credentials": "Smith", "patronymic": "bin Ahmad"} {"name": "Hasani Maria", "order": "FAMILY_FIRST", "given": "Maria", "family": "Hasani", "initials": "M. H."} {"name": "Hasani, Maria", "given": "Maria", "family": "Hasani", "initials": "M. H."} @@ -2608,6 +2614,8 @@ {"name": "Juan de la Vega", "given": "Juan", "family": "de la Vega", "initials": "J. V."} {"name": "Juan de la Vega III", "given": "Juan", "family": "de la Vega", "suffix": "III", "initials": "J. V.", "generation": "III"} {"name": "Juan de la Vega Rodríguez", "given": "Juan", "family": "de la Vega Rodríguez", "initials": "J. V. R."} +{"name": "Juan de la Vega Ruiz", "given": "Juan", "family": "de la Vega Ruiz", "initials": "J. V. R."} +{"name": "Juan de la Vega Ruiz Soto", "given": "Juan", "family": "de la Vega Ruiz Soto", "initials": "J. V. R. S."} {"name": "Juan de la Vega del Valle", "given": "Juan", "middle": "de la Vega", "family": "del Valle", "initials": "J. V. V."} {"name": "Juan de la Vega, Jr.", "given": "Juan", "family": "de la Vega", "suffix": "Jr.", "initials": "J. V.", "generation": "Jr."} {"name": "Juan de la de la Vega", "given": "Juan", "family": "de la de la Vega", "initials": "J. V."} @@ -3122,6 +3130,7 @@ {"name": "Martine Sodersen", "given": "Martine", "family": "Sodersen", "initials": "M. S."} {"name": "Martini, Fabio Massimo Carlo Alberto", "given": "Fabio", "middle": "Massimo Carlo Alberto", "family": "Martini", "initials": "F. M. C. A. M."} {"name": "Martín Descalzo, José Luis", "given": "José", "middle": "Luis", "family": "Martín Descalzo", "initials": "J. L. M. D."} +{"name": "Martín López, Ana", "given": "Ana", "family": "Martín López", "initials": "A. M. L."} {"name": "Martín Villazón Ochoa", "given": "Martín", "middle": "Villazón", "family": "Ochoa", "initials": "M. V. O."} {"name": "Martín-Santos, Luis", "given": "Luis", "family": "Martín-Santos", "initials": "L. M."} {"name": "Marulanda Vélez, Manuel", "given": "Manuel", "family": "Marulanda Vélez", "initials": "M. M. V."} @@ -3473,6 +3482,7 @@ {"name": "Ortega y Gasset Vi", "given": "Ortega y Gasset", "family": "Vi", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: generation as suffix (shape)"], "initials": "O. G. V."} {"name": "Ortega y Gasset, Dr.", "title": "Dr.", "given": "Ortega", "middle": "y", "family": "Gasset", "initials": "O. y. G."} {"name": "Ortega y Gasset, Ed", "given": "Ortega", "middle": "y", "family": "Gasset", "suffix": "Ed", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: name as given (declared)"], "initials": "O. y. G.", "capitalized_force": "Ortega y Gasset, ED"} +{"name": "Ortega y Gasset, José", "given": "José", "family": "Ortega y Gasset", "initials": "J. O. G."} {"name": "Ortega y Gasset, MJ, PhD", "given": "Ortega", "middle": "y", "family": "Gasset", "suffix": "MJ, PhD", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: name as given (position)"], "initials": "O. y. G."} {"name": "Orueta y Duarte, Ricardo de", "given": "Ricardo", "family": "de Orueta y Duarte", "initials": "R. O. D."} {"name": "Orval, Pierre d'", "given": "Pierre", "family": "d' Orval", "initials": "P. O."} @@ -4424,6 +4434,7 @@ {"name": "Van Buren, Ed", "given": "Ed", "family": "Van Buren", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: credential as suffix (vocabulary)"], "initials": "E. B.", "capitalized_force": "Ed van Buren"} {"name": "Van Dalen Hoogeveen, Maria da Graça César Martín", "given": "Maria", "middle": "da Graça César Martín", "family": "Van Dalen Hoogeveen", "initials": "M. G. C. M. D. H.", "capitalized_force": "Maria da Graça César Martín van Dalen Hoogeveen"} {"name": "Van Gogh Ana María", "given": "Van", "middle": "Gogh Ana", "family": "María", "ambiguities": ["PARTICLE_OR_GIVEN"], "alternatives": ["PARTICLE_OR_GIVEN: particle as family (vocabulary)"], "initials": "V. G. A. M."} +{"name": "Van Gogh Pérez Ana", "given": "Van", "middle": "Gogh Pérez", "family": "Ana", "ambiguities": ["PARTICLE_OR_GIVEN"], "alternatives": ["PARTICLE_OR_GIVEN: particle as family (vocabulary)"], "initials": "V. G. P. A."} {"name": "Van Gogh Vincent", "given": "Van", "middle": "Gogh", "family": "Vincent", "ambiguities": ["PARTICLE_OR_GIVEN"], "alternatives": ["PARTICLE_OR_GIVEN: particle as family (vocabulary)"], "initials": "V. G. V."} {"name": "Van J. S.", "given": "Van", "middle": "J.", "family": "S.", "ambiguities": ["PARTICLE_OR_GIVEN"], "alternatives": ["PARTICLE_OR_GIVEN: particle as family (vocabulary)"], "initials": "V. J. S."} {"name": "Van Jeremy Johnson", "given": "Van", "middle": "Jeremy", "family": "Johnson", "ambiguities": ["PARTICLE_OR_GIVEN"], "alternatives": ["PARTICLE_OR_GIVEN: particle as family (vocabulary)"], "initials": "V. J. J."} @@ -4725,6 +4736,7 @@ {"name": "de la Cruz, Ma", "given": "Ma", "family": "de la Cruz", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: credential as suffix (vocabulary)"], "initials": "M. C."} {"name": "de la Torre Vega", "family": "de la Torre Vega", "initials": "T. V."} {"name": "de la Vega", "family": "de la Vega", "initials": "V."} +{"name": "de la Vega Ruiz, Juan", "given": "Juan", "family": "de la Vega Ruiz", "initials": "J. V. R."} {"name": "de la Vega y Santos Juan", "family": "de la Vega y Santos Juan", "initials": "V. S. J."} {"name": "de la Vega, Dr. Juan", "title": "Dr.", "given": "Juan", "family": "de la Vega", "initials": "J. V."} {"name": "de la Vega, Dr. Juan III", "title": "Dr.", "given": "Juan", "family": "de la Vega", "suffix": "III", "initials": "J. V.", "generation": "III"} From 8d3de7a897a766d50c1f73b9987c59a6c1678ea1 Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Thu, 19 Nov 2026 14:16:31 -0800 Subject: [PATCH 2/4] Measure the division under the Portuguese packs #1481 turned on; list them (#1456, #1479) Co-Authored-By: Claude Opus 5.5 --- docs/design/decisions/O6-two-family-names.md | 1 + docs/migrate.rst | 4 ++-- docs/release_log.rst | 2 +- tools/differential/corpus_rules.jsonl | 1 + tools/differential/snapshot.jsonl | 1 + 5 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/design/decisions/O6-two-family-names.md b/docs/design/decisions/O6-two-family-names.md index fbc9ca76c..db2ab3272 100644 --- a/docs/design/decisions/O6-two-family-names.md +++ b/docs/design/decisions/O6-two-family-names.md @@ -271,5 +271,6 @@ 9. **A bound given-name word counts with the word it completes**, whether or not it is also a particle and whether or not group kept P12's phrase tag on it, which it keeps only where it joined the pair (code review): `عبد الله حسن` divides `عبد الله` | `حسن` before a comma as without one, and `Abu Bakr Siddiq` alike, and `abdul Rahman Khan` before a comma (comma-less, `Ali abdul Rahman Khan` keeps the pair a middle name, O6 taking no bound pair, so its families differ); a bound pair behind a particle is the particle's one word (`de Umm Ali Hasan` divides `de Umm Ali` | `Hasan`, in both writings). `_family_word_count`, which decides whether O6 takes a word, still counts a bound pair as one only by P12's phrase tag, so `Juan abdul Rahman Khan` takes nothing and reads family `Khan` while `abdul Rahman Khan, Juan` divides: the families differ, so the two writings are not held to one division there. Given-first, `Abd El Kader Haddou` reads given `Abd` and family `El Kader Haddou`, which now divides (`El Kader` | `Haddou`), whole on master. 10. **A hyphenated word is one unit beside a second surname**, as the take already counted it (`Andrés Sánchez-Cid Torres`, 2026-11-03 #959), so a family holding one beside a plain word divides where it is read without a take; a family that is one hyphenated word stays whole, the hyphen question decisions/R10 holds open. Seven ORCID families moved so: `de la Rubia Gómez-Moran`, `Aldámiz-Echevarría Iraurgui`, `Saint-Hilaire Tavares`, `Garciarena- Pedroso`, `-Acuña Hernández`, `Aguilar -G` (a stray hyphen read as a word) and `De la cruz-La rosa`, the last cut inside what its writer meant as two hyphen-joined surnames (`De la cruz` | `La rosa` read `De la cruz-La` | `rosa`), accepted as the writer's spacing. - **Measured** 2026-11-19 on the branch against a checkout of `6560abde`, the master it was cut from (the final tree rebased onto `4b0b9441`, #1480, which reads every name of this population as `6560abde` does, the design-docs review re-running the dump on both), both trees parsing 296,151 names (every committed corpus name, every `tests/v2/cases.py` text, and the ORCID names and credit names above) under 13 configurations: the default; and the bare switch, `locales.ES`, the switch with `capitals_as_family` and the switch with `middle_as_family`, each under the three orders. No field, no ambiguity report and no `str()` moved in any configuration, and nothing moved under the default. The views moved, under `locales.ES` given-first, for 6,672 names: 3,270 behind a P10 given name, 2,312 particle-led, 1,028 before a family comma, all filled, and 62 emptied by item 8; under FAMILY_FIRST for 1,117 (1,018 before a comma, 6 particle-led, 93 emptied) and under FAMILY_FIRST_GIVEN_LAST for 1,116. The bare switch moved 6,671, 1,141 and 1,140; with `capitals_as_family` given-first 536 names moved that the bare switch did not move (a set difference), O9's family divided. On the ORCID records, the families read as the holder's box with two name words or more that are divided rose from 166,695 to 171,654; the P10 shape fell from 3,204 to 7 (each with three name words behind the phrase) and the particle-led two-word shape from 1,756 to 0. Of the credit names written with one comma whose two-word head is the holder's family box, 566 of 625 divide (0 before); in the other 59 either the comma is not read as a family comma (`González Ruiz, MA` reads `MA` as a credential) or the head is one unit (`Dos Santos, Priscila`). `local_agreement.py orcid-researchers --base` under the default matches the base; `cldr_agreement.py` matches every default record, and under the ES pack two `sorting` renderings now agree (`Pablo Pérez, Sr. Miguel Ángel Juan Antonio`), re-recorded. The principle's grid (`tests/v2/pipeline/test_post_rules.py`) holds 1,659 pairs whose two writings read one family, none disagreeing; with the comma's division switched off 1,241 disagree, and on `6560abde` 941. Frames per warm parse (`sys.setprofile` call events, py3.11): the default unchanged (the reference row 196, `Smith, John` 98, `Gabriel García Márquez` 159); under `locales.ES` `Gabriel García Márquez` 198 to 202, `García Márquez, Gabriel` 165 to 175, `Juan de la Vega Ruiz` 176 to 187, `María del Carmen García López` 256 to 264 and `Smith, John` 99 to 100, the cost being the marked words' copies. + - **The Portuguese packs.** Rebased onto `d12af9d6` (#1481), which turns the switch on in `locales.PT_BR` and `PT_PT`, the change was measured again under both packs against that master: over every committed corpus text and the ORCID names and credit names of Portugal, Brazil, Angola, Mozambique and Cape Verde (both boxes filled), no field, report or `str()` moves; the views move for 9,553 names under each pack, 4,917 a family opening with a particle (`A. Manuel de Oliveira Duarte` gives `de Oliveira` | `Duarte`), 3,464 behind a P10 phrase or a particle chain the head did not open, 1,097 before a family comma (`ALVES DE OLIVEIRA, Luiz Henrique`), all filled, and 75 emptied by item 8. A family of three surnames, the commonest Portuguese misreading #1453 measured, is three units and left whole. - Recompute: the ORCID shape classes count a family's name words as the words that are no particle and no connective, each hyphen-joined part a word, with the parse's own tags (so a family `García-López` is a hyphen class of two name words, 16,630 undivided on `6560abde` and 16,623 now, where #1479's table, counting a hyphenated word as one, held 17); in each tree (the base imported with `PYTHONSAFEPATH=1` from outside the worktree, its `nameparser.__file__` asserted), parse every text of `tools/differential/corpus*.jsonl`, `tests/v2/cases.py` and the ORCID records named above with their credit names under each configuration, and compare the seven fields, the ambiguity kinds, `str()`, `surname1` and `surname2` name by name; a move is attributed to a shape by the parse's own roles (a family word before the first comma, a middle opening with a particle, a family opening with one). - Open: whether a family a connective or a hyphen joins reads as two units, held by decisions/R10. diff --git a/docs/migrate.rst b/docs/migrate.rst index f1c34af00..dad1aeef7 100644 --- a/docs/migrate.rst +++ b/docs/migrate.rst @@ -2221,8 +2221,8 @@ case, as it writes ``bin``: The second surname under two family names ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Under ``two_family_names``, as the ``es``, ``es_ar``, ``cs`` and ``sk`` -packs turn it on, the ``surname1`` and ``surname2`` views divide a +Under ``two_family_names``, as the ``es``, ``es_ar``, ``cs``, ``sk``, +``pt_br`` and ``pt_pt`` packs turn it on, the ``surname1`` and ``surname2`` views divide a family of two surnames however the family was read, where 3.0 and 3.1 left it whole: written before a family comma, opening with a particle, and behind a given name a particle completes. No field moves: diff --git a/docs/release_log.rst b/docs/release_log.rst index 213ca0da5..9b6a61677 100644 --- a/docs/release_log.rst +++ b/docs/release_log.rst @@ -4,7 +4,7 @@ Release Log nameparser 3.2 is under development. - - **Fix the surname1 and surname2 views, which left a family of two surnames whole before a family comma, opening with a particle, or behind a given name a particle completes.** Under ``two_family_names``, as ``locales.ES``, ``ES_AR``, ``CS`` and ``SK`` turn it on, ``parser_for(locales.ES).parse("García Márquez, Gabriel")`` gives surname1 ``García``, surname2 ``Márquez``, as ``Gabriel García Márquez`` does, where 3.0.0 through 3.1.0 gave surname1 ``García Márquez``, surname2 ``''``. No field moves; a family joined by ``y`` or written as one hyphenated word stays whole, and so, where 3.0.0 through 3.1.0 divided them, do a lone particle and the word after it under a family-first order (``Van Gogh``) and a Turkic father's name with its marker; with ``capitals_as_family`` on too, the family the capitals name is divided. :issue:`1456`, :issue:`1479` + - **Fix the surname1 and surname2 views, which left a family of two surnames whole before a family comma, opening with a particle, or behind a given name a particle completes.** Under ``two_family_names``, as ``locales.ES``, ``ES_AR``, ``CS``, ``SK``, ``PT_BR`` and ``PT_PT`` turn it on, ``parser_for(locales.ES).parse("García Márquez, Gabriel")`` gives surname1 ``García``, surname2 ``Márquez``, as ``Gabriel García Márquez`` does, where 3.0.0 through 3.1.0 gave surname1 ``García Márquez``, surname2 ``''``. No field moves; a family joined by ``y`` or written as one hyphenated word stays whole, and so, where 3.0.0 through 3.1.0 divided them, do a lone particle and the word after it under a family-first order (``Van Gogh``) and a Turkic father's name with its marker; with ``capitals_as_family`` on too, the family the capitals name is divided. :issue:`1456`, :issue:`1479` - **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/tools/differential/corpus_rules.jsonl b/tools/differential/corpus_rules.jsonl index 73bdd9acb..9b32e8a59 100644 --- a/tools/differential/corpus_rules.jsonl +++ b/tools/differential/corpus_rules.jsonl @@ -2007,6 +2007,7 @@ "طارق عبد العزيز" "عبد اللطيف عبد الحميد" "عبد الله" +"عبد الله حسن, علي" "علي عبد الکریم" "محمد بن سلمان" "محمد عبد القريشي" diff --git a/tools/differential/snapshot.jsonl b/tools/differential/snapshot.jsonl index a447d6b18..aa066646a 100644 --- a/tools/differential/snapshot.jsonl +++ b/tools/differential/snapshot.jsonl @@ -6166,6 +6166,7 @@ {"name": "عبد اللطيف عبد الحميد", "given": "عبد اللطيف", "family": "عبد الحميد", "initials": "ع. ا. ع. ا."} {"name": "عبد الله", "given": "عبد", "family": "الله", "initials": "ع. ا."} {"name": "عبد الله الحقيل", "given": "عبد الله", "family": "الحقيل", "initials": "ع. ا. ا."} +{"name": "عبد الله حسن, علي", "given": "علي", "family": "عبد الله حسن", "initials": "ع. ع. ا. ح."} {"name": "عبد الهادي الباني", "given": "عبد الهادي", "family": "الباني", "initials": "ع. ا. ا."} {"name": "عبد الوكيل الهاشمي", "given": "عبد الوكيل", "family": "الهاشمي", "initials": "ع. ا. ا."} {"name": "عبد الکریم عبد الحمید سید ایم پی", "given": "عبد الکریم", "middle": "عبد الحمید سید ایم", "family": "پی", "initials": "ع. ا. ع. ا. س. ا. پ."} From 4a4094f7eebb4c92db5be1a2f229c357dee50e8c Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Thu, 19 Nov 2026 14:30:48 -0800 Subject: [PATCH 3/4] Record the four questions the PR raised as decided (#1456, #1479) The capitals family is divided, the moves the issues did not ask for are accepted, a lone particle ending a family stays the second unit, and the connective and the one-word hyphen stay open; decided 2026-11-19. Co-Authored-By: Claude Opus 5.5 --- docs/design/decisions/O6-two-family-names.md | 5 +++-- docs/design/decisions/O9-words-in-capitals-as-the-family.md | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/design/decisions/O6-two-family-names.md b/docs/design/decisions/O6-two-family-names.md index db2ab3272..078f9de13 100644 --- a/docs/design/decisions/O6-two-family-names.md +++ b/docs/design/decisions/O6-two-family-names.md @@ -267,10 +267,11 @@ 5. **The family-first orders.** The take's family-first cut already divided a chain after a family-first family (2026-11-03 #1024); the comma form divides alike under all three orders, which `test_both_writings_of_one_family_read_the_same_units` holds. 6. **The P10 shape was a defect**, not a decision: decisions/P10's entry of the same date. 7. **A family ending in a standalone patronymic marker under the Turkic rule is left whole**: O2 reads the father's name and the marker of a three-word name as the family and R9 as the patronymic, one unit by decisions/O2's 2026-11-12 #1187 entry, which dividing a family that already held two words would have undone (`Ali Hasan oglu`, and `Hasan oglu, Ali`). The take built the same family in a five-word name and master divided it (`Ali Ahmad Vali Hasan oglu` gave surname1 `Hasan`, surname2 `oglu`); it is whole now too. - 8. **What moved that the issues did not ask.** Routing the take through the same function leaves whole a family the take built that it does not divide as two units: a lone particle as the first unit under a family-first order (`Del Piero Ortega` read `Del`, `Piero`, which rules/O6 and R11 accepted as an error; one unit now, and their Accepted clauses are reworded and deleted), a lone connective taken as a unit (`Carod i Rovira`), and, under a family-first order, a bound given-name word and the unit it completes (`Abd El Kader Haddou` read `Abd`, `El Kader`). Each was a wrong division on master; keeping master's marks there would have needed a second marking path. A first unit of particles alone is refused wherever it arises, not only after a take: `bin Abd Rahman`, whose suffix-tagged `Abd` stops the particle run, would otherwise read `bin` and `Abd Rahman`. A first unit is bare only where a word the vocabulary also lists as a suffix stops the particle run, so the refusal's reach is that shape: `de V, Ali`, which the branch's first build read `de` | `V`, and a particle before a credential under a family-first order (`VAN MD Ali`), whole again; a fix-commit review counted it over a grid of particles before every suffix word and bound word. + 8. **What moved that the issues did not ask, accepted (decided 2026-11-19).** Routing the take through the same function leaves whole a family the take built that it does not divide as two units: a lone particle as the first unit under a family-first order (`Del Piero Ortega` read `Del`, `Piero`, which rules/O6 and R11 accepted as an error; one unit now, and their Accepted clauses are reworded and deleted), a lone connective taken as a unit (`Carod i Rovira`), and, under a family-first order, a bound given-name word and the unit it completes (`Abd El Kader Haddou` read `Abd`, `El Kader`). Each was a wrong division on master; keeping master's marks there would have needed a second marking path. A first unit of particles alone is refused wherever it arises, not only after a take: `bin Abd Rahman`, whose suffix-tagged `Abd` stops the particle run, would otherwise read `bin` and `Abd Rahman`. A first unit is bare only where a word the vocabulary also lists as a suffix stops the particle run, so the refusal's reach is that shape: `de V, Ali`, which the branch's first build read `de` | `V`, and a particle before a credential under a family-first order (`VAN MD Ali`), whole again; a fix-commit review counted it over a grid of particles before every suffix word and bound word. 9. **A bound given-name word counts with the word it completes**, whether or not it is also a particle and whether or not group kept P12's phrase tag on it, which it keeps only where it joined the pair (code review): `عبد الله حسن` divides `عبد الله` | `حسن` before a comma as without one, and `Abu Bakr Siddiq` alike, and `abdul Rahman Khan` before a comma (comma-less, `Ali abdul Rahman Khan` keeps the pair a middle name, O6 taking no bound pair, so its families differ); a bound pair behind a particle is the particle's one word (`de Umm Ali Hasan` divides `de Umm Ali` | `Hasan`, in both writings). `_family_word_count`, which decides whether O6 takes a word, still counts a bound pair as one only by P12's phrase tag, so `Juan abdul Rahman Khan` takes nothing and reads family `Khan` while `abdul Rahman Khan, Juan` divides: the families differ, so the two writings are not held to one division there. Given-first, `Abd El Kader Haddou` reads given `Abd` and family `El Kader Haddou`, which now divides (`El Kader` | `Haddou`), whole on master. 10. **A hyphenated word is one unit beside a second surname**, as the take already counted it (`Andrés Sánchez-Cid Torres`, 2026-11-03 #959), so a family holding one beside a plain word divides where it is read without a take; a family that is one hyphenated word stays whole, the hyphen question decisions/R10 holds open. Seven ORCID families moved so: `de la Rubia Gómez-Moran`, `Aldámiz-Echevarría Iraurgui`, `Saint-Hilaire Tavares`, `Garciarena- Pedroso`, `-Acuña Hernández`, `Aguilar -G` (a stray hyphen read as a word) and `De la cruz-La rosa`, the last cut inside what its writer meant as two hyphen-joined surnames (`De la cruz` | `La rosa` read `De la cruz-La` | `rosa`), accepted as the writer's spacing. + 11. **A lone particle ending a family stays the second unit (decided 2026-11-19)**, as the comma-less name already read it on master (`Juan García de` gives `García` | `de`), so the comma writing agrees (`Beethoven van, Ludwig` under FAMILY_FIRST gives `Beethoven` | `van`); two particles ending it are no unit and leave it whole (`Smith van der, Juan`). - **Measured** 2026-11-19 on the branch against a checkout of `6560abde`, the master it was cut from (the final tree rebased onto `4b0b9441`, #1480, which reads every name of this population as `6560abde` does, the design-docs review re-running the dump on both), both trees parsing 296,151 names (every committed corpus name, every `tests/v2/cases.py` text, and the ORCID names and credit names above) under 13 configurations: the default; and the bare switch, `locales.ES`, the switch with `capitals_as_family` and the switch with `middle_as_family`, each under the three orders. No field, no ambiguity report and no `str()` moved in any configuration, and nothing moved under the default. The views moved, under `locales.ES` given-first, for 6,672 names: 3,270 behind a P10 given name, 2,312 particle-led, 1,028 before a family comma, all filled, and 62 emptied by item 8; under FAMILY_FIRST for 1,117 (1,018 before a comma, 6 particle-led, 93 emptied) and under FAMILY_FIRST_GIVEN_LAST for 1,116. The bare switch moved 6,671, 1,141 and 1,140; with `capitals_as_family` given-first 536 names moved that the bare switch did not move (a set difference), O9's family divided. On the ORCID records, the families read as the holder's box with two name words or more that are divided rose from 166,695 to 171,654; the P10 shape fell from 3,204 to 7 (each with three name words behind the phrase) and the particle-led two-word shape from 1,756 to 0. Of the credit names written with one comma whose two-word head is the holder's family box, 566 of 625 divide (0 before); in the other 59 either the comma is not read as a family comma (`González Ruiz, MA` reads `MA` as a credential) or the head is one unit (`Dos Santos, Priscila`). `local_agreement.py orcid-researchers --base` under the default matches the base; `cldr_agreement.py` matches every default record, and under the ES pack two `sorting` renderings now agree (`Pablo Pérez, Sr. Miguel Ángel Juan Antonio`), re-recorded. The principle's grid (`tests/v2/pipeline/test_post_rules.py`) holds 1,659 pairs whose two writings read one family, none disagreeing; with the comma's division switched off 1,241 disagree, and on `6560abde` 941. Frames per warm parse (`sys.setprofile` call events, py3.11): the default unchanged (the reference row 196, `Smith, John` 98, `Gabriel García Márquez` 159); under `locales.ES` `Gabriel García Márquez` 198 to 202, `García Márquez, Gabriel` 165 to 175, `Juan de la Vega Ruiz` 176 to 187, `María del Carmen García López` 256 to 264 and `Smith, John` 99 to 100, the cost being the marked words' copies. - **The Portuguese packs.** Rebased onto `d12af9d6` (#1481), which turns the switch on in `locales.PT_BR` and `PT_PT`, the change was measured again under both packs against that master: over every committed corpus text and the ORCID names and credit names of Portugal, Brazil, Angola, Mozambique and Cape Verde (both boxes filled), no field, report or `str()` moves; the views move for 9,553 names under each pack, 4,917 a family opening with a particle (`A. Manuel de Oliveira Duarte` gives `de Oliveira` | `Duarte`), 3,464 behind a P10 phrase or a particle chain the head did not open, 1,097 before a family comma (`ALVES DE OLIVEIRA, Luiz Henrique`), all filled, and 75 emptied by item 8. A family of three surnames, the commonest Portuguese misreading #1453 measured, is three units and left whole. - Recompute: the ORCID shape classes count a family's name words as the words that are no particle and no connective, each hyphen-joined part a word, with the parse's own tags (so a family `García-López` is a hyphen class of two name words, 16,630 undivided on `6560abde` and 16,623 now, where #1479's table, counting a hyphenated word as one, held 17); in each tree (the base imported with `PYTHONSAFEPATH=1` from outside the worktree, its `nameparser.__file__` asserted), parse every text of `tools/differential/corpus*.jsonl`, `tests/v2/cases.py` and the ORCID records named above with their credit names under each configuration, and compare the seven fields, the ambiguity kinds, `str()`, `surname1` and `surname2` name by name; a move is attributed to a shape by the parse's own roles (a family word before the first comma, a middle opening with a particle, a family opening with one). - - Open: whether a family a connective or a hyphen joins reads as two units, held by decisions/R10. + - Open (decided 2026-11-19 to stay open): whether a family a connective joins, or one hyphenated word, reads as two units, held by decisions/R10. diff --git a/docs/design/decisions/O9-words-in-capitals-as-the-family.md b/docs/design/decisions/O9-words-in-capitals-as-the-family.md index 117f25a45..91da0ce81 100644 --- a/docs/design/decisions/O9-words-in-capitals-as-the-family.md +++ b/docs/design/decisions/O9-words-in-capitals-as-the-family.md @@ -36,4 +36,4 @@ Open: [#1402](https://github.com/derek73/python-nameparser/issues/1402) (a bare - **2026-11-12 #659, the FOURTH REVIEW — THE PEEL COMES BEFORE THE RUN IS CHOSEN, AND A MARKER IS NO CAPITALS WORD.** (A marker excluded in any position superseded by the FIFTH REVIEW entry, which excludes it only where another capitals word is left to be the family.) An independent code review of PR #1363 at 8b3ca491 (switch off byte-identical to the base over 591,210 rows) found three defects, each reproduced on that head. The run chosen was the last, and the peel worked inside it, so a credential a name word cut off from the family became the family (`DUPONT Marie MBA` read given `DUPONT`, family `MBA`; `DUPONT Marie JR`, `Marie DUPONT Jr. MBA`, `Marie DUPONT M.D. PHD` and `Marie DUPONT Esq. MBA` the same): the suffix slot is now read from the end before any run is chosen, past a suffix written otherwise, peeling a listed credential, generation or numeral in capitals wherever a capitals word that is no particle is left, and the last run of the words left is the family. Under a patronymic rule a marker written in capitals joined the family while the patronymic view claimed it (`ALIYEV Ilham Heydar OGLU` under `locales.TR_AZ` read family `OGLU`, patronymic `Heydar OGLU`; `Mehriban Arif QIZI PAŞAYEVA` family `QIZI PAŞAYEVA`; `ИВАНОВ Иван ИВАНОВИЧ` under the East Slavic rule family `ИВАНОВИЧ`): a word the rule in force reads as its marker is no capitals word, and a grid test holds that the switch moves no such word into the family. The invariant the review proposed, that the family and the patronymic view never share a word, does not hold with the switch off: R9 reads a Turkic marker with the word before it whatever field that word is in, and 5,648 of the grid's three-word rows share one with the switch off (measured 2026-11-12), which is R9's own reading. And `_assign`'s `order` report, which stands down for `initials_as_family`, survived where this rule acted (`Anna Q. MD`, `Vega Y. JR`): the THIRD REVIEW entry's drop covers it. The review's scaling finding: a quadratic in one run's length passed the row of four-word runs, so a long-run row holds one run's length at a base of 3,200 units, where a planted copy per word read 7.50x against the tree's 4.39x (the shared base of 800 let it pass at 4.83x), and the leading-conjunction trim no longer pops from the front. Recorded as accepted rather than changed: a lowercase conjunction chained into a unit beside the given name (`MARTIN y Ana Maria` → given `y Ana`, `MARTIN y Ana` → given `Ana`); a capitals word with any letters glued in front, a capital among them or not (`Jean-PIERRE`, `DuPONT`, `eBAY`); an empty part before a comma read by nothing (`, DUPONT Marie`); and shapes no list writes (`MARY III Smith`, `Mary AND AND AND SMITH`, `Anna Y MD Mary`, `de Marie DUPONT`'s initials `d. M. D.`). - **2026-11-12 #659, the FIFTH REVIEW — A MARKER STAYS THE FAMILY WHERE NOTHING ELSE CAN BE, AND A CONJUNCTION IS NO NAME WORD FOR THE PEEL.** An independent review of 39bf6d34 (switch off byte-identical to its parent over 893,256 parses) found three defects and a rule-text error. The FOURTH REVIEW's marker exclusion tested the spelling in any position, so a surname spelled like a marker lost the family where R9 reads no patronymic (`ABRAMOVICH Roman` and `АБРАМОВИЧ Роман` under the East Slavic rule read given `ABRAMOVICH`; `Ivan PETROVICH Smith` family `Smith`; `OGLU Ahmed` under the Turkic rule given `OGLU`): a marker is now left out of the run only where another capitals word that is no particle, conjunction or marker is left to be the family, and the grid test holds both directions. The peel's count of capitals words it must leave counted a conjunction, which the run then trims, so the switch stood down (`Hugo AND LAC` read given `Hugo AND LAC`; `Marie AND CPA`, `Anna OF MA`, `Marie THE LAC` the same; `John Smith AND MD` family `Smith AND`, suffix `MD`): it now passes a conjunction over by the same predicate the runs use. The peel tested membership against its list of peeled words, a quadratic (`Ann DUPONT` + `MBA` × N read 8.22x for 4x at 3,200): a set now, and a scaling row of trailing credentials holds it. The rule text that scoped S6's, S11's and O9's precedence to "the only word of its run" was wrong once the peel crosses the name (`DUPONT Marie MA`, `DUPONT Marie KC`, `DUPONT Jean FILS` read suffix): the scope is the only capitals word before the first comma that is no particle, conjunction or marker. Recorded as accepted: a lowercase joining word the parse read as a suffix ends the peel (`Ivan FAN R IVANOV MD de` → family `IVANOV MD`); `SIR John MD` → family `SIR`, suffix `MD`; a capitals word right before a marker in other case is both the family and the patronymic view's father's name (`AHMED Kyzy` under the Turkic rule, present in the parent too), so O9's precedence sentence now says the view is read over the words in their written order; and a joining word before a letter leaves the reports and the given-middle split to the order (`ALLIOT-MARIE Anna y V PhD`, present in the parent too). After this entry the rule is frozen for the first PR: a further unwritten shape is recorded, not handled. - **2026-11-12 #659, the RECORDED SHAPES — FOUR UNWRITTEN SHAPES KEPT AS THEY READ, AND THE PRECEDENCE SCOPE CORRECTED.** With the rule frozen, the shapes found after the FIFTH REVIEW are recorded in rules/O9's Accepted bullets rather than handled, the readings taken from the tree at c61f64b9: under the East Slavic rule `ABRAMOVICH Roman MBA` reads given `ABRAMOVICH`, middle `Roman`, family `MBA`, the marker exclusion asking whether another capitals word is left before the peel takes the credential (`ABRAMOVICH Roman, MBA` and `IVANOV Roman MBA` read family `ABRAMOVICH` and `IVANOV`); under the Turkic rule, with O2's three-word reading merged from #1187, `Aidai MEDERBEK kyzy` reads family `MEDERBEK`, middle `kyzy`, and `Aidai Mederbek KYZY` family `KYZY`, middle `Mederbek`, where the switch off reads family `MEDERBEK kyzy` and `Mederbek KYZY` (the four-word `ALIYEV Ali Ahmad oglu` is unchanged, family `ALIYEV`); `Hugo AND LAC` reads given `Hugo AND`; `Ivan PETROVICH IVANOVICH` under the East Slavic rule reads family `PETROVICH IVANOVICH` and no patronymic; and `DR ABRAMOVICH Roman` reads family `DR`, given `ABRAMOVICH` under that rule and family `DR ABRAMOVICH` without it. None is written in any cached list (the parliaments' Turkic names are four words, the family in capitals). The first two are pinned by test rows stating the accepted reading. The FIFTH REVIEW's scope for S6's, S11's and O9's precedence, "the only capitals word before the first comma that is no particle, conjunction or marker", misdescribed two shapes: a numeral after the word is no capitals word the peel must leave (`Jean Pierre FILS III` → family `FILS`, suffix `III`), and of two listed credentials ending the name the first is the family where nothing before it can be (`Marie MA MBA` → family `MA`, suffix `MBA`). The scope now reads: the word ending the name is the family where no other capitals word before it and before the first comma can be, the listed credentials and numerals after it coming off first. No reading moved. -- 2026-11-19 #1456, #1479 — O6 DIVIDES THE FAMILY THE CAPITALS NAMED. With both switches on, O6 still takes no word into a family this rule named, and now divides that family by its own words where it holds two units (`Ana GARCÍA LÓPEZ` gives surname1 `GARCÍA`, surname2 `LÓPEZ`), as it divides every family since decisions/O6's 2026-11-19 #1456, #1479 entry: the division is a function of the family's words, so it does not ask which rule read them. No field moves. Where this rule misreads given names in capitals as the family (`ABRAHAM ELEAZAR Quipuscoa Jiménez`), the division divides them too. +- 2026-11-19 #1456, #1479, decided 2026-11-19 — O6 DIVIDES THE FAMILY THE CAPITALS NAMED. With both switches on, O6 still takes no word into a family this rule named, and now divides that family by its own words where it holds two units (`Ana GARCÍA LÓPEZ` gives surname1 `GARCÍA`, surname2 `LÓPEZ`), as it divides every family since decisions/O6's 2026-11-19 #1456, #1479 entry: the division is a function of the family's words, so it does not ask which rule read them. No field moves. Where this rule misreads given names in capitals as the family (`ABRAHAM ELEAZAR Quipuscoa Jiménez`), the division divides them too. From 7aeb4a0322316509ace170779bef8ec6373860e9 Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Thu, 19 Nov 2026 14:35:39 -0800 Subject: [PATCH 4/4] State the decided trailing particle in rules/O6 and its Standing line (#1456, #1479) The review of the decision commit found the lone particle ending a family decided only in a Log item, the rule's wording predicting a division for Smith van der, Juan, which the code leaves whole. Co-Authored-By: Claude Opus 5.5 --- docs/design/decisions/O6-two-family-names.md | 2 +- docs/design/rules/O6-two-family-names.md | 5 +++++ tools/differential/corpus_rules.jsonl | 2 ++ tools/differential/snapshot.jsonl | 2 ++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/design/decisions/O6-two-family-names.md b/docs/design/decisions/O6-two-family-names.md index 078f9de13..fab39bae8 100644 --- a/docs/design/decisions/O6-two-family-names.md +++ b/docs/design/decisions/O6-two-family-names.md @@ -10,7 +10,7 @@ - Both family names stay in `family` through 2.x; a second-surname field is the RFC's Phase 4 output model (docs/design/vocabulary-model-rfc.md, "The rules a pack can choose"), and a pack may later switch this rule on — 2026-10-24 #754; landed as the `surname2` view, `family` keeping both, 2026-10-29 #754, sub-phase 4d. - The family's words are counted as P1's fold counts them, a connective join and a hyphen counting as their words, so a family already holding two keeps what it has; the word taken must count as one, a hyphenated word counting as one there unless it writes given names (each part a listed given name or an initial), and be no initial written alone — 2026-10-24 #754; 2026-11-03 #959 (Derek). - A name its script (W4) reads in an order other than the declared `name_order` is left alone; where the two agree it is read like any other — 2026-10-24 #754. -- A family is divided into its two units by its own words, one function every path calls, so the two writings of one name give the same units wherever they give the same family: P1's fold units over the family in written order, divided where there are exactly two, after the rule takes a word, where the family already held two words (a particle chain, the family a P10 phrase leaves), where O9's capitals named it, and before a family comma where no word from after the comma joined it and its script sets no other order. A family opening with a particle divides after the particles and the one word they attach to; one of three units or more, a connective's, a name written `shared`, one whose first unit is particles alone and, under the Turkic rule, the father's name and its marker stay whole; a bound given-name word counts with the word it completes; no given-name list vetoes a word before a comma — 2026-11-19 #1456, #1479. +- A family is divided into its two units by its own words, one function every path calls, so the two writings of one name give the same units wherever they give the same family: P1's fold units over the family in written order, divided where there are exactly two, after the rule takes a word, where the family already held two words (a particle chain, the family a P10 phrase leaves), where O9's capitals named it, and before a family comma where no word from after the comma joined it and its script sets no other order. A family opening with a particle divides after the particles and the one word they attach to; one of three units or more, a connective's, a name written `shared`, one whose first unit is particles alone (a lone particle ending it is its second unit, two are none) and, under the Turkic rule, the father's name and its marker stay whole; a bound given-name word counts with the word it completes; no given-name list vetoes a word before a comma — 2026-11-19 #1456, #1479. - Under a family-first order the first two name words are the family, the remainder laid out as the positions after a family — 2026-10-24 #754. - Under a family-first order a particle chain after the family is cut where P1's family-first fold cuts its own run, its particles and the one name word they attach to taken, so `Pérez de la Vega Juan` reads family 'Pérez de la Vega', given 'Juan'; without the switch, or under the default order, the chain stays whole — 2026-11-03 #1024. - The switch runs before `middle_as_family` and is not refused beside it: given-first, the two together read as `middle_as_family` alone — 2026-10-24 #754. diff --git a/docs/design/rules/O6-two-family-names.md b/docs/design/rules/O6-two-family-names.md index 5a64f9a2f..35a45ec73 100644 --- a/docs/design/rules/O6-two-family-names.md +++ b/docs/design/rules/O6-two-family-names.md @@ -187,6 +187,11 @@ "Flores Jorge Ana" family-first+two_family_names+es_given_names → given="Jorge" "Flores Jorge Ana" family-first-given-last+two_family_names+es_given_names → middle="Jorge" ``` +- A particle ending a family is a unit of its own where it stands alone, so it is the second surname, as the take reads `Juan García de`, before a comma too; two ending it are no unit and leave the family whole. + ``` + "Beethoven van, Ludwig" family-first+two_family_names → surname2="van" + "Smith van der, Juan" two_family_names → surname2="" + ``` - The rule reports nothing: the caller declared the convention, as a declared order is followed without a report, and a report on most names of three words or more would teach the caller to ignore the field. --- diff --git a/tools/differential/corpus_rules.jsonl b/tools/differential/corpus_rules.jsonl index 9b32e8a59..ca10e2143 100644 --- a/tools/differential/corpus_rules.jsonl +++ b/tools/differential/corpus_rules.jsonl @@ -196,6 +196,7 @@ "Batyn Sükhee" "Beethoven Ludwig Maria van" "Beethoven Ludwig van" +"Beethoven van, Ludwig" "Beethoven, Ludwig van" "Berg Jan de Jr." "Berg, Jan van der" @@ -1601,6 +1602,7 @@ "Smith née Jones PhD" "Smith van der Berg V, John" "Smith van der V, John" +"Smith van der, Juan" "Smith vd v, John" "Smith y V" "Smith y V, John" diff --git a/tools/differential/snapshot.jsonl b/tools/differential/snapshot.jsonl index aa066646a..4f4d90072 100644 --- a/tools/differential/snapshot.jsonl +++ b/tools/differential/snapshot.jsonl @@ -474,6 +474,7 @@ {"name": "Beaury-Saurel, Amélie", "given": "Amélie", "family": "Beaury-Saurel", "initials": "A. B."} {"name": "Beethoven Ludwig Maria van", "given": "Beethoven", "middle": "Ludwig Maria", "family": "van", "initials": "B. L. M. v.", "capitalized_force": "Beethoven Ludwig Maria Van"} {"name": "Beethoven Ludwig van", "given": "Beethoven", "middle": "Ludwig", "family": "van", "initials": "B. L. v.", "capitalized_force": "Beethoven Ludwig Van"} +{"name": "Beethoven van, Ludwig", "given": "Ludwig", "family": "Beethoven van", "initials": "L. B."} {"name": "Beethoven, Ludwig van", "given": "Ludwig", "family": "van Beethoven", "ambiguities": ["PARTICLE_OR_GIVEN"], "alternatives": ["PARTICLE_OR_GIVEN: name as middle (declared)"], "initials": "L. B."} {"name": "Begum, Mst Amina", "family": "Begum", "suffix": "Mst Amina", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: name as given (position)"], "initials": "B.", "capitalized_force": "Begum, MST Amina"} {"name": "Bella Cohen Spewack", "given": "Bella", "middle": "Cohen", "family": "Spewack", "initials": "B. C. S."} @@ -4050,6 +4051,7 @@ {"name": "Smith van der", "given": "Smith", "family": "van der", "initials": "S. v. d.", "capitalized_force": "Smith Van Der"} {"name": "Smith van der Berg V, John", "given": "John", "family": "Smith van der Berg", "suffix": "V", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: initial as family (shape)"], "initials": "J. S. B.", "generation": "V"} {"name": "Smith van der V, John", "given": "John", "family": "Smith van der V", "initials": "J. S. V."} +{"name": "Smith van der, Juan", "given": "Juan", "family": "Smith van der", "initials": "J. S."} {"name": "Smith vd v, John", "given": "John", "family": "Smith", "suffix": "vd v", "initials": "J. S.", "capitalized_force": "John Smith VD V", "generation": "v", "credentials": "vd"} {"name": "Smith y V", "given": "Smith", "family": "y", "suffix": "V", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: initial as family (shape)"], "initials": "S. y.", "generation": "V"} {"name": "Smith y V, John", "given": "John", "family": "Smith y V", "initials": "J. S. V."}