From d8b589fe62fbab51986a7f6ab5bd5dda16f09b74 Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Sat, 21 Nov 2026 15:15:06 -0800 Subject: [PATCH 1/5] Read an unlisted mixed-case credential after a comma (MRes, AuD) An unlisted word of letters in mixed case that opens with two capitals or ends in one is the caps shape after a comma, in C4's count, C6's contrast and C16's company, so "Jane Smith, MRes" gives suffix MRes and "Smith, M.B. ChB" suffix "M.B. ChB" (rules/C16's Accepted bullet amended). A capital only inside the word (LeBron), or a hyphen in it (Pharm-D), keeps it a name word; the trailing positions under CapsSuffixes.EVERYWHERE read capitals alone, so "Alex Lee ONeill" keeps its family name. Case repair keeps such a word as written when forced, and the company of a C16 run carries the caps shape's marks. Co-Authored-By: Claude Opus 5.5 --- ...a-credential-after-one-word-and-a-comma.md | 3 +- ...caps-word-needs-the-names-case-contrast.md | 10 ++ ...-that-join-the-ambiguous-class-by-shape.md | 2 + ...a-credential-after-one-word-and-a-comma.md | 6 +- ...caps-word-needs-the-names-case-contrast.md | 12 ++- .../R4-case-repair-reads-the-unjoined-mark.md | 3 +- ...-that-join-the-ambiguous-class-by-shape.md | 6 ++ docs/languages.rst | 6 +- docs/locales.rst | 6 +- docs/policy.rst | 24 ++++- docs/release_log.rst | 1 + nameparser/AGENTS.md | 2 +- nameparser/_pipeline/_classify.py | 2 +- nameparser/_pipeline/_comma.py | 34 +++++-- nameparser/_pipeline/_vocab.py | 35 ++++++- nameparser/_policy.py | 20 ++-- nameparser/_render.py | 7 ++ tests/v2/cases.py | 99 +++++++++++++++++++ tests/v2/pipeline/test_classify.py | 3 +- tests/v2/pipeline/test_vocab.py | 49 +++++++-- tests/v2/test_cases.py | 21 ++-- tests/v2/test_config_diff.py | 4 +- tests/v2/test_locales.py | 5 +- tests/v2/test_parser.py | 7 +- tests/v2/test_render.py | 21 ++++ tools/differential/corpus_rules.jsonl | 11 +++ tools/differential/snapshot.jsonl | 15 ++- 27 files changed, 365 insertions(+), 49 deletions(-) diff --git a/docs/design/decisions/C16-initials-spelling-a-credential-after-one-word-and-a-comma.md b/docs/design/decisions/C16-initials-spelling-a-credential-after-one-word-and-a-comma.md index 43333e2ee..53be1c7de 100644 --- a/docs/design/decisions/C16-initials-spelling-a-credential-after-one-word-and-a-comma.md +++ b/docs/design/decisions/C16-initials-spelling-a-credential-after-one-word-and-a-comma.md @@ -11,7 +11,7 @@ Open: none in this file. ## Log -- 2026-11-10 (Derek), #1238 — INITIALS RUN TOGETHER BEHIND ONE WORD ARE THE GIVEN NAME WHATEVER THEY SPELL. `Jansen, J.P.` read suffix 'J.P.' and no given name, where `Jansen, J.Q.` read given 'J.', middle 'Q.' (rules/T7 parting it): a listed credential never reached C4's count, so the comma was a suffix comma before C5's exception was asked. Dutch lists write every name `Surname, Initials`, and a pair of initials spells a listed credential as often as letters fall together. The issue's three questions were decided on these measures, taken 2026-11-10 against master d4a8a884: +- 2026-11-10 (Derek), #1238 (its acceptance of `Smith, M.B. ChB` as given 'M.' superseded by 2026-11-21 #1516) — INITIALS RUN TOGETHER BEHIND ONE WORD ARE THE GIVEN NAME WHATEVER THEY SPELL. `Jansen, J.P.` read suffix 'J.P.' and no given name, where `Jansen, J.Q.` read given 'J.', middle 'Q.' (rules/T7 parting it): a listed credential never reached C4's count, so the comma was a suffix comma before C5's exception was asked. Dutch lists write every name `Surname, Initials`, and a pair of initials spells a listed credential as often as letters fall together. The issue's three questions were decided on these measures, taken 2026-11-10 against master d4a8a884: GAIN. The Tweede Kamer's open data (3,083 members, initials, particle, title and surname in separate boxes; `Persoon` from the OData feed, read 2026-11-08), composed as `Surname, Initials`: 82 of 1,236 members with dotted initials lost the given name on master, 1 on the branch (`de Roo van Alderwerelt, J.K.H`, three letters behind two name words, C5's Accepted case); `Surname, Initials particle` 23 of 305 → 0; `particle Surname, Initials` 24 of 305 → 1 (`de Nerée tot Babberich, F.J.F.M.`, the same case); `Surname, Title Initials` 41 of 461 → 13, each a degree in front of the initials (`Biekman, MSc A.N.`), which reads as the credential run. COST. `snapshot.py --local --base `: ClinicalTrials.gov officials move 11 of 352,104 distinct names, every one a lone surname before `M.D`/`M.D.`/`M.S` (`Ferguson, M.D.` → given 'M.', middle 'D.', reported); FEC's 2026 individual contributors move 160 of 1,893,964 names, of which 65 are lone runs spelling no common credential (`BATES, D.M.`, `OWENS, J.P.`), 26 `J.D.`, 6 `M.S.`, 2 `M.D.`, 5 another lone two-letter credential, 33 a credential then a name past a second comma (`ARENAS, M.D., MAGDALENA C.`, which read the name as a suffix on master and reads the credential as initials now, as its unlisted twin does), and 23 a run with more behind it (`CLAYTON, A.M. TONY`, `RINEHART, J.D. JR.`, `WRIGHT, M.S. III`); PSC individuals, UK Electoral Commission donors and TSE donors move none. The committed corpora move 2 names (`Andrews, M.D.`, `Smith, A.B.C.`). WHICH HEADS. Every comma head was declined: the 24 ClinicalTrials.gov officials with two words before the comma and a dotted credential (`Bin Zhang, M.D.`, `Le Shen, M.D., Ph.D.`) are all credentials, and would all have moved. One name word is C4's count, and one word as written too, since the count passes over a title word and reads a capitalized particle with its surname as one: the first build moved `Ashley Knight, M.S. BME` (family 'Ashley Knight') and `Bin Zhang, M.D.`, found by the ClinicalTrials.gov run and the grid. So a title word is a word here, and a particle is none only written in lower case before a word with a capital, the Dutch tussenvoegsel's writing (`de Waart, J.P.`); a lower-case particle before a word with no capital keeps the credential (`du juan, M.D.`), while a one-word head in lower case is one word (`smith, M.D.` → given 'M.'). The second review found the numeral strip dropping any word shaped like one (`Le Vi, M.D.`, `Dr. Vi, M.D.`) and a listed single letter (`Smith V, M.D.`, a whole name to C1): a numeral is passed over only in capitals, a suffix word only of two or more letters behind a word, and a title left alone is no surname (`Dr. VI, M.D.`). The code review found a lone capitalized particle (`Le, J.P.`, a Vietnamese surname) and a numeral of two or more letters ending the head (`Jansen VI, J.P.`, C3's count) kept out; both now read as one word. A suffix word is passed over only where it ends the head: one in front of a word is a word (`Dr.B. Akila., M.D`, found by the ClinicalTrials.gov run of that fix). @@ -21,3 +21,4 @@ Open: none in this file. WHERE IT SITS. The first draft amended rules/C5, and the design-docs review found it outside C5's When (two letters, unlisted) and its Signal, overriding C13 and contradicting C11 with neither saying so; it is rules/C16, with a precedence line in C8 and C13, a sentence in C11's first Then bullet, and a line in C1's map. HOW. `_comma.decide` gathers the first such run and passes it to `segment_suffix_reading`, which returns no reading where the run stands in the part's leading run of titles, so the part is the given part; the run is then tagged `initial`, as a run written apart is, so the given part's walk does not peel it as a trailing suffix behind a title, and the report is made there, where the decision was taken. ACCEPTED: `Smith, M.D.` reads given 'M.', middle 'D.', the credential named in the report, the 11 ClinicalTrials.gov names and FEC's handful of lone `M.D.`/`M.S.` the cost; 1.4.0 read all of these given 'J.P.' or 'M.D.' whole, 2.0.0 through 3.0.1 suffix (wheels, 2026-11-10). RECOMPUTE: the Tweede Kamer figures compose `Achternaam`, `Tussenvoegsel`, `Titels` and `Initialen` from the feed's `Persoon` entity in the four forms above and count the parses with an empty given name, in each tree; the local ones are `uv run python tools/differential/snapshot.py --local ctgov-officials --base ` and the same for `fec-individuals`, `psc-individuals`, `ukec-individuals` and `tse-donors`. +- 2026-11-21 #1516 — A MIXED-CASE CREDENTIAL BEHIND THE RUN IS ITS COMPANY. Decided 2026-11-21. `Smith, M.B. ChB` reads suffix 'M.B. ChB', reported, where the #1238 entry accepted given 'M.', middle 'B. ChB' (as 1.4.0 read given 'M.B.', middle 'ChB'), because the caps shape now reads a word in mixed case that opens with two capitals or ends in one after a comma (decisions/C6's 2026-11-21 #1516 entry), and an unlisted capitals word C6 admits behind the run is company, as `Smith, J.P. AUD` read already. A credential written in neither shape stays a name word behind the run (`Smith, M.D. PhDc`, `Smith, M.D. M. Sc.` → given 'M.'), as the rule's Accepted bullet now states. SUPERSEDES: the #1238 entry's acceptance of `Smith, M.B. ChB`. diff --git a/docs/design/decisions/C6-unlisted-all-caps-word-needs-the-names-case-contrast.md b/docs/design/decisions/C6-unlisted-all-caps-word-needs-the-names-case-contrast.md index 13c388f7e..b769a49d2 100644 --- a/docs/design/decisions/C6-unlisted-all-caps-word-needs-the-names-case-contrast.md +++ b/docs/design/decisions/C6-unlisted-all-caps-word-needs-the-names-case-contrast.md @@ -2,6 +2,8 @@ ## Standing +- After a comma, an unlisted word of letters in mixed case that opens with two capitals or ends in one is the caps shape as an all-caps word is, in C4's count, C6's contrast and C16's company (`Jane Smith, MRes` → suffix 'MRes'); a capital only inside the word, or a hyphen or slash in it, keeps it a name word (`Jane Smith, LeBron`, `Jane Smith, Pharm-D` → given), and the trailing positions under `CapsSuffixes.EVERYWHERE` read capitals alone (`Alex Lee ONeill` → family 'ONeill') — 2026-11-21 #1516. + Elsewhere: this rule's decision, that an unlisted all-caps word after the comma joins the ambiguous credential class by default behind two name words, where the name carries a case contrast (`John Smith, XYZ` → suffix 'XYZ'; `Smith, XYZ` → given 'XYZ'; `MÜLLER WEIß, HANS` → given 'HANS'), with its two-letter rule (narrowed for two capitals followed by credentials by decisions/C5's 2026-11-11 #1323 entry, and for two capitals alone before a later part's listed credential by its 2026-11-15 #1392 entry) and the mixed-run membership — decisions/S9's 2026-10-01 (Derek), #564 entry, where the caps shape's switch is decided; the contrast test reused for a suffix word ending the name before the comma — decisions/C12's 2026-10-18 (Derek), #656 entry. Open: none in this file. @@ -10,3 +12,11 @@ Open: none in this file. - 2026-10-01 (Derek), #564 — AN UNLISTED ALL-CAPS WORD IS A CREDENTIAL IN THE PART AFTER A COMMA BEHIND TWO NAME WORDS, BY DEFAULT. The decision, its two-letter rule and the mixed-run membership are recorded under decisions/S9 (#564), where the caps shape's switch has always been decided; this bullet is C6's pointer to it. - 2026-10-18 #728 — SPLIT FROM decisions/C1 with the rule. The entries above were written under decisions/C1 while this rule was part of rules/C1, and moved here unchanged but for the pointers the move broke, the measurement paragraphs, each cut to one line naming its population, counts, baseline and PR, and the superseded passages, each cut to its decision and what replaced it; where one says rules/C1 or C1, it means the rule as it then stood, which held this one. +- 2026-11-21 #1516 — A WORD IN MIXED CASE WRITTEN THE WAY A CREDENTIAL IS JOINS THE CAPS SHAPE AFTER A COMMA. Decided 2026-11-21. An unlisted word of letters in mixed case that opens with two capitals or ends in one (`MRes`, `DClinPsy`, `AuD`, `BScN`) is the caps shape wherever an all-caps word is read after a comma: C4's count, C6's contrast and C16's company (`Jane Smith, MRes` → given 'Jane', family 'Smith', suffix 'MRes', reported, where 1.4.0 through 3.1.0 read given 'MRes', family 'Jane Smith'). Such a word is written neither in capitals nor the way a name is, and no vocabulary lists every degree written so. A capital only inside the word is a name's writing (`LeBron`, `McKenzie`, `DeShawn`), and a word in mixed case holding a hyphen or a slash is left out: a first build took joined chunks too, and given boxes are full of names joined so (`Cheng-I`, `I-Chun`, `Jay-R` in hundreds of ORCID given boxes, `Gul-E` and `Noor-E` in PSC's), so `Pharm-D` stays the given name, as does `PhDc`, whose ends hold one capital. + GAIN. `snapshot.py --local --base `: ClinicalTrials.gov officials 915 moved of 539,368, 776 gaining the credential (`AuD`, `DClinPsy`, `DNSc`, `MBBChir`, `MRes`, `BMedSci` among the words taken, and `PhD` behind them), one reading `MDs` as the credential where it had read `Abd`, and 138 moving only the forced case view or a report's alternative; contacts 652 moved, 580 gaining the credential (`AuD`, `MEd`, `BScN`, `HBSc`) and 72 a case view or an alternative only; ORCID researchers 24 moved, all credentials (`CEng`, `PGDip`, `MAEd`), `local_agreement.py orcid-researchers --base` scoring 5 fixed, 0 broken, 2 changed (wrong either way); FEC, GOV.UK people, UK Electoral Commission donors, DOF signatures, PSC and PatentsView 0 moved, and PSC's and PatentsView's agreement unchanged. + COST. One name of the moved reads wrong, a Catalan given name typed with a doubled capital (`LLuís`) behind a two-word head. Beyond the moved, the shape costs the listing form behind two or more name words what the all-caps shape costs it (`García Márquez, JOSE` → suffix): a given box holding a word of the shape, unlisted, in a record of mixed case, is in 577 of ORCID's 1,831,533 records (typos such as `MAria`, initials glued to a name, and real spellings, Dutch `IJsbrand` and Serbo-Croatian `LJiljana`), 55 PatentsView records and no PSC record, and it moves only where a writer composes `Surname Surname, Given`, which no fielded corpus composes (`de Vries Smit, IJsbrand` → suffix). + WHY NOT EVERYWHERE'S TRAILING POSITIONS. Ending a name without a comma the shape is how a surname typed without its apostrophe is written (`ONeill`, `DSouza`, `OReilly`), and how `McCAFFREY` is: about 770 ORCID family boxes hold such a word alone, each of which would lose its family name in a name of three words under `CapsSuffixes.EVERYWHERE`. So the predicate takes the mixed-case arm only where the comma's decision asks (`caps_shape_candidate`'s `mixed_case`), and classify's trailing tag reads capitals alone (`Alex Lee ONeill` → family 'ONeill' under EVERYWHERE). + CASE REPAIR (rules/R4). A shape word in mixed case is kept as written, forced or not, where the acronym clause wrote `MRES`; and the company a C16 run takes now carries the shape's marks the count gives, so `Smith, J.P. AUD` and `Ashley Knight, M.S. BME` keep their capitals forced, where master wrote `Aud` and `Bme`. + C16. `Smith, M.B. ChB` reads suffix 'M.B. ChB', as `Smith, J.P. AUD` already did; the reversal of that part of decisions/C16's 2026-11-10 #1238 entry is decisions/C16's 2026-11-21 #1516 entry. + THE FILTER'S OWN NARROWING. The comma's C-level filter first widened `isupper()` to `not islower() and not istitle()`, which drops a word of capitals split by a caseless letter (`istitle()` reads `XיZ` title-shaped): the corpus run found the one such word ctgov-contacts holds moved from the suffix to the given name, and the filter keeps `isupper()` as an arm of its own (case row `a_caps_word_holding_a_caseless_letter_stays_a_credential`). + RECOMPUTE: the moves, `snapshot.py --local ctgov-officials --base ` and likewise `ctgov-contacts`, `orcid-researchers`, `fec-individuals`, `govuk-people`, `ukec-individuals`, `dof-signatures`, `psc-individuals`, `patentsview-inventors`; the box counts, over each fielded corpus's `raw.jsonl` in the tools cache, the words of the given box (or the family box alone) that `_vocab._mixed_capitals` admits once NFC-composed and `in_any_wordlist` refuses, in records whose composed `name` is neither all upper nor all lower case, measured against ad9d5d20's lexicon on 2026-11-21. diff --git a/docs/design/decisions/S9-unlisted-words-that-join-the-ambiguous-class-by-shape.md b/docs/design/decisions/S9-unlisted-words-that-join-the-ambiguous-class-by-shape.md index 1b8ea9520..75e57dc75 100644 --- a/docs/design/decisions/S9-unlisted-words-that-join-the-ambiguous-class-by-shape.md +++ b/docs/design/decisions/S9-unlisted-words-that-join-the-ambiguous-class-by-shape.md @@ -10,6 +10,7 @@ Examples name each field as the default order reads it; under the family-first o - At the first slot after a comma, paired initials (two single letters joined by a period, the trailing period optional) are the given name and report (`García Márquez, G.J.` → given names 'G.J.'); only an unambiguous suffix word in front that is not title vocabulary, or a second dotted-shape word in the part, or since #1392 a listed credential in a later comma part where the pair stands alone in its own (decisions/C5's 2026-11-15 entry), makes them the credential run (`John Smith, PhD X.Y.` → suffix 'PhD X.Y.'; `García Márquez, Ms G.J.` → title 'Ms', given names 'G.J.'), while a word behind (`De La Cruz, M.J. PhD`) or a class member in front (`García Márquez, Ed G.J.` → given 'Ed') speaks for nothing, and three letters run together read by the count (`García Márquez, G.J.R.` → suffix 'G.J.R.') — 2026-09-30 #563. - A flip resting only on dotted-shape words is silent (`John Smith, X.Y.Z. G.J.`) unless the only words speaking for a pair are other pairs (`John Smith, X.Y. P.Q.` reports) or a later part's credential (`Jane Doe, M.H., PhD` reports, decisions/C5's 2026-11-15 entry); at the trailing slots paired initials are no word of the class and read as the name word they are written as, reported (`John Smith R.T.` → family 'R.T.', `Doe, John R.T.` → middle 'R.T.'), while three dotted letters keep #516's reading (`John Smith X.Y.Z.` → suffix) — 2026-09-30 #563; 2026-10-24 #864. - `Policy.unlisted_caps_suffixes` takes OFF, AFTER_COMMA or EVERYWHERE, default AFTER_COMMA, and a bool raises: an unlisted all-caps alphabetic word of two or more letters joins the class by shape in the part right after a comma behind two or more name words (`John Smith, XYZ` → suffix 'XYZ', `Smith, XYZ` → given 'XYZ'), beside listed credentials as well as alone (`John Smith, PhD XYZ` → suffix 'PhD XYZ'), and under EVERYWHERE at every suffix position — 2026-10-01 #564. +- After a comma a word in mixed case that opens with two capitals or ends in one is the caps shape too (`Jane Smith, MRes` → suffix 'MRes'); under EVERYWHERE the other positions read capitals alone (`Alex Lee ONeill` → family 'ONeill') — 2026-11-21 #1516, recorded under decisions/C6. - The comma's case contrast is carried by a word of the name before the comma that holds a capital, ends in a lowercase cased letter and is claimed by no wordlist as a non-name, so an all-caps record keeps its given name (`MÜLLER WEIß, HANS`, `LLOYD WEBBER, ANDREW PhD`) and a name written in lowercase reads the listing form (`john smith, XYZ` → given 'XYZ'); a lone two-letter word is not admitted at the comma (`García Márquez, MJ` → given 'MJ') unless a later comma part is a listed credential (`García Márquez, MJ, PhD` → suffix 'MJ, PhD', decisions/C5's 2026-11-15 #1392 entry) — 2026-10-01 #564. - Accepted: a given name written in capitals behind a two-word surname reads as the credential (`García Márquez, GABRIEL` → suffix 'GABRIEL', reported), OFF being the escape; and case repair follows the reading, a caps word in the part a suffix comma opened being tagged under AFTER_COMMA, one in a third or later part only under EVERYWHERE — 2026-10-01 #564. - Under EVERYWHERE the cost is the three-word name (`Jean Pierre DUPONT` → family 'Pierre', suffix 'DUPONT'), while a two-word name keeps its family and reports (`Jean DUPONT`); unlisted is checked by wordlist membership rather than tags (`John Smith NEE` keeps family 'NEE'), and a roman numeral is the numeral fork's before the shape is asked (`John Smith VI` → suffix 'VI') — 2026-09-14 (Derek), corrected 2026-09-18. @@ -53,3 +54,4 @@ Open: none in this file. - 2026-10-25 #752 — THE CAPS SHAPE'S JOINED SPELLING (phase 2d, the unlisted half of item 5 of decisions/vocabulary-model's 2026-10-23 #752 entry, agreed by Derek on 2026-10-23; #797's half A). An unlisted word of capitals in letter chunks joined by `-` or `/`, one chunk of two or more letters, is the caps shape: `John Smith, PU-PH` reads suffix 'PU-PH' with the class's report where 1.4.0 through 2.6.0 read given 'PU-PH', family 'John Smith'. It joins the class exactly where and as the unjoined word does, so the C4 count and C6's case contrast gate it after a comma by default (`JOHN SMITH, PU-PH`, `Smith, PU-PH` → given) and EVERYWHERE takes it at every suffix position, its cost the unjoined word's (`Jean Pierre DUPONT-MORETTI` reads as `Jean Pierre DUPONT` does); keeping it to the comma under EVERYWHERE too was not built, since it would make one shape two by position. "Unlisted" is the whole word in no wordlist, as for the unjoined word; a word whose every chunk counts as a suffix as written is rules/S3's joined credential, read unambiguously before this shape is asked (`MD-PHD`), so the two overlap in no reading. Single-letter chunks alone are how initials are joined (`A-B`) and stay out, and a chunk holding a digit or a period is no letter chunk. REACHABILITY: the comma's candidate list, C12's case-repair marks and classify under EVERYWHERE each ask `isalpha()` and `isupper()` in C before calling the predicate, and the joined spelling fails `isalpha()`, so each pre-filter widened with it to a capitals word holding a joiner; the 2026-10-23 measurement's first run moved nothing for the same reason. MEASURED (2026-10-25, against the phase 2c commit 15d5426f, every local corpus recorded from it with `--tree`): `tools/differential/snapshot.py` moves nothing but the rules' own new examples; `cldr_agreement.py` matches every record; `local_agreement.py psc-individuals` matches its record; tse-donors and fec-individuals, none (FEC is written in one case, so the contrast never admits a word there); ctgov-officials, 529 of 352,104 entries. Of the 529, 519 are a joined capitals word after a comma, now the suffix with a suffix-or-name report (5 of them in a third part, where the comma-structure report stays): 516 had read it as the given name with the name reversed around it, and 3 had read a listed credential opening the part as the given name and the joined word as the middle (`John Smith, MSN ACNP-BC`), the whole part now the suffix. 10 move only in `capitalized(force=True)`, a joined capitals word already in a suffix run now keeping its capitals (rules/R4). The words are 104 distinct credentials and job titles, `PU-PH` (258) and `MCU-PH` (30), the French hospital-university ranks, and `MS-OMPT` (32) the commonest; none is a name. The 2026-10-23 figure, 759, was measured without phase 2c, which now reads about 230 of them as listed credentials. One of the 516 also takes a word before the comma into the suffix, as the unjoined twin reads: a capitals word between a listed credential and the comma (`Jean Claude MD DUPONT, PU-PH` → family 'Claude', suffix 'MD DUPONT, PU-PH', reported), where the part before the comma reads as the name without it (rules/C1) and `Jean Claude MD DUPONT` alone already gives suffix 'MD DUPONT' by rules/S8's run; ACCEPTED here, since it is S8's reading of a capitals surname behind a credential, the same with `XYZ` or `PhD` after the comma. COST: a capitals word holding a joiner pays the caps shape's path, as an unjoined capitals word already does (`SMITH-JONES, MARY-JANE` 175 → 189 profiler frames, py3.11), and a word with a lowercase letter or no joiner pays nothing new (`Mary Smith-Jones` 159, `John Smith, XYZ` 264, before and after). Pinned by the #752 rows of tests/v2/cases.py and `test_caps_shape_candidate_reads_joined_capitals` (tests/v2/pipeline/test_vocab.py). - 2026-10-28 #357 — NO V1 CALLER IS LEFT FOR THE SWITCHES TO MISS (decisions/3-0-reevaluations' 2026-10-28 #357, REMOVAL entry): the 2026-09-14 and 2026-10-01 #564 entries recorded that the shim translated neither switch, so `HumanName` followed both defaults; with the facade removed, every caller reaches both through `Policy`. SUPERSEDES: the v1-shim consequence the 2026-09-14 (Derek), corrected 2026-09-18 and 2026-10-01 (Derek), #564 entries recorded. - 2026-11-11 #1323 — THE UNDOTTED PAIR BEFORE CREDENTIALS IS THE CREDENTIAL RUN, behind two or more name words carrying the contrast. SUPERSEDES, for that one shape, the 2026-10-01 (Derek), #564 entry's '(3)' reading of a two-letter word inside a longer part 'exactly as #563 reads the dotted pair': `Jane Doe, BM PhD` → suffix 'BM PhD', where `John Smith, A.B. Ph.D.` keeps given names 'A.B.'. The measurement and what moved are decisions/C5's 2026-11-11 #1323 entry; a lone two-letter word is still never admitted at the comma. +- 2026-11-21 #1516 — THE CAPS SHAPE READS A WORD IN MIXED CASE AFTER A COMMA, AND NOWHERE ELSE. The decision and its measurement are decisions/C6's 2026-11-21 #1516 entry; this bullet is S9's pointer to it, the trailing positions of `CapsSuffixes.EVERYWHERE` being this rule's. diff --git a/docs/design/rules/C16-initials-spelling-a-credential-after-one-word-and-a-comma.md b/docs/design/rules/C16-initials-spelling-a-credential-after-one-word-and-a-comma.md index c3aedfae9..6e4622a7c 100644 --- a/docs/design/rules/C16-initials-spelling-a-credential-after-one-word-and-a-comma.md +++ b/docs/design/rules/C16-initials-spelling-a-credential-after-one-word-and-a-comma.md @@ -37,6 +37,7 @@ ``` "Smith, M.D. Ph.D." → suffix="M.D. Ph.D." "Smith, M.D. MS" → suffix="M.D. MS" + "Smith, M.B. ChB" → suffix="M.B. ChB" "Smith, M.D. / PhD" → suffix="M.D. / PhD" "Smith, PhD J.P." → suffix="PhD J.P." "Rinehart, J.D. Jr." → given="J." · boundary @@ -53,9 +54,10 @@ **Accepted:** -- A credential the vocabulary does not list whole behind the run is a name word there, as behind a run spelling nothing, though C13 read a credential opening the part as taking it in: 'Smith, M.B. ChB' and 'Smith, M.D. M. Sc.' read the run as the given name, the unlisted chunk with it, as 'Smith, X.Q. ChB' does. +- A credential the vocabulary does not list whole behind the run, and written in neither of the shapes C6 admits, is a name word there, as behind a run spelling nothing, though C13 read a credential opening the part as taking it in: 'Smith, M.D. M. Sc.' and 'Smith, M.D. PhDc' read the run as the given name, the unlisted words with it, as 'Smith, X.Q. ChB' does. ``` - "Smith, M.B. ChB" → given="M." + "Smith, M.D. M. Sc." → given="M." + "Smith, M.D. PhDc" → given="M." ``` - A one-word surname before a credential written as dotted initials reads as a name with no given name written out ('Smith, M.D.' → given 'M.', middle 'D.'), the credential named in the report; a credential then a given name past a second comma ('Arenas, M.D., Magdalena C.') reads as its twin of unlisted letters does. The undotted spelling is the credential's own and is unchanged ('Smith, MD'). diff --git a/docs/design/rules/C6-unlisted-all-caps-word-needs-the-names-case-contrast.md b/docs/design/rules/C6-unlisted-all-caps-word-needs-the-names-case-contrast.md index 5d9f24016..d9d3e2043 100644 --- a/docs/design/rules/C6-unlisted-all-caps-word-needs-the-names-case-contrast.md +++ b/docs/design/rules/C6-unlisted-all-caps-word-needs-the-names-case-contrast.md @@ -1,6 +1,6 @@ # C6 — an unlisted all-caps word needs the name's case contrast -**When:** an unlisted word written in capitals stands in the part after the comma, as in "John Smith, XYZ". +**When:** an unlisted word written in capitals, or in mixed case the way a credential is, stands in the part after the comma, as in "John Smith, XYZ" and "John Smith, MRes". **Then:** an unlisted all-caps word joins the ambiguous credential class (C4, S9) in the part after the comma only where the name carries the contrast: one of its own words before the comma written the way a name is written in mixed case. @@ -8,6 +8,16 @@ ``` "MÜLLER WEIß, HANS" → given="HANS" · boundary ``` +- **A word in mixed case that opens with two capitals or ends in one is written the way a credential is, and reads here as an all-caps word does** ('MRes', 'DClinPsy', 'AuD'): it is not written the way a name is, and the vocabulary cannot list every degree written so. A capital only inside the word is a name's writing ('LeBron', 'McKenzie'), and so is a word in mixed case holding a hyphen or a slash ('Pharm-D', as 'Jay-R' is a given name). The mixed-case word is read after the comma only: S9's other positions read capitals alone. + ``` + "Jane Smith, MRes" → suffix="MRes" + "Jane Smith, AuD" → suffix="AuD" + "Jane Smith, LeBron" → given="LeBron" · boundary + "Jane Smith, PhDc" → given="PhDc" · boundary + "Jane Smith, Pharm-D" → given="Pharm-D" · boundary + "JANE SMITH, MRes" → given="MRes" · boundary + "Smith, MRes" → given="MRes" · boundary + ``` - **A surname written in capitals ends in a capital whatever is glued in front of it, and a word written wholly in lowercase holds none**, so such a record keeps its given name beside its lowercase particles, titles and clauses ("GISCARD d'ESTAING, VALÉRY", 'LLOYD FitzGERALD, RONALD'), and a name written wholly in lowercase reads the listing form. **Because:** capitals are a credential's writing only against a name written otherwise; a name written in capitals, or wholly in lowercase, says nothing about any word in it. diff --git a/docs/design/rules/R4-case-repair-reads-the-unjoined-mark.md b/docs/design/rules/R4-case-repair-reads-the-unjoined-mark.md index 5f0c4ed85..40c815dfe 100644 --- a/docs/design/rules/R4-case-repair-reads-the-unjoined-mark.md +++ b/docs/design/rules/R4-case-repair-reads-the-unjoined-mark.md @@ -90,8 +90,9 @@ "Ronald Macdonald" → capitalized_forced="Ronald MacDonald" "JAMES MACKENZIE" → capitalized="James Mackenzie" · boundary ``` -- **A credential acronym the exceptions map does not carry is an initialism**, so a single-case word the parse put in the suffix role from the acronym vocabulary (written whole across any hyphen or slash it holds, `OTR/L`, not as two name words), or read as a credential by its dotted shape alone (S3) or by its capitals (S9), repairs to its all-caps spelling rather than a title-cased one, and that repair outranks the Mc convention where a word fits both (MCSE, not McSe). A roman numeral the parse put in the suffix role is written in capitals the way a generation is written, whether or not the vocabulary lists it (VI as well as III). A suffix word that is neither an acronym, a numeral nor an exceptions-map entry -- the generational `jr`, `sr` -- keeps its title case. +- **A credential acronym the exceptions map does not carry is an initialism**, so a single-case word the parse put in the suffix role from the acronym vocabulary (written whole across any hyphen or slash it holds, `OTR/L`, not as two name words), or read as a credential by its dotted shape alone (S3) or by its capitals (S9), repairs to its all-caps spelling rather than a title-cased one, and that repair outranks the Mc convention where a word fits both (MCSE, not McSe). A roman numeral the parse put in the suffix role is written in capitals the way a generation is written, whether or not the vocabulary lists it (VI as well as III). A suffix word that is neither an acronym, a numeral nor an exceptions-map entry -- the generational `jr`, `sr` -- keeps its title case. A word read as a credential after a comma by its mixed case (C6) is kept as written, forced or not, its capitals being what made it one. ``` + "Jane Smith, MRes" → capitalized_forced="Jane Smith, MRes" "john smith md" → capitalized="John Smith MD" "john smith m.d." → capitalized="John Smith M.D." "john smith iii." → capitalized="John Smith III." diff --git a/docs/design/rules/S9-unlisted-words-that-join-the-ambiguous-class-by-shape.md b/docs/design/rules/S9-unlisted-words-that-join-the-ambiguous-class-by-shape.md index e3a188356..9b2feee1d 100644 --- a/docs/design/rules/S9-unlisted-words-that-join-the-ambiguous-class-by-shape.md +++ b/docs/design/rules/S9-unlisted-words-that-join-the-ambiguous-class-by-shape.md @@ -13,6 +13,12 @@ "John Smith, Pu-Ph" → given="Pu-Ph" · boundary "Jean Pierre DUPONT-MORETTI" unlisted_caps_suffixes-everywhere → suffix="DUPONT-MORETTI" ``` +- **A word in mixed case written as a credential is ('MRes', 'AuD') is the caps shape after a comma only** (C6): ending a name it is how a surname typed without its apostrophe is written ('ONeill', 'DSouza'), so the caller setting below reads capitals alone there. + ``` + "Jane Smith, MRes" → suffix="MRes" + "Alex Lee ONeill" unlisted_caps_suffixes-everywhere → family="ONeill" · boundary + "Alex Lee MRes" unlisted_caps_suffixes-everywhere → family="MRes" · boundary + ``` - **Where the caps shape is admitted by default.** By default that second shape is admitted in one position only, the part after a comma with two or more name words before it (C4, C6): French and Korean records write the SURNAME in capitals, and that convention puts the capitals at the end of a name or before a comma, never after a comma behind a full name. ``` "John Smith XYZ" → family="XYZ" · boundary diff --git a/docs/languages.rst b/docs/languages.rst index 98c29d0d0..6e2960496 100644 --- a/docs/languages.rst +++ b/docs/languages.rst @@ -125,7 +125,7 @@ titles under ``cs`` wherever a doctorate is one: - title * - Bare, after a comma: ``Jana Malá, MgA`` - title - - name word + - suffix, by its capitals (``MgA``); name word (``mjr``) - suffix - title * - Dotted, after a comma: ``Jana Malá, MgA.`` @@ -155,7 +155,9 @@ at the head of a name or of the part after a comma (see >>> parse("Jan Novák, MUDr").title 'MUDr' - >>> parse("Jana Malá, MgA").family + >>> parse("Jana Malá, MgA").suffix + 'MgA' + >>> parse("Jana Malá, mjr").family 'Jana Malá' >>> czech.parse("Jana Malá, MgA").title 'MgA' diff --git a/docs/locales.rst b/docs/locales.rst index 0a35d46cf..ede473ade 100644 --- a/docs/locales.rst +++ b/docs/locales.rst @@ -1098,9 +1098,11 @@ What a strict choice drops it drops from every name: >>> no_phd = Parser(lexicon=Lexicon.default().remove( ... "phd", kind="credential")) + >>> korean.parse("Kim Min Jun, Phd").suffix + 'Phd' >>> parser_for(ko, base=no_phd, strict=True).parse( - ... "Kim Min Jun, PhD").given - 'PhD' + ... "Kim Min Jun, Phd").given + 'Phd' Which choices can be strict ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/docs/policy.rst b/docs/policy.rst index 0ce0bb333..76c0613f4 100644 --- a/docs/policy.rst +++ b/docs/policy.rst @@ -174,7 +174,8 @@ Brackets and suffixes * - ``unlisted_caps_suffixes`` - :class:`~nameparser.CapsSuffixes` - ``AFTER_COMMA`` - - Where an unlisted all-caps word such as ``XYZ`` reads as a + - Where an unlisted all-caps word such as ``XYZ`` (and after a + comma, a mixed-case one such as ``MRes``) reads as a credential: after a comma (``AFTER_COMMA``), at the end of a name as well (``EVERYWHERE``), or nowhere (``OFF``). See :ref:`unlisted-credentials`. @@ -1323,7 +1324,8 @@ Credentials the vocabulary doesn't list No suffix list holds every post-nominal, so two ``Policy`` fields, both new in 2.4, read an unlisted word as a credential from how it is written: in periods -(``X.Y.Z.``), or in capitals (``XYZ``). The writing cannot settle it +(``X.Y.Z.``), or in capitals (``XYZ``, and after a comma ``MRes``). +The writing cannot settle it alone, because a surname can be written either way, so both fields also decide by position: the word has to stand behind a name that can spare it. For the ones written otherwise, see @@ -1461,7 +1463,12 @@ All-caps words ``unlisted_caps_suffixes`` reads an unlisted word of two or more capital letters, with no period in it, and since 2.7 one of capitals joined by a hyphen or a slash (``PU-PH``, ``MS-OMPT``) with a part of -two or more letters. Its value is a +two or more letters. After a comma it also reads a word of letters in +mixed case that opens with two capitals or ends in one (``MRes``, +``DClinPsy``, ``AuD``), the way degrees are written. A capital only +inside a word (``LeBron``, ``McKenzie``) is a name's writing, and a word +in mixed case holding a hyphen (``Pharm-D``) is left alone, since given +names are written so (``Jay-R``). Its value is a :class:`~nameparser.CapsSuffixes`, because where capitals mean a credential depends on a second convention: many records write the SURNAME in capitals (``"Jean DUPONT"``, ``"DUPONT, Jean"``). @@ -1493,6 +1500,11 @@ all-caps surname convention never writes capitals there: >>> cred = parse("John Smith, PU-PH") >>> cred.family, cred.suffix ('Smith', 'PU-PH') + >>> cred = parse("Jane Smith, MRes") + >>> cred.family, cred.suffix + ('Smith', 'MRes') + >>> parse("Jane Smith, LeBron").given + 'LeBron' ``EVERYWHERE`` ^^^^^^^^^^^^^^ @@ -1500,7 +1512,9 @@ all-caps surname convention never writes capitals there: ``CapsSuffixes.EVERYWHERE`` also reads the end of a name, the given part's last word after a family comma, and the word ending a maiden marker's clause. Those are the places an all-caps surname IS written, -which is why it is not the default: +which is why it is not the default. It reads only words wholly in +capitals there, since a surname typed without its apostrophe +(``ONeill``, ``DSouza``) ends a name in mixed case: .. doctest:: @@ -1516,6 +1530,8 @@ which is why it is not the default: >>> cred = caps_everywhere.parse("Jean Pierre DUPONT") >>> cred.family, cred.suffix ('Pierre', 'DUPONT') + >>> caps_everywhere.parse("Alex Lee ONeill").family + 'ONeill' ``OFF`` ^^^^^^^ diff --git a/docs/release_log.rst b/docs/release_log.rst index 4b7373a41..f8cd9d6fe 100644 --- a/docs/release_log.rst +++ b/docs/release_log.rst @@ -4,6 +4,7 @@ Release Log nameparser 3.2 is under development. + - **Read an unlisted credential written in mixed case after a name and a comma, such as MRes or AuD.** ``parse("Jane Smith, MRes")`` gives suffix ``MRes``, where 1.4.0 through 3.1.0 gave given ``MRes``, family ``Jane Smith``; the word must open with two capitals or end in one, so ``LeBron`` and ``PhDc`` stay given names, and initials spelling a credential before such a word read as the credential with it (``Smith, M.B. ChB``). ``CapsSuffixes.EVERYWHERE`` still reads only words in capitals where no comma stands (``Alex Lee ONeill`` keeps family ``ONeill``). :issue:`1516` - **Add French dit and dite as connectives under a French choice.** With ``languages=frozenset({"fr"})`` chosen, ``Jean Dupont dit Lebrun`` gives family ``Dupont dit Lebrun``, where the default, as 1.4.0 through 3.1.0, gives middle ``Dupont dit``, family ``Lebrun``; a West African alias joins the given name the same way (``Mamadou dit Madou``), and the default is unchanged, ``Dit`` and ``Dite`` being names too. :issue:`1159` - **Add Brazilian Portuguese familiar forms, found in the names Brazil's election candidates put on the ballot.** With ``familiar-form`` accepted, ``Tião Alves`` / ``Sebastião Alves`` and ``Cida Silva`` / ``Aparecida Silva`` are consistent, where 3.1.0 read a conflict. They are filed under ``pt-BR``, so a strict choice of another language leaves them out, and one name spelled two ways (``Elizangela`` / ``Elisangela``) is not among them. :issue:`1495` - **Add the Czech and Slovak post-nominals DiS., DrSc. and ArtD. as credentials.** ``parse("Jan Novák, DiS.")`` gives suffix ``DiS.``, where 1.4.0 through 3.1.0 gave title ``DiS.``; DiS., which is also a surname, reads as the credential after a full name and a comma, and written as ``DiS.`` or ``Dis`` it stays a name word at the end of a name of mixed case without one (``Jan Novák DiS.``), while a surname written ``DIS`` there reads as the credential (``Jan DIS``). :issue:`969` diff --git a/nameparser/AGENTS.md b/nameparser/AGENTS.md index 55548245f..ef7ff06bf 100644 --- a/nameparser/AGENTS.md +++ b/nameparser/AGENTS.md @@ -76,7 +76,7 @@ Capitals between two name words have the same second reading: some writers put t ### A word written in capitals -A rule that reads a word's capitals meets spellings the plain `isupper()` misjudges both ways, and a gate measured before #659's rule (rules/O9) found each in real data on 2026-11-12: a title or a placeholder written in capitals (`DR.` opening 192 given boxes of the 2025-10 ORCID dump, `N/A` in every one of `psc-individuals`' 128 such names), which a full stop or a slash rules out; a surname written in capitals behind a lowercase prefix (`McDONALD`, `d'ESTAING`), which `isupper()` refuses; and a name whose only lowercase letters stand in a title or a particle (`Dr. ANITA ROY`, `MARIA de SOUZA LIMA`), which a whole-name case test calls mixed. Put each in the grid, with a lowercase and a Title-case twin of every example (the twins must not move), and the NFD spelling. +A rule that reads a word's capitals meets spellings the plain `isupper()` misjudges both ways, and a gate measured before #659's rule (rules/O9) found each in real data on 2026-11-12: a title or a placeholder written in capitals (`DR.` opening 192 given boxes of the 2025-10 ORCID dump, `N/A` in every one of `psc-individuals`' 128 such names), which a full stop or a slash rules out; a surname written in capitals behind a lowercase prefix (`McDONALD`, `d'ESTAING`), which `isupper()` refuses; and a name whose only lowercase letters stand in a title or a particle (`Dr. ANITA ROY`, `MARIA de SOUZA LIMA`), which a whole-name case test calls mixed. Put each in the grid, with a lowercase and a Title-case twin of every example (the twins must not move), and the NFD spelling. And a filter written as "neither lower nor title case" is not a wider `isupper()`: `istitle()` passes over a caseless letter, so a word of capitals split by one (`XיZ`) is title-shaped to it, and #1516's first build, widening the comma's `isupper()` filter to `not islower() and not istitle()` for mixed-case credentials, dropped the one such word ctgov-contacts holds from the suffix; keep `isupper()` as its own arm when widening a case filter, and put a caps word with a caseless letter in the grid. ### Adjacent pairs of words diff --git a/nameparser/_pipeline/_classify.py b/nameparser/_pipeline/_classify.py index 92a06cc42..586efb9df 100644 --- a/nameparser/_pipeline/_classify.py +++ b/nameparser/_pipeline/_classify.py @@ -482,7 +482,7 @@ def _tags_for(token: WorkToken, n: str, state: ParseState, or "/" in token.text) or not unicodedata.is_normalized("NFC", token.text)) and caps_shape_candidate(token.text, lex, state.policy, - one_case)): + one_case, mixed_case=False)): # #516's all-caps half: an unlisted word written in capitals # inside a mixed-case name. EVERYWHERE tags it in every # slot; the default admits it only in the part after a diff --git a/nameparser/_pipeline/_comma.py b/nameparser/_pipeline/_comma.py index 680aff927..88818094a 100644 --- a/nameparser/_pipeline/_comma.py +++ b/nameparser/_pipeline/_comma.py @@ -49,7 +49,7 @@ from nameparser._pipeline._vocab import ( ROMAN, caps_shape_candidate, claimed_as_non_name, composed_len, delimiter_cores, ends_in_a_generation, glued_cores, - glued_stem, glues, is_caps_word, + glued_stem, glues, is_caps_word, is_mixed_caps_word, is_letter_run, is_paired_initials, is_single_letter_numeral, is_wholly_suffix, _joined_chunks, _listed_whole, name_reading, name_word_count, reads_as_generation, suffix_reading, @@ -415,7 +415,7 @@ def _company(state: ParseState, seg0: Sequence[int], p: Sequence[int], return True if (state.one_case or not caps_shape_candidate(text, state.lexicon, state.policy, - one_case=False)): + one_case=False, mixed_case=True)): return False if not contrast: contrast.append(_name_contrast(state, seg0)) @@ -750,7 +750,13 @@ def decide(state: ParseState, splits: bool | None = True) -> ParseState: or len(p) == 1 and (AMBIGUOUS_ACRONYM_TAG in (tags := tokens[p[0]].tags) or ("vocab:suffix" not in tags - and (texts[p[0]].isupper() + # capitals, or the mixed case `is_mixed_caps_word` + # reads; `isupper()` kept as its own arm, a caps + # word holding a caseless letter ('XיZ') being + # title-shaped to `istitle()` + and ((texts[p[0]].isupper() + or not texts[p[0]].islower() + and not texts[p[0]].istitle()) and (texts[p[0]].isalpha() # the joined spelling ('PU-PH'), the # predicate's other half (rules/S9) @@ -758,7 +764,8 @@ def decide(state: ParseState, splits: bool | None = True) -> ParseState: or "/" in texts[p[0]]) or not unicodedata.is_normalized( "NFC", texts[p[0]]) - and is_caps_word(texts[p[0]]))))] + and (is_caps_word(texts[p[0]]) + or is_mixed_caps_word(texts[p[0]])))))] # rules/C16: "behind one word, initials run together are the given # name whatever they spell" -- the runs that spell a listed # credential ('J.P.', 'M.A.'), joined to the class so C4's count is @@ -794,6 +801,10 @@ def decide(state: ParseState, splits: bool | None = True) -> ParseState: initials_at = p[0] break contrast_box: list[bool] = [] + # the unlisted capitals words the run's company admitted, given the + # caps shape's marks below as the count's are ('Smith, M.B. ChB' + # keeps 'ChB' forced, rules/R4) + company_caps: list[int] = [] if initials_at is not None: # titles in front of the run are the given part's (C16); # behind it a credential is company: a title/suffix dual only in @@ -807,6 +818,13 @@ def decide(state: ParseState, splits: bool | None = True) -> ParseState: if rest and all(_company(state, seg0, p, pt, texts, contrast_box) for p, pt in rest): initials_at = None + # `_company` admits a single unlisted word by the caps shape + # alone (its last test) + company_caps = [ + p[0] for p, pt in rest + if len(p) == 1 and "split" not in pt + and "vocab:suffix" not in tokens[p[0]].tags + and AMBIGUOUS_ACRONYM_TAG not in tokens[p[0]].tags] elif initials_at not in maybe: run_alone = not maybe maybe.append(initials_at) @@ -846,7 +864,7 @@ def decide(state: ParseState, splits: bool | None = True) -> ParseState: if listing and not generation: return state names = 0 - caps: set[int] = set() + caps: set[int] = set(company_caps) licensed: set[int] = set() run = False # a pair a later comma part's credential spoke for (rules/C5), whose @@ -885,7 +903,8 @@ def decide(state: ParseState, splits: bool | None = True) -> ParseState: continue if (AMBIGUOUS_ACRONYM_TAG not in tokens[i].tags and pol.unlisted_caps_suffixes is not CapsSuffixes.OFF - and caps_shape_candidate(text, lex, pol, one_case=False)): + and caps_shape_candidate(text, lex, pol, one_case=False, + mixed_case=True)): if contrast is None: contrast = _name_contrast(state, seg0) # the box the helpers below read, empty until now @@ -1041,6 +1060,9 @@ def decide(state: ParseState, splits: bool | None = True) -> ParseState: and (text.isupper() and (text.isalpha() or "-" in text or "/" in text) + or not text.islower() + and not text.istitle() + and is_mixed_caps_word(text) or not unicodedata.is_normalized( "NFC", text) and is_caps_word(text))): caps.add(i) diff --git a/nameparser/_pipeline/_vocab.py b/nameparser/_pipeline/_vocab.py index 54146a8c8..7e0c865d6 100644 --- a/nameparser/_pipeline/_vocab.py +++ b/nameparser/_pipeline/_vocab.py @@ -2006,7 +2006,8 @@ class at all). # asks C-level `isalpha()`/`isupper()` and the suffix tag first, so a # comma name with no unlisted all-caps word never reaches it. def caps_shape_candidate(text: str, lexicon: Lexicon, policy: Policy, - one_case: bool | None) -> bool: + one_case: bool | None, *, + mixed_case: bool) -> bool: """Whether TEXT is an UNLISTED all-caps credential candidate: two or more alphabetic characters, or letter chunks joined by '-' or '/' (`_joined_capitals`, #752), no period (a period fails @@ -2045,6 +2046,12 @@ def caps_shape_candidate(text: str, lexicon: Lexicon, policy: Policy, `n not in suffix_acronyms_ambiguous`, `_comma.decide`'s AMBIGUOUS_ACRONYM_TAG test), so a listed member never pays for the call. + + `mixed_case` admits a mixed-case word as well (`_mixed_capitals`: + 'DClinPsy', 'AuD'), which only the part after a comma asks for + (rules/C6, decisions/C6 (#1516)); the trailing position under + `CapsSuffixes.EVERYWHERE` passes False, a surname typed without its + apostrophe ('ONeill', 'DSouza') ending a name there. """ if (policy.unlisted_caps_suffixes is CapsSuffixes.OFF or one_case is not False): @@ -2052,11 +2059,26 @@ def caps_shape_candidate(text: str, lexicon: Lexicon, policy: Policy, if not text.isascii(): text = unicodedata.normalize("NFC", text) if not (len(text) >= 2 and text.isalpha() and text.isupper() - or _joined_capitals(text)): + or _joined_capitals(text) + or mixed_case and _mixed_capitals(text)): return False return not in_any_wordlist(_normalize(text), lexicon) +def _mixed_capitals(text: str) -> bool: + """Whether TEXT is an alphabetic mixed-case word that opens with two + capitals ('DClinPsy', 'MRes') or ends in one ('AuD', 'PharmD'): + written neither in capitals nor the way a name is, so the caps + shape reads it after a comma. A capital only inside the word + ('LeBron', 'McKenzie') is a name's writing and stays out, and so + does a word holding anything but letters ('Pharm-D', the joined + arm having caught given names such as 'Jay-R'). TEXT is + NFC-composed.""" + return (len(text) >= 2 and text.isalpha() and not text.isupper() + and (text[0].isupper() and text[1].isupper() + or text[-1].isupper())) + + #: A word of letter chunks joined by '-' or '/' ('PU-PH', 'MD/MBA'). _JOINED_LETTERS = re.compile( r'(?:' + _LETTER + r')+(?:[-/](?:' + _LETTER + r')+)+') @@ -2089,6 +2111,15 @@ def is_caps_word(text: str) -> bool: return composed.isalpha() and composed.isupper() +def is_mixed_caps_word(text: str) -> bool: + """Whether TEXT, once NFC-composed, is the mixed-case word the caps + shape reads after a comma (`_mixed_capitals`: 'MRes', 'AuD'), for + the comma's C-level filters, which ask it of a word neither in one + case nor written the way a name is, or not NFC (#652).""" + return _mixed_capitals(text if text.isascii() + else unicodedata.normalize("NFC", text)) + + def composed(text: str) -> str: """TEXT NFC-composed where it is not ASCII, so a letter typed as its base and a combining mark is one letter, as the vocabulary lookup diff --git a/nameparser/_policy.py b/nameparser/_policy.py index 0cf951553..d01cebb76 100644 --- a/nameparser/_policy.py +++ b/nameparser/_policy.py @@ -46,16 +46,19 @@ class CapsSuffixes(StrEnum): #: 2.3 read it. OFF = "off" #: Only after a comma, behind two or more name words ("John Smith, - #: XYZ" gives suffix ``XYZ``). The default: the all-caps SURNAME - #: convention ("Jean DUPONT", "DUPONT, Jean") never writes the - #: capitals there. + #: XYZ" gives suffix ``XYZ``), where a word in mixed case that opens + #: with two capitals or ends in one reads so too ("Jane Smith, MRes"). + #: The default: the all-caps SURNAME convention ("Jean DUPONT", + #: "DUPONT, Jean") never writes the capitals there. AFTER_COMMA = "after-comma" #: After a comma and ending a name with no comma ("John Smith XYZ" #: gives suffix ``XYZ``), where the all-caps surname convention #: does write them -- "Jean Pierre DUPONT" then gives family #: ``Pierre``, suffix ``DUPONT``. Cannot be set with #: ``Policy.capitals_as_family``, which reads that word as the - #: family. + #: family. Its other positions read a word wholly in capitals only: + #: a surname typed without its apostrophe ("Alex Lee ONeill") ends + #: a name there. EVERYWHERE = "everywhere" @@ -925,7 +928,11 @@ class Policy: #: ``AFTER_COMMA``, the default, reads it only in the part after a #: comma with two or more name words before it: "John Smith, XYZ" #: gives suffix ``XYZ``, while "Smith, XYZ" keeps given ``XYZ`` (one - #: name word) and "García Márquez, MJ" keeps given ``MJ`` -- a lone + #: name word). There a word in mixed case that opens with two + #: capitals or ends in one is read as an all-caps word is ("Jane + #: Smith, MRes", "Jane Smith, AuD"), a capital only inside a word + #: being a name's writing ("Jane Smith, LeBron" keeps given + #: ``LeBron``) and "García Márquez, MJ" keeps given ``MJ`` -- a lone #: two-letter word is how a person's initials are written, and two #: words before the comma may be one surname, the case #563 decides #: for "M.J." too. Credentials behind the two letters make them one: @@ -942,7 +949,8 @@ class Policy: #: convention's own position: "John Smith XYZ" gives suffix ``XYZ``, #: and "Jean Pierre DUPONT" gives family ``Pierre``, suffix #: ``DUPONT`` -- the cost, a swallowed family name being the worse - #: failure. The two-word "Jean DUPONT" and "Minjun KIM" keep their + #: failure. The mixed-case word is not read there: "Alex Lee ONeill" + #: keeps family ``ONeill``. The two-word "Jean DUPONT" and "Minjun KIM" keep their #: family even then (one word before the credential is never #: enough), but gain the fork's report. ``OFF`` reads no such word #: as a credential anywhere and reports nothing, as 2.3 did. A digit diff --git a/nameparser/_render.py b/nameparser/_render.py index d18351deb..acfc9fab2 100644 --- a/nameparser/_render.py +++ b/nameparser/_render.py @@ -703,6 +703,13 @@ def _cap_word(word: str, role: Role, tags: frozenset[str], if role is Role.SUFFIX and ( undotted in lex._sets.suffix_acronyms or SHAPE_ACRONYM_TAG in tags): + # rules/R4: "A word read as a credential after a comma by its + # mixed case (C6) is kept as written, forced or not" -- the + # caps shape's mark on a word in more than one case ('MRes', + # 'AuD'); decisions/C6 (#1516) + if (SHAPE_ACRONYM_TAG in tags and "." not in word + and not word.isupper() and not word.islower()): + return word return word.upper() # rules/R4: "A roman numeral the parse put in the suffix role is # written in capitals" whether or not the vocabulary lists it: 'vi' diff --git a/tests/v2/cases.py b/tests/v2/cases.py index 2e1dbc8ef..ed664a408 100644 --- a/tests/v2/cases.py +++ b/tests/v2/cases.py @@ -7120,6 +7120,105 @@ def _check_cjk_shape_purity(self) -> None: "capitals after a comma behind a full name, so the " "default reads the comma position (rules/C6, S9). " "2.3.0 read given 'XYZ', family 'John Smith'"), + # #1516: a word in mixed case written as a credential is -- opening + # with two capitals or ending in one -- is the caps shape after a + # comma (rules/C6); the words the narrower all-caps test refused + # that stay names keep a row each below. + Case("a_mixed_case_word_opening_with_two_capitals_is_a_credential", + "Jane Smith, MRes", + {"given": "Jane", "family": "Smith", "suffix": "MRes"}, + classification="fix(#1516)", + ambiguities=("suffix-or-name",), + notes="rules/C6's mixed-case bullet; 3.1 read given 'MRes', " + "family 'Jane Smith'"), + Case("a_mixed_case_word_ending_in_a_capital_is_a_credential", + "Jane Smith, AuD", + {"given": "Jane", "family": "Smith", "suffix": "AuD"}, + classification="fix(#1516)", + ambiguities=("suffix-or-name",), + notes="rules/C6; 3.1 read given 'AuD', family 'Jane Smith'"), + Case("a_decomposed_mixed_case_credential_is_read_composed", + "Jane Smith, MRE\u0301s", + {"given": "Jane", "family": "Smith", "suffix": "MRE\u0301s"}, + classification="fix(#1516)", + ambiguities=("suffix-or-name",), + notes="the accent typed as a combining mark (#652): the comma's " + "C-level filter asks the composed word"), + Case("a_mixed_case_credential_beside_a_listed_one", + "Jane Smith, MRes PhD", + {"given": "Jane", "family": "Smith", "suffix": "MRes PhD"}, + classification="fix(#1516)", + ambiguities=("suffix-or-name",)), + Case("a_caps_word_holding_a_caseless_letter_stays_a_credential", + "John Smith, X\u05d9Z", + {"given": "John", "family": "Smith", "suffix": "X\u05d9Z"}, + classification="fix(#564)", + ambiguities=("suffix-or-name",), + notes="#1516's guard: `istitle()` holds a word of capitals " + "split by a caseless letter title-shaped, so the comma's " + "widened filter keeps `isupper()` as an arm of its own; " + "its first build read given here"), + Case("a_capital_inside_a_word_is_a_names_writing_after_a_comma", + "Jane Smith, LeBron", + {"given": "LeBron", "family": "Jane Smith"}, + notes="a capital only inside the word is no credential's " + "writing (rules/C6)"), + Case("a_mc_name_after_a_comma_stays_the_given_name", + "Jane Smith, McKenzie", + {"given": "McKenzie", "family": "Jane Smith"}), + Case("a_word_neither_opening_with_two_capitals_nor_ending_in_one", + "Jane Smith, PhDc", + {"given": "PhDc", "family": "Jane Smith"}, + notes="the mixed-case shape reads the word's ends only " + "(rules/C6); a caller lists such a credential"), + Case("a_mixed_case_word_with_a_hyphen_is_no_credential_by_shape", + "Jane Smith, Pharm-D", + {"given": "Pharm-D", "family": "Jane Smith"}, + notes="'Jay-R' is a given name written so (rules/C6)"), + Case("two_capitals_after_a_comma_stay_the_given_name", + "Kim Jong, UN", + {"given": "UN", "family": "Kim Jong"}, + notes="rules/C6's two-letter rule: a lone pair of capitals is " + "how initials are written, and the mixed-case arm adds " + "nothing to it"), + Case("a_mixed_case_word_in_a_capitals_name_has_no_contrast", + "JANE SMITH, MRes", + {"given": "MRes", "family": "JANE SMITH"}, + notes="the contrast is a word before the comma written the " + "way a name is (rules/C6)"), + Case("a_mixed_case_word_behind_one_name_word_is_the_given_name", + "Smith, MRes", + {"given": "MRes", "family": "Smith"}, + notes="rules/C4's count, as for 'Smith, XYZ'"), + Case("a_lowercase_name_keeps_its_given_name_after_a_comma", + "jane smith, mres", + {"given": "mres", "family": "jane smith"}), + Case("a_mixed_case_credential_is_company_for_initials_spelling_one", + "Smith, M.B. ChB", + {"family": "Smith", "suffix": "M.B. ChB"}, + classification="fix(#1516)", + ambiguities=("suffix-or-name",), + notes="rules/C16's Except, as 'Smith, J.P. AUD' reads; 3.1 read " + "given 'M.', middle 'B. ChB'"), + Case("an_apostrophe_less_surname_ending_a_name_stays_the_family", + "Alex Lee ONeill", + {"given": "Alex", "middle": "Lee", "family": "ONeill"}, + policy=Policy(unlisted_caps_suffixes=CapsSuffixes.EVERYWHERE), + notes="the mixed-case shape is read after a comma only " + "(rules/S9), so EVERYWHERE's trailing position reads capitals " + "alone (#1516)"), + Case("a_d_surname_without_its_apostrophe_stays_the_family", + "Alex Lee DSouza", + {"given": "Alex", "middle": "Lee", "family": "DSouza"}, + policy=Policy(unlisted_caps_suffixes=CapsSuffixes.EVERYWHERE)), + Case("an_o_surname_without_its_apostrophe_stays_the_family", + "Alex Lee OReilly", + {"given": "Alex", "middle": "Lee", "family": "OReilly"}, + policy=Policy(unlisted_caps_suffixes=CapsSuffixes.EVERYWHERE)), + Case("a_mc_surname_in_capitals_ending_a_name_stays_the_family", + "Alex Lee McCAFFREY", + {"given": "Alex", "middle": "Lee", "family": "McCAFFREY"}, + policy=Policy(unlisted_caps_suffixes=CapsSuffixes.EVERYWHERE)), Case("the_comma_caps_reading_can_be_switched_off", "John Smith, XYZ", {"given": "XYZ", "family": "John Smith"}, diff --git a/tests/v2/pipeline/test_classify.py b/tests/v2/pipeline/test_classify.py index e1106b0c3..d4e7f5c25 100644 --- a/tests/v2/pipeline/test_classify.py +++ b/tests/v2/pipeline/test_classify.py @@ -693,7 +693,8 @@ def test_ambiguous_class_candidate_agrees_with_the_tag( policy=policy)[word] candidate = (ambiguous_class_candidate(word, lex, policy) or (policy.unlisted_caps_suffixes - and caps_shape_candidate(word, lex, policy, one_case))) + and caps_shape_candidate(word, lex, policy, one_case, + mixed_case=False))) # rules/S3's paired initials, the one shape the two answers part # on by design: the candidate (segment's, before the comma has # been read) admits them, and classify holds the class tag back, diff --git a/tests/v2/pipeline/test_vocab.py b/tests/v2/pipeline/test_vocab.py index f6086cc7d..e4244119e 100644 --- a/tests/v2/pipeline/test_vocab.py +++ b/tests/v2/pipeline/test_vocab.py @@ -576,9 +576,42 @@ def test_caps_shape_candidate_reads_joined_capitals( # capitals in letter chunks joined by a hyphen or a slash lex = Lexicon.default() pol = Policy() - assert caps_shape_candidate(text, lex, pol, one_case=False) is expected + assert caps_shape_candidate(text, lex, pol, one_case=False, + mixed_case=True) is expected # gated as the unjoined word is: a name in one case says nothing - assert caps_shape_candidate(text, lex, pol, one_case=True) is False + assert caps_shape_candidate(text, lex, pol, one_case=True, + mixed_case=True) is False + + +@pytest.mark.parametrize("text, expected", [ + ("MRes", True), # opens with two capitals + ("DClinPsy", True), + ("AuD", True), # ends in a capital + ("DNSc", True), + ("MRE\u0301s", True), # decomposed, read composed (#652) + ("LeBron", False), # a capital only inside: a name's writing + ("McKenzie", False), + ("DeShawn", False), + ("PhDc", False), # neither + ("Pharm-D", False), # a hyphen in mixed case: 'Jay-R' is a name + ("Jay-R", False), + ("Smith", False), # written the way a name is + ("smith", False), + ("Ms", False), # listed + ("PhD", False), +]) +def test_caps_shape_candidate_reads_mixed_case_only_where_asked( + text: str, expected: bool) -> None: + # #1516: the mixed-case arm, which only the part after a comma asks + # for; the trailing position under EVERYWHERE never does + lex = Lexicon.default() + pol = Policy() + assert caps_shape_candidate(text, lex, pol, one_case=False, + mixed_case=True) is expected + assert caps_shape_candidate(text, lex, pol, one_case=False, + mixed_case=False) is False + assert caps_shape_candidate(text, lex, pol, one_case=True, + mixed_case=True) is False def test_caps_shape_candidate_refuses_a_listed_joined_word() -> None: @@ -586,9 +619,9 @@ def test_caps_shape_candidate_refuses_a_listed_joined_word() -> None: # word lex = Lexicon.default() | Lexicon(surnames={"dupont-moretti"}) assert not caps_shape_candidate("DUPONT-MORETTI", lex, Policy(), - one_case=False) + one_case=False, mixed_case=False) assert caps_shape_candidate("DUPONT-MORETTI", Lexicon.default(), - Policy(), one_case=False) + Policy(), one_case=False, mixed_case=False) def test_ambiguous_class_candidate_admits_a_by_shape_member() -> None: @@ -686,7 +719,7 @@ def test_the_caps_exclusion_covers_every_vocabulary_field() -> None: # name. on = Policy(unlisted_caps_suffixes=CapsSuffixes.EVERYWHERE) base = Lexicon.default() - assert caps_shape_candidate("ZZQX", base, on, False) + assert caps_shape_candidate("ZZQX", base, on, False, mixed_case=False) assert set(_INTO_FIELD) == set(_VOCAB_FIELDS) - {"conjunctions_ambiguous"} for field, into in _INTO_FIELD.items(): lex = into(base, "zzqx") @@ -699,9 +732,11 @@ def test_the_caps_exclusion_covers_every_vocabulary_field() -> None: # shape; and #959's fourth, the given names only O6 reads if field in ("titles_ambiguous", "title_phrases", "given_name_abbreviations", "given_names"): - assert caps_shape_candidate("ZZQX", lex, on, False), field + assert caps_shape_candidate("ZZQX", lex, on, False, + mixed_case=False), field else: - assert not caps_shape_candidate("ZZQX", lex, on, False), field + assert not caps_shape_candidate("ZZQX", lex, on, False, + mixed_case=False), field def test_is_title_shaped_is_h2_s_shape_alone() -> None: diff --git a/tests/v2/test_cases.py b/tests/v2/test_cases.py index f9ee1f6c4..7cb5b3dac 100644 --- a/tests/v2/test_cases.py +++ b/tests/v2/test_cases.py @@ -525,10 +525,12 @@ def test_the_field_sweep_sees_the_claims_it_checks() -> None: # 'Jane Doe, BM, ...' rows); 2257 -> 2272 the same day, #969's DiS # rows' suffix-or-name under three orders; 2272 -> 2275 the same day, # its review's 'PETR JAN DIS' under three orders; 2275 -> 2278 the - # same day, its second review's 'Jan DIS' under three orders. - assert claims == 2278, ( - f"the field sweep checks {claims} claims, recorded as 2278 on " - f"2026-11-20") + # same day, its second review's 'Jan DIS' under three orders; 2278 + # -> 2296 on 2026-11-21, #1516's six caps-shape rows reporting + # suffix-or-name under three orders. + assert claims == 2296, ( + f"the field sweep checks {claims} claims, recorded as 2296 on " + f"2026-11-21") #: The kinds that report a fork between two readings of a word, so carry @@ -611,6 +613,11 @@ def test_the_field_sweep_sees_the_claims_it_checks() -> None: ("JOHN SMITH MD (B) VI JONES", None), ("JOHN SMITH MD (B) VI JONES", 2), ("John Smith MA VI Jones", None), ("John Smith MA VI Jones", 2), + # a name word in a mixed-case credential's place leaves the initials + # in front of it no company, so they are the given name (rules/C16, + # #1516) + ("Smith, M.B. ChB", None), ("Smith, M.B. ChB", 1), + ("Smith, M.B. ChB", 2), } #: Reports whose deferred field assign could not name: the particle the @@ -1021,8 +1028,10 @@ def test_the_alternative_sweep_sees_the_fields_it_checks() -> None: # under three orders; 617 -> 620 and 509 -> 512 the same day, #1361's # and #1284's rows under three orders; 620 -> 629 the same day, #969's # three DiS rows after a comma under three orders; 629 -> 632 the same - # day, its review's 'PETR JAN DIS' under three orders - assert (checked, skipped) == (632, 512), (checked, skipped) + # day, its review's 'PETR JAN DIS' under three orders; 632 -> 647 on + # 2026-11-21, #1516's five caps-shape rows under three orders, + # 'Smith, M.B. ChB' being a stand-in reread + assert (checked, skipped) == (647, 512), (checked, skipped) def test_every_case_name_is_unique() -> None: diff --git a/tests/v2/test_config_diff.py b/tests/v2/test_config_diff.py index 717cf5029..3ea977d97 100644 --- a/tests/v2/test_config_diff.py +++ b/tests/v2/test_config_diff.py @@ -124,7 +124,9 @@ def test_a_name_whose_tokens_differ_is_tallied_as_retokenized() -> None: def test_the_tally_counts_moves_by_input_fields_and_word() -> None: - texts = ["Ana Souza PhD", "Bo Lima, PhD", "Ana Souza", "Cy Dias Ph.D."] + # 'Phd' after the comma: unlisted, 'PhD' is read by the caps shape's + # mixed-case arm and stays a suffix (#1516) + texts = ["Ana Souza PhD", "Bo Lima, Phd", "Ana Souza", "Cy Dias Ph.D."] names = [(t, None, frozenset({"one"} if i % 2 else {"one", "two"})) for i, t in enumerate(texts)] specs = ("default", _NO_PHD) diff --git a/tests/v2/test_locales.py b/tests/v2/test_locales.py index 0ca3120e8..d856d6a5b 100644 --- a/tests/v2/test_locales.py +++ b/tests/v2/test_locales.py @@ -3362,8 +3362,11 @@ def test_no_exclusion_is_pack_shaped_any_more() -> None: ("cs", None, "MgA Jana Malá", ("", "MgA", "Jana", "Malá", "", "", ()), ("MgA", "Jana", "", "Malá", "", "", ())), + # the default reads it after a two-word head by the caps shape's + # mixed-case arm, as the credential it is (#1516); the pack, as the + # title it lists ("cs", None, "Jana Malá, MgA", - ("", "MgA", "", "Jana Malá", "", "", ()), + ("", "Jana", "", "Malá", "MgA", "", ("SUFFIX_OR_NAME",)), ("MgA", "Jana", "", "Malá", "", "", ())), ("cs", None, "Malá, MgA", ("", "MgA", "", "Malá", "", "", ()), diff --git a/tests/v2/test_parser.py b/tests/v2/test_parser.py index e91236b59..e1623d876 100644 --- a/tests/v2/test_parser.py +++ b/tests/v2/test_parser.py @@ -3522,11 +3522,14 @@ def test_a_caller_removes_a_mul_word_as_any_other() -> None: assert kept.parse("Ana Souza, PhD").suffix == "PhD" assert kept.parse("Dr Ana Souza").title == "Dr" lexicon = Lexicon.default().remove("phd", kind="credential") - assert Parser(lexicon=lexicon).parse("Ana Souza, PhD").given == "PhD" + # written 'Phd', as a name is: 'PhD' unlisted is still read by the + # caps shape's mixed-case arm after a comma (#1516) + assert Parser(lexicon=lexicon).parse("Ana Souza, Phd").given == "Phd" + assert Parser(lexicon=lexicon).parse("Ana Souza, PhD").suffix == "PhD" for strict in (False, True): got = parser_for(_choosing("pt"), base=Parser(lexicon=lexicon), strict=strict) - assert got.parse("Ana Souza, PhD").given == "PhD" + assert got.parse("Ana Souza, Phd").given == "Phd" stripped = kept.lexicon.remove("dr", kind="academic") assert Parser(lexicon=stripped).parse("Dr Ana Souza").given == "Dr" diff --git a/tests/v2/test_render.py b/tests/v2/test_render.py index 887b91a97..6b36bc1e0 100644 --- a/tests/v2/test_render.py +++ b/tests/v2/test_render.py @@ -2305,6 +2305,27 @@ def test_a_caps_credential_after_a_comma_keeps_its_capitals_in_every_setting( assert str(name.capitalized(force=True)) == rendered, (setting, text) +def test_a_mixed_case_credential_is_kept_as_written_when_forced() -> None: + # rules/R4 (#1516): a word the caps shape read after a comma in mixed + # case ('MRes', 'AuD') keeps its writing, forced or not: no mask + # lists it, and the acronym clause's capitals would write 'MRES'. + # Its all-caps twin still repairs to capitals, and the company of a + # run of initials (rules/C16) carries the shape's marks too. + for text, rendered in ( + ("Jane Smith, MRes", "Jane Smith, MRes"), + ("Jane Smith, AuD", "Jane Smith, AuD"), + ("Jane Smith, MRes PhD", "Jane Smith, MRes PhD"), + ("Jane Smith, MRE\u0301s", "Jane Smith, MRE\u0301s"), + ("Smith, M.B. ChB", "Smith, M.B. ChB"), + ("Smith, J.P. AUD", "Smith, J.P. AUD"), + ("Ashley Knight, M.S. BME", "Ashley Knight, M.S. BME")): + assert str(parse(text).capitalized(force=True)) == rendered, text + assert str(parse(text).capitalized()) == rendered, text + # a word written as a name is, read as the given name, still repairs + assert str(parse("Jane Smith, PhDc").capitalized(force=True)) == ( + "Phdc Jane Smith") + + def test_a_marked_particle_lowercases_only_where_the_particle_arm_would( ) -> None: """rules/R4, #700: a particle written with its mark ("d'", diff --git a/tools/differential/corpus_rules.jsonl b/tools/differential/corpus_rules.jsonl index ac2e800c9..710e879a3 100644 --- a/tools/differential/corpus_rules.jsonl +++ b/tools/differential/corpus_rules.jsonl @@ -109,6 +109,8 @@ "Aidai Mederbek kyzy, PhD" "Ait Haddou Karim" "Alex Green, FRCS (SN)" +"Alex Lee MRes" +"Alex Lee ONeill" "Alexandre Dumas fils" "Ali Ahmad Oğlu" "Ali Ahmad Vali Hasan oglu" @@ -555,6 +557,7 @@ "JANE DOE MA R.T." "JANE DOE, M.H., PHD" "JANE DOE, MH, PHD" +"JANE SMITH, MRes" "JEAN ST-PIERRE" "JEAN y Perez" "JEFFREY (JD) BRICKEN" @@ -734,8 +737,13 @@ "Jane Smith née Jones, PhD" "Jane Smith née PhD" "Jane Smith née V" +"Jane Smith, AuD" "Jane Smith, Dr / PhD" +"Jane Smith, LeBron" +"Jane Smith, MRes" "Jane Smith, PhD/NP-C" +"Jane Smith, PhDc" +"Jane Smith, Pharm-D" "Jane Smith, née Jones" "Jane Smith-NP-C" "Jane and née Jones" @@ -1764,14 +1772,17 @@ "Smith, M.B. ChB" "Smith, M.D." "Smith, M.D. / PhD" +"Smith, M.D. M. Sc." "Smith, M.D. MS" "Smith, M.D. Ph.D." +"Smith, M.D. PhDc" "Smith, MA" "Smith, MD" "Smith, MD ; PhD" "Smith, MD J" "Smith, MD PhD" "Smith, MD; PhD" +"Smith, MRes" "Smith, Ma" "Smith, Ma. John" "Smith, Major. John" diff --git a/tools/differential/snapshot.jsonl b/tools/differential/snapshot.jsonl index 099554684..18696aa1b 100644 --- a/tools/differential/snapshot.jsonl +++ b/tools/differential/snapshot.jsonl @@ -221,6 +221,8 @@ {"name": "Aldephonse Alexandre Félix du Jardin", "given": "Aldephonse", "middle": "Alexandre Félix", "family": "du Jardin", "initials": "A. A. F. J."} {"name": "Alex Ben Johnson", "given": "Alex", "middle": "Ben", "family": "Johnson", "initials": "A. B. J."} {"name": "Alex Green, FRCS (SN)", "given": "Alex", "family": "Green", "suffix": "FRCS", "nickname": "SN", "initials": "A. G.", "capitalized_force": "Alex \"Sn\" Green, FRCS"} +{"name": "Alex Lee MRes", "given": "Alex", "middle": "Lee", "family": "MRes", "initials": "A. L. M.", "capitalized_force": "Alex Lee Mres"} +{"name": "Alex Lee ONeill", "given": "Alex", "middle": "Lee", "family": "ONeill", "initials": "A. L. O.", "capitalized_force": "Alex Lee Oneill"} {"name": "Alex van Johnson", "given": "Alex", "family": "van Johnson", "initials": "A. J."} {"name": "Alexander Parra Uribe", "given": "Alexander", "middle": "Parra", "family": "Uribe", "initials": "A. P. U."} {"name": "Alexandre Dumas fils", "given": "Alexandre", "family": "Dumas", "suffix": "fils", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: name as family (declared)"], "initials": "A. D.", "generation": "fils"} @@ -414,7 +416,7 @@ {"name": "Artur MAS I GAVARRO", "given": "Artur", "middle": "MAS I", "family": "GAVARRO", "initials": "A. M. I. G.", "capitalized_force": "Artur Mas I Gavarro"} {"name": "Arturo Acevedo Vallarino", "given": "Arturo", "middle": "Acevedo", "family": "Vallarino", "initials": "A. A. V."} {"name": "Asas Manterola, Benita", "given": "Benita", "family": "Asas Manterola", "initials": "B. A. M."} -{"name": "Ashley Knight, M.S. BME", "given": "Ashley", "family": "Knight", "suffix": "M.S. BME", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: name as given (position)"], "initials": "A. K.", "capitalized_force": "Ashley Knight, M.S. Bme"} +{"name": "Ashley Knight, M.S. BME", "given": "Ashley", "family": "Knight", "suffix": "M.S. BME", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: name as given (position)"], "initials": "A. K."} {"name": "Asmar", "given": "Asmar", "ambiguities": ["GIVEN_OR_FAMILY"], "alternatives": ["GIVEN_OR_FAMILY: name as family (position)"], "initials": "A."} {"name": "Asmar", "order": "FAMILY_FIRST", "given": "Asmar", "ambiguities": ["GIVEN_OR_FAMILY"], "alternatives": ["GIVEN_OR_FAMILY: name as family (position)"], "initials": "A."} {"name": "Assad, Hafis al-", "given": "Hafis", "family": "al- Assad", "initials": "H. A."} @@ -1695,6 +1697,7 @@ {"name": "JANE DOE NEE YO-YO MA", "given": "JANE", "family": "DOE", "suffix": "MA", "maiden": "YO-YO", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: name as maiden (declared)"], "initials": "J. D.", "capitalized": "Jane Doe (Yo-Yo) MA"} {"name": "JANE DOE, M.H., PHD", "given": "M.", "middle": "H.", "family": "JANE DOE", "suffix": "PHD", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: credential as suffix (shape)"], "initials": "M. H. J. D.", "capitalized": "M.H. Jane Doe PhD"} {"name": "JANE DOE, MH, PHD", "given": "MH", "family": "JANE DOE", "suffix": "PHD", "initials": "M. J. D.", "capitalized": "Mh Jane Doe PhD"} +{"name": "JANE SMITH, MRes", "given": "MRes", "family": "JANE SMITH", "initials": "M. J. S.", "capitalized_force": "Mres Jane Smith"} {"name": "JANE YO-YO MA", "given": "JANE", "family": "YO-YO", "suffix": "MA", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: name as family (declared)"], "initials": "J. Y.", "capitalized": "Jane Yo-Yo MA"} {"name": "JEAN ST-PIERRE", "given": "JEAN", "family": "ST-PIERRE", "initials": "J. S.", "capitalized": "Jean St-Pierre"} {"name": "JEAN y Perez", "given": "JEAN", "middle": "y", "family": "Perez", "initials": "J. y. P.", "capitalized_force": "Jean y Perez"} @@ -1942,8 +1945,13 @@ {"name": "Jane Smith née Jones, PhD", "given": "Jane", "family": "Smith", "suffix": "PhD", "maiden": "Jones", "initials": "J. S."} {"name": "Jane Smith née PhD", "given": "Jane", "middle": "Smith", "family": "née", "suffix": "PhD", "initials": "J. S. n.", "capitalized_force": "Jane Smith Née PhD"} {"name": "Jane Smith née V", "given": "Jane", "family": "Smith", "maiden": "V", "initials": "J. S."} +{"name": "Jane Smith, AuD", "given": "Jane", "family": "Smith", "suffix": "AuD", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: name as given (position)"], "initials": "J. S."} {"name": "Jane Smith, Dr / PhD", "title": "Dr", "given": "Jane", "family": "Smith", "suffix": "PhD", "initials": "J. S."} +{"name": "Jane Smith, LeBron", "given": "LeBron", "family": "Jane Smith", "initials": "L. J. S.", "capitalized_force": "Lebron Jane Smith"} +{"name": "Jane Smith, MRes", "given": "Jane", "family": "Smith", "suffix": "MRes", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: name as given (position)"], "initials": "J. S."} {"name": "Jane Smith, PhD/NP-C", "given": "Jane", "family": "Smith", "suffix": "PhD/NP-C", "initials": "J. S."} +{"name": "Jane Smith, PhDc", "given": "PhDc", "family": "Jane Smith", "initials": "P. J. S.", "capitalized_force": "Phdc Jane Smith"} +{"name": "Jane Smith, Pharm-D", "given": "Pharm-D", "family": "Jane Smith", "initials": "P. J. S."} {"name": "Jane Smith, née Jones", "given": "née", "middle": "Jones", "family": "Jane Smith", "initials": "n. J. J. S.", "capitalized_force": "Née Jones Jane Smith"} {"name": "Jane Smith-NP-C", "given": "Jane", "family": "Smith-NP-C", "initials": "J. S.", "capitalized_force": "Jane Smith-Np-C"} {"name": "Jane and née Jones", "given": "Jane and née", "family": "Jones", "initials": "J. n. J.", "capitalized_force": "Jane and Née Jones"} @@ -4231,11 +4239,13 @@ {"name": "Smith, Jr., John", "family": "Smith", "suffix": "Jr., John", "ambiguities": ["COMMA_STRUCTURE"], "initials": "S.", "generation": "Jr.", "credentials": "John"} {"name": "Smith, Jr., PhD", "family": "Smith", "suffix": "Jr., PhD", "initials": "S.", "generation": "Jr.", "credentials": "PhD"} {"name": "Smith, LEED AP", "given": "LEED", "middle": "AP", "family": "Smith", "initials": "L. A. S.", "capitalized_force": "Leed Ap Smith"} -{"name": "Smith, M.B. ChB", "given": "M.", "middle": "B. ChB", "family": "Smith", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: credential as suffix (vocabulary)"], "initials": "M. B. C. S.", "capitalized_force": "M.B. Chb Smith"} +{"name": "Smith, M.B. ChB", "family": "Smith", "suffix": "M.B. ChB", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: name as given (position)"], "initials": "S."} {"name": "Smith, M.D.", "given": "M.", "middle": "D.", "family": "Smith", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: credential as suffix (vocabulary)"], "initials": "M. D. S."} {"name": "Smith, M.D. / PhD", "family": "Smith", "suffix": "M.D. / PhD", "initials": "S."} +{"name": "Smith, M.D. M. Sc.", "given": "M.", "middle": "D. M. Sc.", "family": "Smith", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: credential as suffix (vocabulary)"], "initials": "M. D. M. S. S."} {"name": "Smith, M.D. MS", "family": "Smith", "suffix": "M.D. MS", "initials": "S."} {"name": "Smith, M.D. Ph.D.", "family": "Smith", "suffix": "M.D. Ph.D.", "initials": "S."} +{"name": "Smith, M.D. PhDc", "given": "M.", "middle": "D. PhDc", "family": "Smith", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: credential as suffix (vocabulary)"], "initials": "M. D. P. S.", "capitalized_force": "M.D. Phdc Smith"} {"name": "Smith, MA", "family": "Smith", "suffix": "MA", "initials": "S."} {"name": "Smith, MD", "family": "Smith", "suffix": "MD", "initials": "S."} {"name": "Smith, MD - PhD - FACS", "family": "Smith", "suffix": "MD - PhD - FACS", "initials": "S."} @@ -4244,6 +4254,7 @@ {"name": "Smith, MD PhD", "family": "Smith", "suffix": "MD PhD", "initials": "S."} {"name": "Smith, MD; PhD", "family": "Smith", "suffix": "MD; PhD", "initials": "S."} {"name": "Smith, MEng", "given": "MEng", "family": "Smith", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: credential as suffix (vocabulary)"], "initials": "M. S.", "capitalized_force": "Meng Smith"} +{"name": "Smith, MRes", "given": "MRes", "family": "Smith", "initials": "M. S.", "capitalized_force": "Mres Smith"} {"name": "Smith, Ma", "given": "Ma", "family": "Smith", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: credential as suffix (vocabulary)"], "initials": "M. S."} {"name": "Smith, Ma. John", "given": "Ma.", "middle": "John", "family": "Smith", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: credential as suffix (vocabulary)"], "initials": "M. J. S."} {"name": "Smith, Major. John", "title": "Major.", "given": "John", "family": "Smith", "initials": "J. S."} From f084da4b6df02af66a77285aea20b9f2ba621b3d Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Sat, 21 Nov 2026 15:18:29 -0800 Subject: [PATCH 2/5] Narrow the missing-credentials recipe to the words the shape misses Co-Authored-By: Claude Opus 5.5 --- docs/policy.rst | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/policy.rst b/docs/policy.rst index 76c0613f4..7734dc398 100644 --- a/docs/policy.rst +++ b/docs/policy.rst @@ -1554,8 +1554,9 @@ two-word surname, which the default reads as a credential: Finding the credentials your data uses ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -A credential written in mixed case that the vocabulary does not list -(``PhDc``, ``Pharm-D``) is read by neither shape above. After a comma +A credential the vocabulary does not list, written in mixed case +without two capitals opening it or one ending it (``PhDc``, +``Pharm-D``), is read by neither shape above. After a comma behind a full name it becomes the given name, and the words before the comma become the family name, the way ``Ruiz Paz, Ana`` is read. To find the ones your data holds: @@ -1605,14 +1606,16 @@ A non-empty ``ambiguities`` holding ``suffix-or-name`` marks a name where the parser weighed a credential against a name, as it does for the capitals shape, and for an unlisted word behind a listed credential, which is read as a credential and reported -(``Ana Ruiz Paz, PhD PhDc``). A mixed-case word opening the part -after the comma is never weighed, so it carries no report, and the count -above is the way to find it: +(``Ana Ruiz Paz, PhD PhDc``). A mixed-case word that neither shape +reads, opening the part after the comma, is never weighed, so it +carries no report, and the count above is the way to find it: .. doctest:: >>> [a.kind.value for a in parse("Ana Ruiz Paz, XYZ").ambiguities] ['suffix-or-name'] + >>> [a.kind.value for a in parse("Ana Ruiz Paz, MRes").ambiguities] + ['suffix-or-name'] >>> parse("Ana Ruiz Paz, PhDc").ambiguities () >>> [a.kind.value for a in parse("Ana Ruiz Paz, PhD PhDc").ambiguities] From 51099af05a24f07650a4d35e7c49b2b8a3e16a80 Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Sat, 21 Nov 2026 15:34:38 -0800 Subject: [PATCH 3/5] Address the review of the mixed-case credential shape The comma's filter asks the shape's two ends in C, so a word with a capital only inside it (McDonald, LeBron) no longer pays the count's frames. Rules S9 now define the mixed-case spelling and C6 reads it; C6 and C16 record the accepted costs (DAndre, McDONALD after a two-word surname, Jansen, J.P. IJsbrand), R4 states its precedence over R5 and where the kept spelling does not reach, and decisions/C6's cost paragraph is corrected. Two code arms no input reached are removed, and the rows the tests review asked for are added, among them the one that pins classify's mixed_case=False. Co-Authored-By: Claude Opus 5.5 --- docs/customize.rst | 4 +- ...a-credential-after-one-word-and-a-comma.md | 2 +- ...caps-word-needs-the-names-case-contrast.md | 6 +- .../R4-case-repair-reads-the-unjoined-mark.md | 1 + ...-that-join-the-ambiguous-class-by-shape.md | 3 +- docs/design/rules/C1-suffix-comma-decision.md | 4 +- ...a-credential-after-one-word-and-a-comma.md | 6 ++ ...ambiguous-credential-class-at-the-comma.md | 2 +- ...caps-word-needs-the-names-case-contrast.md | 11 ++- .../R4-case-repair-reads-the-unjoined-mark.md | 8 +- ...-that-join-the-ambiguous-class-by-shape.md | 6 +- docs/languages.rst | 3 +- docs/locales.rst | 4 +- docs/release_log.rst | 2 +- docs/usage.rst | 4 +- nameparser/_pipeline/_comma.py | 21 +++-- nameparser/_pipeline/_vocab.py | 21 ++--- nameparser/_policy.py | 2 +- nameparser/_render.py | 5 +- tests/v2/cases.py | 77 +++++++++++++++++++ tests/v2/test_cases.py | 13 ++-- tools/differential/corpus_rules.jsonl | 7 ++ tools/differential/snapshot.jsonl | 7 ++ 23 files changed, 170 insertions(+), 49 deletions(-) diff --git a/docs/customize.rst b/docs/customize.rst index 6207976e2..1a0632dd3 100644 --- a/docs/customize.rst +++ b/docs/customize.rst @@ -1277,7 +1277,9 @@ signatures: usual way says nothing about how the name was cased. - A suffix written in more than one case is the writer's spelling and is kept as written (``john smith EdD`` gives ``John Smith EdD``) - unless you pass ``force=True``. + unless you pass ``force=True``. An unlisted credential read by its + mixed case after a comma (``Jane Smith, MRes``) is kept as written + even then, since nothing else says how it is spelled. .. doctest:: diff --git a/docs/design/decisions/C16-initials-spelling-a-credential-after-one-word-and-a-comma.md b/docs/design/decisions/C16-initials-spelling-a-credential-after-one-word-and-a-comma.md index 53be1c7de..57381ae68 100644 --- a/docs/design/decisions/C16-initials-spelling-a-credential-after-one-word-and-a-comma.md +++ b/docs/design/decisions/C16-initials-spelling-a-credential-after-one-word-and-a-comma.md @@ -21,4 +21,4 @@ Open: none in this file. WHERE IT SITS. The first draft amended rules/C5, and the design-docs review found it outside C5's When (two letters, unlisted) and its Signal, overriding C13 and contradicting C11 with neither saying so; it is rules/C16, with a precedence line in C8 and C13, a sentence in C11's first Then bullet, and a line in C1's map. HOW. `_comma.decide` gathers the first such run and passes it to `segment_suffix_reading`, which returns no reading where the run stands in the part's leading run of titles, so the part is the given part; the run is then tagged `initial`, as a run written apart is, so the given part's walk does not peel it as a trailing suffix behind a title, and the report is made there, where the decision was taken. ACCEPTED: `Smith, M.D.` reads given 'M.', middle 'D.', the credential named in the report, the 11 ClinicalTrials.gov names and FEC's handful of lone `M.D.`/`M.S.` the cost; 1.4.0 read all of these given 'J.P.' or 'M.D.' whole, 2.0.0 through 3.0.1 suffix (wheels, 2026-11-10). RECOMPUTE: the Tweede Kamer figures compose `Achternaam`, `Tussenvoegsel`, `Titels` and `Initialen` from the feed's `Persoon` entity in the four forms above and count the parses with an empty given name, in each tree; the local ones are `uv run python tools/differential/snapshot.py --local ctgov-officials --base ` and the same for `fec-individuals`, `psc-individuals`, `ukec-individuals` and `tse-donors`. -- 2026-11-21 #1516 — A MIXED-CASE CREDENTIAL BEHIND THE RUN IS ITS COMPANY. Decided 2026-11-21. `Smith, M.B. ChB` reads suffix 'M.B. ChB', reported, where the #1238 entry accepted given 'M.', middle 'B. ChB' (as 1.4.0 read given 'M.B.', middle 'ChB'), because the caps shape now reads a word in mixed case that opens with two capitals or ends in one after a comma (decisions/C6's 2026-11-21 #1516 entry), and an unlisted capitals word C6 admits behind the run is company, as `Smith, J.P. AUD` read already. A credential written in neither shape stays a name word behind the run (`Smith, M.D. PhDc`, `Smith, M.D. M. Sc.` → given 'M.'), as the rule's Accepted bullet now states. SUPERSEDES: the #1238 entry's acceptance of `Smith, M.B. ChB`. +- 2026-11-21 #1516 — A MIXED-CASE CREDENTIAL BEHIND THE RUN IS ITS COMPANY. Decided 2026-11-21. `Smith, M.B. ChB` reads suffix 'M.B. ChB', reported, where the #1238 entry accepted given 'M.', middle 'B. ChB' (as 1.4.0 read given 'M.B.', middle 'ChB'), because the caps shape now reads a word in mixed case that opens with two capitals or ends in one after a comma (decisions/C6's 2026-11-21 #1516 entry), and an unlisted capitals word C6 admits behind the run is company, as `Smith, J.P. AUD` read already. A credential written in neither shape stays a name word behind the run (`Smith, M.D. PhDc`, `Smith, M.D. M. Sc.` → given 'M.'), as the rule's Accepted bullet now states. The cost: a given name written in the shape behind the run is company too, so `Jansen, J.P. IJsbrand` reads suffix 'J.P. IJsbrand' and no given name, where ad9d5d20 read given 'J.', as `Jansen, J.P. IJSBRAND` already read; accepted in the rule, a list writing initials and then such a name being rarer than the credentials written so behind initials. SUPERSEDES: the #1238 entry's acceptance of `Smith, M.B. ChB`. diff --git a/docs/design/decisions/C6-unlisted-all-caps-word-needs-the-names-case-contrast.md b/docs/design/decisions/C6-unlisted-all-caps-word-needs-the-names-case-contrast.md index b769a49d2..e0ad61d4a 100644 --- a/docs/design/decisions/C6-unlisted-all-caps-word-needs-the-names-case-contrast.md +++ b/docs/design/decisions/C6-unlisted-all-caps-word-needs-the-names-case-contrast.md @@ -14,9 +14,9 @@ Open: none in this file. - 2026-10-18 #728 — SPLIT FROM decisions/C1 with the rule. The entries above were written under decisions/C1 while this rule was part of rules/C1, and moved here unchanged but for the pointers the move broke, the measurement paragraphs, each cut to one line naming its population, counts, baseline and PR, and the superseded passages, each cut to its decision and what replaced it; where one says rules/C1 or C1, it means the rule as it then stood, which held this one. - 2026-11-21 #1516 — A WORD IN MIXED CASE WRITTEN THE WAY A CREDENTIAL IS JOINS THE CAPS SHAPE AFTER A COMMA. Decided 2026-11-21. An unlisted word of letters in mixed case that opens with two capitals or ends in one (`MRes`, `DClinPsy`, `AuD`, `BScN`) is the caps shape wherever an all-caps word is read after a comma: C4's count, C6's contrast and C16's company (`Jane Smith, MRes` → given 'Jane', family 'Smith', suffix 'MRes', reported, where 1.4.0 through 3.1.0 read given 'MRes', family 'Jane Smith'). Such a word is written neither in capitals nor the way a name is, and no vocabulary lists every degree written so. A capital only inside the word is a name's writing (`LeBron`, `McKenzie`, `DeShawn`), and a word in mixed case holding a hyphen or a slash is left out: a first build took joined chunks too, and given boxes are full of names joined so (`Cheng-I`, `I-Chun`, `Jay-R` in hundreds of ORCID given boxes, `Gul-E` and `Noor-E` in PSC's), so `Pharm-D` stays the given name, as does `PhDc`, whose ends hold one capital. GAIN. `snapshot.py --local --base `: ClinicalTrials.gov officials 915 moved of 539,368, 776 gaining the credential (`AuD`, `DClinPsy`, `DNSc`, `MBBChir`, `MRes`, `BMedSci` among the words taken, and `PhD` behind them), one reading `MDs` as the credential where it had read `Abd`, and 138 moving only the forced case view or a report's alternative; contacts 652 moved, 580 gaining the credential (`AuD`, `MEd`, `BScN`, `HBSc`) and 72 a case view or an alternative only; ORCID researchers 24 moved, all credentials (`CEng`, `PGDip`, `MAEd`), `local_agreement.py orcid-researchers --base` scoring 5 fixed, 0 broken, 2 changed (wrong either way); FEC, GOV.UK people, UK Electoral Commission donors, DOF signatures, PSC and PatentsView 0 moved, and PSC's and PatentsView's agreement unchanged. - COST. One name of the moved reads wrong, a Catalan given name typed with a doubled capital (`LLuís`) behind a two-word head. Beyond the moved, the shape costs the listing form behind two or more name words what the all-caps shape costs it (`García Márquez, JOSE` → suffix): a given box holding a word of the shape, unlisted, in a record of mixed case, is in 577 of ORCID's 1,831,533 records (typos such as `MAria`, initials glued to a name, and real spellings, Dutch `IJsbrand` and Serbo-Croatian `LJiljana`), 55 PatentsView records and no PSC record, and it moves only where a writer composes `Surname Surname, Given`, which no fielded corpus composes (`de Vries Smit, IJsbrand` → suffix). + COST. One name of the moved reads wrong, a Catalan given name typed with a doubled capital (`LLuís`) behind a two-word head. Beyond the moved, the shape costs a given name written in it what the all-caps shape costs one written in capitals, in two forms. Behind two or more name words and a comma, the listing form reads it as the credential (`García Márquez, JOSE` and `García López, DAndre` → suffix), which reaches a given name typed without its apostrophe (`DAndre`, `ONeill`) and a surname in capitals behind a lowercase prefix (`McDONALD`, `DiCAPRIO`), each recorded as accepted in rules/C6; narrowing the spelling to spare the second would cost about 190 of the credentials the moved names gained (ClinicalTrials.gov officials 126, contacts 63, ORCID 1), which end in a run of capitals behind a lowercase letter too (`MScPT`, `PhDMD`, `MBBChBAO`). And behind one word, a run of initials spelling a listed credential takes such a name as company, so the list loses its given name (`Jansen, J.P. IJsbrand` → suffix 'J.P. IJsbrand'; rules/C16's Accepted bullet), where ad9d5d20 read given 'J.'. A given box holding a word of the shape, unlisted, in a record of mixed case, is in 577 of ORCID's 1,831,533 records (typos such as `MAria`, initials glued to a name, and real spellings, Dutch `IJsbrand` and Serbo-Croatian `LJiljana`), 55 PatentsView records and no PSC record; no fielded corpus composes either form, so the boxes bound the exposure rather than count it. WHY NOT EVERYWHERE'S TRAILING POSITIONS. Ending a name without a comma the shape is how a surname typed without its apostrophe is written (`ONeill`, `DSouza`, `OReilly`), and how `McCAFFREY` is: about 770 ORCID family boxes hold such a word alone, each of which would lose its family name in a name of three words under `CapsSuffixes.EVERYWHERE`. So the predicate takes the mixed-case arm only where the comma's decision asks (`caps_shape_candidate`'s `mixed_case`), and classify's trailing tag reads capitals alone (`Alex Lee ONeill` → family 'ONeill' under EVERYWHERE). - CASE REPAIR (rules/R4). A shape word in mixed case is kept as written, forced or not, where the acronym clause wrote `MRES`; and the company a C16 run takes now carries the shape's marks the count gives, so `Smith, J.P. AUD` and `Ashley Knight, M.S. BME` keep their capitals forced, where master wrote `Aud` and `Bme`. + CASE REPAIR (rules/R4). A shape word in mixed case is kept as written, forced or not, where the shape's mark would otherwise send it to the acronym clause's capitals (`MRES`; on ad9d5d20 the word was the given name, forced `Mres`); and the company a C16 run takes now carries the shape's marks the count gives, so `Smith, J.P. AUD` and `Ashley Knight, M.S. BME` keep their capitals forced, where master wrote `Aud` and `Bme`. C16. `Smith, M.B. ChB` reads suffix 'M.B. ChB', as `Smith, J.P. AUD` already did; the reversal of that part of decisions/C16's 2026-11-10 #1238 entry is decisions/C16's 2026-11-21 #1516 entry. THE FILTER'S OWN NARROWING. The comma's C-level filter first widened `isupper()` to `not islower() and not istitle()`, which drops a word of capitals split by a caseless letter (`istitle()` reads `XיZ` title-shaped): the corpus run found the one such word ctgov-contacts holds moved from the suffix to the given name, and the filter keeps `isupper()` as an arm of its own (case row `a_caps_word_holding_a_caseless_letter_stays_a_credential`). - RECOMPUTE: the moves, `snapshot.py --local ctgov-officials --base ` and likewise `ctgov-contacts`, `orcid-researchers`, `fec-individuals`, `govuk-people`, `ukec-individuals`, `dof-signatures`, `psc-individuals`, `patentsview-inventors`; the box counts, over each fielded corpus's `raw.jsonl` in the tools cache, the words of the given box (or the family box alone) that `_vocab._mixed_capitals` admits once NFC-composed and `in_any_wordlist` refuses, in records whose composed `name` is neither all upper nor all lower case, measured against ad9d5d20's lexicon on 2026-11-21. + RECOMPUTE: the moves, `snapshot.py --local ctgov-officials --base ` and likewise `ctgov-contacts`, `orcid-researchers`, `fec-individuals`, `govuk-people`, `ukec-individuals`, `dof-signatures`, `psc-individuals`, `patentsview-inventors`; the box counts, over each fielded corpus's `raw.jsonl` in the tools cache (ORCID's and PatentsView's `given` box, PSC's `forename` and `middle_name`; for the 770, ORCID's `family` box holding the word alone), the words that this PR's `_vocab._mixed_capitals` admits once NFC-composed and `in_any_wordlist` refuses under the default lexicon, in records whose composed `name` is neither all upper nor all lower case, measured on 2026-11-21. diff --git a/docs/design/decisions/R4-case-repair-reads-the-unjoined-mark.md b/docs/design/decisions/R4-case-repair-reads-the-unjoined-mark.md index 468f0f084..278fba016 100644 --- a/docs/design/decisions/R4-case-repair-reads-the-unjoined-mark.md +++ b/docs/design/decisions/R4-case-repair-reads-the-unjoined-mark.md @@ -129,3 +129,4 @@ Accepted costs, deferred to the rescoped #459 rather than relitigated here: the - 2026-11-09 #1280 — AN ELIDED PARTICLE IN A HYPHENATED WORD KEEPS ITS LOWERCASE. #1224's hyphen clause wrote the first word of a hyphenated word's opening part with the particle arm left out, and the per-word walk splits `'s` at its apostrophe, so `WILLEM 'S-GRAVESANDE` repaired to "Willem 'S-Gravesande" and the lowercase `willem 's-gravesande` was made wrong the same way, as 3.0.1 did; spaced, the whole-token particle test already kept `'s Gravesande` lowercase. Dutch writes the elided articles `'s` (des) and `'t` (het) lowercase whether a space or a hyphen joins them (Wikidata labels: Arent van 's-Gravesande, G.H. 's-Gravesande; no committed corpus outside the rules' own example rows, and no local corpus, writes a hyphenated `'s-` or `'t-`, decisions/N2's 2026-11-09 entry; re-measured over the local corpora, 2026-11-09, the same detector finding 96 spaced `'t`; a hyphen before the particle, `-'s`, found in none). Decided by the word's form, not a new property: the particles whose listed spelling opens with an apostrophe are exactly `'s`, `'t` and their typographic twins (`Lexicon.default()._sets.particles`, 2026-11-09), so a part of a hyphenated word that is such a particle, asked whole by the particle arm, keeps its lowercase, and every other particle opening a hyphenated word keeps #1224's capital (`Ter-Petrosyan`). Any part, not the opening one only: the per-word walk splits the particle at its apostrophe in every part, and a plain particle after the first hyphen already keeps its lowercase (`JUAN GARCIA-DE-VEGA` → 'Juan Garcia-de-Vega'), so `Smit-'s-Gravesande` keeps it too; the first draft lowered the opening part alone, and review found forced repair still rewriting `Willem Smit-'s-Gravesande` to `'S-`. A hyphenated word of particles alone carries no unjoined mark, so rules/R4's all-particle Except does not reach it (`JAN 'S-VAN` → "Jan 's-van", as `MARIA VAN-DER` → 'Maria Van-der' under #1224). The particle arm's own limits stand: a given name opening `'s-` takes its capital (`'S-JACOB SMIT` → "'S-Jacob Smit"). Compared with the parent commit's snapshot, two committed entries move, both in the forced view: `Arent van 's-Gravesande`, which forced repair had rewritten to `'S-`, now comes back as written; and THE COST, `Aaron 'T-Bone Walker` (decisions/N2's `'T-Bone` row), whose middle word forced repair now writes "'t-Bone": a nickname spelled with the listed `'t` and a hyphen is read as that particle, nothing in a one-case `'T-BONE` telling it from `'T-HART`; written in mixed case it is left as written (rules/R5). Pinned by rules/R4's examples and test_an_elided_particle_in_a_hyphenated_word_keeps_its_lowercase. - 2026-11-12 #1256 — THE NO-CAPITAL SCRIPT IS READ FROM THE SCRIPT-PROPERTY TABLE. The 2026-11-08 #1223 test (a first letter whose single-letter lower case title-cases to itself) is replaced by the Georgian row of `_policy._SCRIPT_PROPERTIES`: a first letter in a row with no case is written in its lower case. Over every codepoint it changes the same 46 Mtavruli letters (decisions/script-properties). - 2026-11-12 #1222 (#1256) — DECIDED: A NAME MIXING MTAVRULI WITH MKHEDRULI IS WRITTEN IN MKHEDRULI. Georgian has no case, so its standard writing is Mkhedruli throughout, and a name holding Mtavruli beside Mkhedruli is one case to the contrast like any other caseless name (rules/R5's gate reads the script-property table's Georgian row, decisions/script-properties); `capitalized()` then writes it in Mkhedruli, as `capitalized(force=True)` already did since #1223. Two shapes move on the default path, each kept as written by 1.4.0 through 3.0.1 (run against the wheels from a scratch directory, 2026-11-12): a Mtavruli first letter on Mkhedruli in the Latin habit, `Უჩა გოგოლაძე` → 'უჩა გოგოლაძე' (4 of 5,242 Wikidata labels of Georgian citizens write one, per #1222, counted on 2026-11-07), and a Mtavruli surname beside a Mkhedruli given name, the capitals of emphasis, `ნინო ᲑᲣᲠᲯᲐᲜᲐᲫᲔ` → 'ნინო ბურჯანაძე'. The second differs from Latin, where `capitalized()` keeps a surname written in capitals in a name of mixed case (`Jean DUPONT`): Latin's capitals are case, a choice the writer makes against the rest of the name, while Mtavruli is a style of a caseless script, so the gate sees no contrast and the emphasis is not kept (rules/R5's Accepted bullet). #1223's test pinning the first shape as kept on the default path moved with this entry (tests/v2/test_render.py). +- 2026-11-21 #1516 — A CREDENTIAL READ BY ITS MIXED CASE IS KEPT AS WRITTEN, FORCED OR NOT, and the company of rules/C16's run carries the caps shape's marks (`Smith, J.P. AUD` and `Ashley Knight, M.S. BME` keep their capitals forced, where ad9d5d20 wrote `Aud` and `Bme`). The reason and the measurement are decisions/C6's 2026-11-21 #1516 entry, its CASE REPAIR paragraph; this bullet is R4's pointer to it. A word of that writing read as a credential past a second comma still repairs as any suffix (`Jane Smith, PhD, MRes` forced → `Mres`), as rules/R4 now states. diff --git a/docs/design/decisions/S9-unlisted-words-that-join-the-ambiguous-class-by-shape.md b/docs/design/decisions/S9-unlisted-words-that-join-the-ambiguous-class-by-shape.md index 75e57dc75..ff76c1081 100644 --- a/docs/design/decisions/S9-unlisted-words-that-join-the-ambiguous-class-by-shape.md +++ b/docs/design/decisions/S9-unlisted-words-that-join-the-ambiguous-class-by-shape.md @@ -10,7 +10,6 @@ Examples name each field as the default order reads it; under the family-first o - At the first slot after a comma, paired initials (two single letters joined by a period, the trailing period optional) are the given name and report (`García Márquez, G.J.` → given names 'G.J.'); only an unambiguous suffix word in front that is not title vocabulary, or a second dotted-shape word in the part, or since #1392 a listed credential in a later comma part where the pair stands alone in its own (decisions/C5's 2026-11-15 entry), makes them the credential run (`John Smith, PhD X.Y.` → suffix 'PhD X.Y.'; `García Márquez, Ms G.J.` → title 'Ms', given names 'G.J.'), while a word behind (`De La Cruz, M.J. PhD`) or a class member in front (`García Márquez, Ed G.J.` → given 'Ed') speaks for nothing, and three letters run together read by the count (`García Márquez, G.J.R.` → suffix 'G.J.R.') — 2026-09-30 #563. - A flip resting only on dotted-shape words is silent (`John Smith, X.Y.Z. G.J.`) unless the only words speaking for a pair are other pairs (`John Smith, X.Y. P.Q.` reports) or a later part's credential (`Jane Doe, M.H., PhD` reports, decisions/C5's 2026-11-15 entry); at the trailing slots paired initials are no word of the class and read as the name word they are written as, reported (`John Smith R.T.` → family 'R.T.', `Doe, John R.T.` → middle 'R.T.'), while three dotted letters keep #516's reading (`John Smith X.Y.Z.` → suffix) — 2026-09-30 #563; 2026-10-24 #864. - `Policy.unlisted_caps_suffixes` takes OFF, AFTER_COMMA or EVERYWHERE, default AFTER_COMMA, and a bool raises: an unlisted all-caps alphabetic word of two or more letters joins the class by shape in the part right after a comma behind two or more name words (`John Smith, XYZ` → suffix 'XYZ', `Smith, XYZ` → given 'XYZ'), beside listed credentials as well as alone (`John Smith, PhD XYZ` → suffix 'PhD XYZ'), and under EVERYWHERE at every suffix position — 2026-10-01 #564. -- After a comma a word in mixed case that opens with two capitals or ends in one is the caps shape too (`Jane Smith, MRes` → suffix 'MRes'); under EVERYWHERE the other positions read capitals alone (`Alex Lee ONeill` → family 'ONeill') — 2026-11-21 #1516, recorded under decisions/C6. - The comma's case contrast is carried by a word of the name before the comma that holds a capital, ends in a lowercase cased letter and is claimed by no wordlist as a non-name, so an all-caps record keeps its given name (`MÜLLER WEIß, HANS`, `LLOYD WEBBER, ANDREW PhD`) and a name written in lowercase reads the listing form (`john smith, XYZ` → given 'XYZ'); a lone two-letter word is not admitted at the comma (`García Márquez, MJ` → given 'MJ') unless a later comma part is a listed credential (`García Márquez, MJ, PhD` → suffix 'MJ, PhD', decisions/C5's 2026-11-15 #1392 entry) — 2026-10-01 #564. - Accepted: a given name written in capitals behind a two-word surname reads as the credential (`García Márquez, GABRIEL` → suffix 'GABRIEL', reported), OFF being the escape; and case repair follows the reading, a caps word in the part a suffix comma opened being tagged under AFTER_COMMA, one in a third or later part only under EVERYWHERE — 2026-10-01 #564. - Under EVERYWHERE the cost is the three-word name (`Jean Pierre DUPONT` → family 'Pierre', suffix 'DUPONT'), while a two-word name keeps its family and reports (`Jean DUPONT`); unlisted is checked by wordlist membership rather than tags (`John Smith NEE` keeps family 'NEE'), and a roman numeral is the numeral fork's before the shape is asked (`John Smith VI` → suffix 'VI') — 2026-09-14 (Derek), corrected 2026-09-18. @@ -20,7 +19,7 @@ Examples name each field as the default order reads it; under the family-first o Not standing: the split of 2026-10-17 #682, carried out. -Elsewhere: the wordlist roster the caps entry names, eleven of the thirteen vocabulary fields, corrected to all of them (a caller's surname keeps `Jean Pierre DUPONT` its family under EVERYWHERE) — decisions/S6's 2026-09-18, WHOLE-PR REVIEW ROUND entry; `De La Cruz, M.J. K.L.` → given names 'M.J. K.L.' behind a one-word particle surname (the middle since decisions/S3's 2026-10-24 #864 entry) — decisions/C3's 2026-10-01 (Derek), #575 entry; the three listed and dotted runs the caps entry kept apart (`John Smith, Ed Ma`, `John Smith, ma do`, `John Smith, X.Y.Z. A.B.`), credential runs by C4's count — decisions/S7's 2026-09-27 (Derek), #544 entry headed A CREDENTIAL RUN KEEPS ITS AMBIGUOUS MEMBERS; the contrast test reused for a suffix word ending the name before the comma — decisions/C12's 2026-10-18 (Derek), #656 entry. +Elsewhere: the caps shape's mixed-case spelling, read after a comma only (`Jane Smith, MRes` → suffix 'MRes'; under EVERYWHERE `Alex Lee ONeill` keeps family 'ONeill') — decisions/C6's 2026-11-21 #1516 entry. The wordlist roster the caps entry names, eleven of the thirteen vocabulary fields, corrected to all of them (a caller's surname keeps `Jean Pierre DUPONT` its family under EVERYWHERE) — decisions/S6's 2026-09-18, WHOLE-PR REVIEW ROUND entry; `De La Cruz, M.J. K.L.` → given names 'M.J. K.L.' behind a one-word particle surname (the middle since decisions/S3's 2026-10-24 #864 entry) — decisions/C3's 2026-10-01 (Derek), #575 entry; the three listed and dotted runs the caps entry kept apart (`John Smith, Ed Ma`, `John Smith, ma do`, `John Smith, X.Y.Z. A.B.`), credential runs by C4's count — decisions/S7's 2026-09-27 (Derek), #544 entry headed A CREDENTIAL RUN KEEPS ITS AMBIGUOUS MEMBERS; the contrast test reused for a suffix word ending the name before the comma — decisions/C12's 2026-10-18 (Derek), #656 entry. Open: none in this file. diff --git a/docs/design/rules/C1-suffix-comma-decision.md b/docs/design/rules/C1-suffix-comma-decision.md index 973234e90..4a468a3d3 100644 --- a/docs/design/rules/C1-suffix-comma-decision.md +++ b/docs/design/rules/C1-suffix-comma-decision.md @@ -6,7 +6,7 @@ - **Only the part after the first comma decides**, but for a suffix word ending a whole name before it (C12) and a listed credential in a later part, which speaks for two capitals, dotted or not, standing alone in the part after the first comma (C5). - **How the words before the comma are counted** is C3's. -- **The ambiguous credential class**, counted by name words (C4), with paired initials (C5) and an unlisted all-caps word (C6) read there by rules of their own, and initials spelling a listed credential behind one word read as paired initials are (C16). +- **The ambiguous credential class**, counted by name words (C4), with paired initials (C5) and an unlisted word in the caps shape (C6) read there by rules of their own, and initials spelling a listed credential behind one word read as paired initials are (C16). - **A part read as postnominal** is read before any join (C7). - **The listing form's part after the comma** is still read for what it is (C8), and a credential opening it makes it the postnominal part (C13). - **A one-character suffix word inside a comma part** is read by what stands before it (C9). @@ -30,7 +30,7 @@ - **A suffix word written like an initial** ("John Smith, V."): by default a recognized suffix word counts even written like an initial ("V."); under the strict comma-suffix switch C14 governs, and the word is vetoed. - **The count against written case** ("Smith, MA", "Smith Jr., Ma"): C4 counts the name words before the comma first and asks written case (S6) second, only where the count has left the word a name. - **Paired initials against the count** ("García Márquez, G.J."): C5 is the stated exception to C4's count, since two words before the comma may be one surname written in two. -- **An unlisted all-caps word** ("John Smith, XYZ"): C6 decides whether it joins C4's class at all, only where the name carries a case contrast, and once it has joined, C4's count reads it. +- **An unlisted word in the caps shape** ("John Smith, XYZ"): C6 decides whether it joins C4's class at all, only where the name carries a case contrast, and once it has joined, C4's count reads it. - **A generation ending the name before the comma against paired initials after it** ("John Smith Jr., M.J."): written dotted, the initials keep C5's reading and are the given name, the generation staying the suffix, unless a later part's listed credential speaks for them (C5); written undotted as two capitals, they are C12's credential, read as the credential they look like. A numeral ending the family part is read as the comma-less name reads it (S10), so the roman numerals S10 reads by their shape stay the suffix as the listed ones do, save that a particle or a connective in the part counts as no word to spare there, the comma having named the part a surname (S10). ``` "John Smith Jr., M.J." → given_names="M.J." diff --git a/docs/design/rules/C16-initials-spelling-a-credential-after-one-word-and-a-comma.md b/docs/design/rules/C16-initials-spelling-a-credential-after-one-word-and-a-comma.md index 6e4622a7c..0179a7f17 100644 --- a/docs/design/rules/C16-initials-spelling-a-credential-after-one-word-and-a-comma.md +++ b/docs/design/rules/C16-initials-spelling-a-credential-after-one-word-and-a-comma.md @@ -60,6 +60,12 @@ "Smith, M.D. PhDc" → given="M." ``` +- A given name written in the caps shape behind the run is company like a credential, so the run and the name read as the credential and the name loses its given name: 'Jansen, J.P. IJsbrand' reads as 'Jansen, J.P. IJSBRAND' does. A list writing initials and then a name spelled so is rare beside the credentials written that way behind initials ('Smith, M.B. ChB'). + ``` + "Jansen, J.P. IJsbrand" → suffix="J.P. IJsbrand" + "Jansen, J.P. Ijsbrand" → given="J." + ``` + - A one-word surname before a credential written as dotted initials reads as a name with no given name written out ('Smith, M.D.' → given 'M.', middle 'D.'), the credential named in the report; a credential then a given name past a second comma ('Arenas, M.D., Magdalena C.') reads as its twin of unlisted letters does. The undotted spelling is the credential's own and is unchanged ('Smith, MD'). ``` "Smith, M.D." → given="M." diff --git a/docs/design/rules/C4-ambiguous-credential-class-at-the-comma.md b/docs/design/rules/C4-ambiguous-credential-class-at-the-comma.md index 9df65ee12..feb1f6c37 100644 --- a/docs/design/rules/C4-ambiguous-credential-class-at-the-comma.md +++ b/docs/design/rules/C4-ambiguous-credential-class-at-the-comma.md @@ -48,7 +48,7 @@ **Precedence:** - **Paired initials** ("García Márquez, G.J."): C5 wins; paired initials are the exception to the count. -- **An unlisted all-caps word** ("MÜLLER WEIß, HANS"): C6 decides whether it is a word of this class here at all, which it is only where the name carries a case contrast. +- **An unlisted word in the caps shape** ("MÜLLER WEIß, HANS"): C6 decides whether it is a word of this class here at all, which it is only where the name carries a case contrast. --- **Signal:** count: name words before the comma, for a word of the ambiguous class after it diff --git a/docs/design/rules/C6-unlisted-all-caps-word-needs-the-names-case-contrast.md b/docs/design/rules/C6-unlisted-all-caps-word-needs-the-names-case-contrast.md index d9d3e2043..6c6667a30 100644 --- a/docs/design/rules/C6-unlisted-all-caps-word-needs-the-names-case-contrast.md +++ b/docs/design/rules/C6-unlisted-all-caps-word-needs-the-names-case-contrast.md @@ -8,7 +8,7 @@ ``` "MÜLLER WEIß, HANS" → given="HANS" · boundary ``` -- **A word in mixed case that opens with two capitals or ends in one is written the way a credential is, and reads here as an all-caps word does** ('MRes', 'DClinPsy', 'AuD'): it is not written the way a name is, and the vocabulary cannot list every degree written so. A capital only inside the word is a name's writing ('LeBron', 'McKenzie'), and so is a word in mixed case holding a hyphen or a slash ('Pharm-D', as 'Jay-R' is a given name). The mixed-case word is read after the comma only: S9's other positions read capitals alone. +- **A word in the caps shape's mixed-case spelling (S9) reads here as an all-caps word does** ('MRes', 'DClinPsy', 'AuD'), the contrast gating it alike; S9 reads that spelling after the comma only. ``` "Jane Smith, MRes" → suffix="MRes" "Jane Smith, AuD" → suffix="AuD" @@ -33,6 +33,15 @@ "Smith, PU-PH" → given="PU-PH" · boundary ``` +**Accepted:** + +- A given name written in the mixed-case spelling after a two-word surname and a comma reads as the credential, as one written in capitals does: a surname written in capitals behind a lowercase prefix ('McDONALD', 'DiCAPRIO') and a given name typed without its apostrophe ('DAndre', 'ONeill') end in a capital or open with two. Narrowing the spelling to spare them would cost the credentials written the same way ('MScPT', 'PhDMD', 'MBBChBAO'), which outnumber them where names are typed. + ``` + "García López, DAndre" → suffix="DAndre" + "John Smith, McDONALD" → suffix="McDONALD" + "García López, DANDRE" → suffix="DANDRE" + ``` + --- **Signal:** case contrast: a word before the comma written in mixed case the way a name is **history:** decisions/C6 · **implemented:** nameparser/_pipeline/_comma.py diff --git a/docs/design/rules/R4-case-repair-reads-the-unjoined-mark.md b/docs/design/rules/R4-case-repair-reads-the-unjoined-mark.md index 40c815dfe..6741da1cb 100644 --- a/docs/design/rules/R4-case-repair-reads-the-unjoined-mark.md +++ b/docs/design/rules/R4-case-repair-reads-the-unjoined-mark.md @@ -90,7 +90,7 @@ "Ronald Macdonald" → capitalized_forced="Ronald MacDonald" "JAMES MACKENZIE" → capitalized="James Mackenzie" · boundary ``` -- **A credential acronym the exceptions map does not carry is an initialism**, so a single-case word the parse put in the suffix role from the acronym vocabulary (written whole across any hyphen or slash it holds, `OTR/L`, not as two name words), or read as a credential by its dotted shape alone (S3) or by its capitals (S9), repairs to its all-caps spelling rather than a title-cased one, and that repair outranks the Mc convention where a word fits both (MCSE, not McSe). A roman numeral the parse put in the suffix role is written in capitals the way a generation is written, whether or not the vocabulary lists it (VI as well as III). A suffix word that is neither an acronym, a numeral nor an exceptions-map entry -- the generational `jr`, `sr` -- keeps its title case. A word read as a credential after a comma by its mixed case (C6) is kept as written, forced or not, its capitals being what made it one. +- **A credential acronym the exceptions map does not carry is an initialism**, so a single-case word the parse put in the suffix role from the acronym vocabulary (written whole across any hyphen or slash it holds, `OTR/L`, not as two name words), or read as a credential by its dotted shape alone (S3) or by its capitals (S9), repairs to its all-caps spelling rather than a title-cased one, and that repair outranks the Mc convention where a word fits both (MCSE, not McSe). A roman numeral the parse put in the suffix role is written in capitals the way a generation is written, whether or not the vocabulary lists it (VI as well as III). A suffix word that is neither an acronym, a numeral nor an exceptions-map entry -- the generational `jr`, `sr` -- keeps its title case. A word read as a credential after a comma by its mixed case (C6) is kept as written, forced or not, its capitals being what made it one; R5's forced repair of a suffix in more than one case passes it by. Such a word read as a credential by other means, past a second comma (C2) or behind a listed credential the count did not weigh, has no such mark and is repaired as any suffix is. ``` "Jane Smith, MRes" → capitalized_forced="Jane Smith, MRes" "john smith md" → capitalized="John Smith MD" @@ -171,6 +171,12 @@ **Accepted:** +- Forced, a listed credential written in mixed case that no mask records is written in capitals beside an unlisted one kept as written: in 'Jane Smith, EdD MRes' the listed word takes the acronym clause and the unlisted one the caps shape's mark. + ``` + "Jane Smith, EdD MRes" → capitalized_forced="Jane Smith, EDD MRes" + "Jane Smith, PhD, MRes" → capitalized_forced="Jane Smith, PhD, Mres" + ``` + - A Cyrillic spelling of an elided prefix before е or і, such as French d' (Д'Естен), loses the capital after its apostrophe, since the Belarusian apostrophe stands before those vowels inside a word and nothing in the letters tells the two apart. ``` "ВАЛЕРІ Д'ЕСТЕН" → capitalized="Валері Д'естен" · boundary diff --git a/docs/design/rules/S9-unlisted-words-that-join-the-ambiguous-class-by-shape.md b/docs/design/rules/S9-unlisted-words-that-join-the-ambiguous-class-by-shape.md index 9b2feee1d..1fa8354d1 100644 --- a/docs/design/rules/S9-unlisted-words-that-join-the-ambiguous-class-by-shape.md +++ b/docs/design/rules/S9-unlisted-words-that-join-the-ambiguous-class-by-shape.md @@ -1,6 +1,6 @@ # S9 — unlisted words that join the ambiguous class by shape -**When:** an unlisted word written in capitals or in dotted chunks stands where a suffix may stand, as in "John Smith XYZ". +**When:** an unlisted word written in capitals, in dotted chunks, or after a comma in mixed case the way a credential is, stands where a suffix may stand, as in "John Smith XYZ". **Then:** an unlisted word joins the ambiguous class (S4) by SHAPE, in the positions each shape is admitted: the dotted shape by default, the caps shape by default in one position and elsewhere where the caller asks for it. @@ -13,7 +13,7 @@ "John Smith, Pu-Ph" → given="Pu-Ph" · boundary "Jean Pierre DUPONT-MORETTI" unlisted_caps_suffixes-everywhere → suffix="DUPONT-MORETTI" ``` -- **A word in mixed case written as a credential is ('MRes', 'AuD') is the caps shape after a comma only** (C6): ending a name it is how a surname typed without its apostrophe is written ('ONeill', 'DSouza'), so the caller setting below reads capitals alone there. +- **A word of letters in mixed case that opens with two capitals or ends in one is written the way a credential is ('MRes', 'DClinPsy', 'AuD'), and is the caps shape after a comma only**, where C6 reads it: a capital only inside the word is a name's writing ('LeBron', 'McKenzie'), and so is a word in mixed case holding a hyphen or a slash ('Pharm-D', as 'Jay-R' is a given name). Ending a name it is how a surname typed without its apostrophe is written ('ONeill', 'DSouza'), so the caller setting below reads capitals alone there. ``` "Jane Smith, MRes" → suffix="MRes" "Alex Lee ONeill" unlisted_caps_suffixes-everywhere → family="ONeill" · boundary @@ -41,5 +41,5 @@ - **An unlisted word in capitals ending a name, under capitals-as-family handling** ("Jean DUPONT"): the caller has said the capitals write the family name, which is the opposite statement about the same word, so the setting that admits it to the class at the end of a name cannot be built with that switch (O9). --- -**Signal:** shape: an unlisted word written in capitals or in dotted chunks, standing in a suffix position +**Signal:** shape: an unlisted word written in capitals, in dotted chunks, or in a credential's mixed case, standing in a suffix position **history:** decisions/S9 · **implemented:** nameparser/_pipeline/_assign.py, nameparser/_pipeline/_classify.py, nameparser/_pipeline/_vocab.py diff --git a/docs/languages.rst b/docs/languages.rst index 6e2960496..b91fba98b 100644 --- a/docs/languages.rst +++ b/docs/languages.rst @@ -125,7 +125,8 @@ titles under ``cs`` wherever a doctorate is one: - title * - Bare, after a comma: ``Jana Malá, MgA`` - title - - suffix, by its capitals (``MgA``); name word (``mjr``) + - suffix, by its mixed case (``MgA``, see + :ref:`all-caps-credentials`); name word (``mjr``) - suffix - title * - Dotted, after a comma: ``Jana Malá, MgA.`` diff --git a/docs/locales.rst b/docs/locales.rst index ede473ade..6a0bb965b 100644 --- a/docs/locales.rst +++ b/docs/locales.rst @@ -1092,7 +1092,9 @@ What a strict choice drops it drops from every name: 'RN' - **The shared words are a default like any other.** Take one out of - the lexicon you build on and no choice brings it back: + the lexicon you build on and no choice brings it back. (The example + writes it ``Phd``: written ``PhD``, an unlisted word is still read as + a credential by its capitals, see :ref:`all-caps-credentials`.) .. doctest:: diff --git a/docs/release_log.rst b/docs/release_log.rst index f8cd9d6fe..3e79e8ef3 100644 --- a/docs/release_log.rst +++ b/docs/release_log.rst @@ -4,7 +4,7 @@ Release Log nameparser 3.2 is under development. - - **Read an unlisted credential written in mixed case after a name and a comma, such as MRes or AuD.** ``parse("Jane Smith, MRes")`` gives suffix ``MRes``, where 1.4.0 through 3.1.0 gave given ``MRes``, family ``Jane Smith``; the word must open with two capitals or end in one, so ``LeBron`` and ``PhDc`` stay given names, and initials spelling a credential before such a word read as the credential with it (``Smith, M.B. ChB``). ``CapsSuffixes.EVERYWHERE`` still reads only words in capitals where no comma stands (``Alex Lee ONeill`` keeps family ``ONeill``). :issue:`1516` + - **Read an unlisted credential written in mixed case after a full name and a comma, such as MRes or AuD.** ``parse("Jane Smith, MRes")`` gives suffix ``MRes``, where 1.4.0 through 3.1.0 gave given ``MRes``, family ``Jane Smith``; the word must open with two capitals or end in one, so ``LeBron`` and ``PhDc`` stay given names, while a given name written so after a two-word surname reads as the credential (``García López, DAndre``). Behind one word it stays the given name (``Smith, MRes``), save behind initials spelling a credential, which read as the credential with it (``Smith, M.B. ChB``, and ``Jansen, J.P. IJsbrand``, which loses its given name). The positions only ``CapsSuffixes.EVERYWHERE`` reads still take words in capitals alone (``Alex Lee ONeill`` keeps family ``ONeill``). :issue:`1516` - **Add French dit and dite as connectives under a French choice.** With ``languages=frozenset({"fr"})`` chosen, ``Jean Dupont dit Lebrun`` gives family ``Dupont dit Lebrun``, where the default, as 1.4.0 through 3.1.0, gives middle ``Dupont dit``, family ``Lebrun``; a West African alias joins the given name the same way (``Mamadou dit Madou``), and the default is unchanged, ``Dit`` and ``Dite`` being names too. :issue:`1159` - **Add Brazilian Portuguese familiar forms, found in the names Brazil's election candidates put on the ballot.** With ``familiar-form`` accepted, ``Tião Alves`` / ``Sebastião Alves`` and ``Cida Silva`` / ``Aparecida Silva`` are consistent, where 3.1.0 read a conflict. They are filed under ``pt-BR``, so a strict choice of another language leaves them out, and one name spelled two ways (``Elizangela`` / ``Elisangela``) is not among them. :issue:`1495` - **Add the Czech and Slovak post-nominals DiS., DrSc. and ArtD. as credentials.** ``parse("Jan Novák, DiS.")`` gives suffix ``DiS.``, where 1.4.0 through 3.1.0 gave title ``DiS.``; DiS., which is also a surname, reads as the credential after a full name and a comma, and written as ``DiS.`` or ``Dis`` it stays a name word at the end of a name of mixed case without one (``Jan Novák DiS.``), while a surname written ``DIS`` there reads as the credential (``Jan DIS``). :issue:`969` diff --git a/docs/usage.rst b/docs/usage.rst index 0561210b8..b657678f7 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -532,8 +532,8 @@ changes them. Two ``Policy`` switches read a word the vocabulary does not hold as a credential from how it is written. ``unlisted_dotted_suffixes`` (on by default) lets a token of two or more period-separated chunks read as -one, and ``unlisted_caps_suffixes`` an all-caps word: by default only -after a +one, and ``unlisted_caps_suffixes`` an all-caps word (and after a +comma, a mixed-case one such as ``MRes``): by default only after a comma behind a full name, and at the end of a name only on request, since an all-caps surname is written there. :ref:`unlisted-credentials` says where each applies and what it diff --git a/nameparser/_pipeline/_comma.py b/nameparser/_pipeline/_comma.py index 88818094a..19a25f5e9 100644 --- a/nameparser/_pipeline/_comma.py +++ b/nameparser/_pipeline/_comma.py @@ -750,13 +750,13 @@ def decide(state: ParseState, splits: bool | None = True) -> ParseState: or len(p) == 1 and (AMBIGUOUS_ACRONYM_TAG in (tags := tokens[p[0]].tags) or ("vocab:suffix" not in tags - # capitals, or the mixed case `is_mixed_caps_word` - # reads; `isupper()` kept as its own arm, a caps - # word holding a caseless letter ('XיZ') being - # title-shaped to `istitle()` + # capitals, or the mixed case `_mixed_capitals` + # reads, asked here in C by its two ends ('MRes', + # 'AuD'; not 'McDonald', which pays no count); + # `caps_shape_candidate` decides and ((texts[p[0]].isupper() - or not texts[p[0]].islower() - and not texts[p[0]].istitle()) + or texts[p[0]][:2].isupper() + or texts[p[0]][-1:].isupper()) and (texts[p[0]].isalpha() # the joined spelling ('PU-PH'), the # predicate's other half (rules/S9) @@ -801,9 +801,9 @@ def decide(state: ParseState, splits: bool | None = True) -> ParseState: initials_at = p[0] break contrast_box: list[bool] = [] - # the unlisted capitals words the run's company admitted, given the - # caps shape's marks below as the count's are ('Smith, M.B. ChB' - # keeps 'ChB' forced, rules/R4) + # the unlisted capitals words the run's company admitted, marked as + # caps-shape credentials below as the count's own are, so case + # repair keeps them ('Smith, M.B. ChB' keeps 'ChB' forced, rules/R4) company_caps: list[int] = [] if initials_at is not None: # titles in front of the run are the given part's (C16); @@ -1060,9 +1060,6 @@ def decide(state: ParseState, splits: bool | None = True) -> ParseState: and (text.isupper() and (text.isalpha() or "-" in text or "/" in text) - or not text.islower() - and not text.istitle() - and is_mixed_caps_word(text) or not unicodedata.is_normalized( "NFC", text) and is_caps_word(text))): caps.add(i) diff --git a/nameparser/_pipeline/_vocab.py b/nameparser/_pipeline/_vocab.py index 7e0c865d6..c05ac2539 100644 --- a/nameparser/_pipeline/_vocab.py +++ b/nameparser/_pipeline/_vocab.py @@ -2003,12 +2003,14 @@ class at all). # default-policy parse a frame it cannot use -- does not apply: the # trailing position is behind `CapsSuffixes.EVERYWHERE` (classify's # first conjunct), and the comma decision, which IS on by default, -# asks C-level `isalpha()`/`isupper()` and the suffix tag first, so a -# comma name with no unlisted all-caps word never reaches it. +# asks C-level `isalpha()`/`isupper()` (and, for the mixed-case arm, +# the case of the word's two ends) and the suffix tag first, so a comma +# name with no unlisted word in capitals or in that mixed case never +# reaches it. def caps_shape_candidate(text: str, lexicon: Lexicon, policy: Policy, one_case: bool | None, *, mixed_case: bool) -> bool: - """Whether TEXT is an UNLISTED all-caps credential candidate: two + """Whether TEXT is an UNLISTED caps-shape credential candidate: two or more alphabetic characters, or letter chunks joined by '-' or '/' (`_joined_capitals`, #752), no period (a period fails `isalpha()` and the joined pattern outright, which is what excludes @@ -2048,10 +2050,11 @@ def caps_shape_candidate(text: str, lexicon: Lexicon, policy: Policy, the call. `mixed_case` admits a mixed-case word as well (`_mixed_capitals`: - 'DClinPsy', 'AuD'), which only the part after a comma asks for - (rules/C6, decisions/C6 (#1516)); the trailing position under - `CapsSuffixes.EVERYWHERE` passes False, a surname typed without its - apostrophe ('ONeill', 'DSouza') ending a name there. + 'DClinPsy', 'AuD'): `_comma.decide` passes True for the part after + a comma (rules/C6, decisions/C6 (#1516)); classify passes False at + every slot it tags, `CapsSuffixes.EVERYWHERE`'s trailing positions + included, a surname typed without its apostrophe ('ONeill', + 'DSouza') ending a name there. """ if (policy.unlisted_caps_suffixes is CapsSuffixes.OFF or one_case is not False): @@ -2071,8 +2074,8 @@ def _mixed_capitals(text: str) -> bool: written neither in capitals nor the way a name is, so the caps shape reads it after a comma. A capital only inside the word ('LeBron', 'McKenzie') is a name's writing and stays out, and so - does a word holding anything but letters ('Pharm-D', the joined - arm having caught given names such as 'Jay-R'). TEXT is + does a word holding anything but letters ('Pharm-D': a mixed-case + joined arm would catch given names such as 'Jay-R'). TEXT is NFC-composed.""" return (len(text) >= 2 and text.isalpha() and not text.isupper() and (text[0].isupper() and text[1].isupper() diff --git a/nameparser/_policy.py b/nameparser/_policy.py index d01cebb76..f82a88cb5 100644 --- a/nameparser/_policy.py +++ b/nameparser/_policy.py @@ -932,7 +932,7 @@ class Policy: #: capitals or ends in one is read as an all-caps word is ("Jane #: Smith, MRes", "Jane Smith, AuD"), a capital only inside a word #: being a name's writing ("Jane Smith, LeBron" keeps given - #: ``LeBron``) and "García Márquez, MJ" keeps given ``MJ`` -- a lone + #: ``LeBron``). "García Márquez, MJ" keeps given ``MJ`` -- a lone #: two-letter word is how a person's initials are written, and two #: words before the comma may be one surname, the case #563 decides #: for "M.J." too. Credentials behind the two letters make them one: diff --git a/nameparser/_render.py b/nameparser/_render.py index acfc9fab2..ab4dd19c9 100644 --- a/nameparser/_render.py +++ b/nameparser/_render.py @@ -706,9 +706,10 @@ def _cap_word(word: str, role: Role, tags: frozenset[str], # rules/R4: "A word read as a credential after a comma by its # mixed case (C6) is kept as written, forced or not" -- the # caps shape's mark on a word in more than one case ('MRes', - # 'AuD'); decisions/C6 (#1516) + # 'AuD'; the dotted shape, S3, sets the same tag, hence the + # period test); decisions/C6 (#1516) if (SHAPE_ACRONYM_TAG in tags and "." not in word - and not word.isupper() and not word.islower()): + and not word.isupper()): return word return word.upper() # rules/R4: "A roman numeral the parse put in the suffix role is diff --git a/tests/v2/cases.py b/tests/v2/cases.py index ed664a408..01cb91608 100644 --- a/tests/v2/cases.py +++ b/tests/v2/cases.py @@ -7200,6 +7200,83 @@ def _check_cjk_shape_purity(self) -> None: ambiguities=("suffix-or-name",), notes="rules/C16's Except, as 'Smith, J.P. AUD' reads; 3.1 read " "given 'M.', middle 'B. ChB'"), + Case("a_mixed_case_credential_behind_a_generation", + "Jane Smith Jr., MRes", + {"given": "Jane", "family": "Smith", "suffix": "Jr., MRes"}, + classification="fix(#1516)", + ambiguities=("suffix-or-name",)), + Case("a_mixed_case_credential_behind_a_title_and_a_name", + "Dr. Jane Smith, MRes", + {"title": "Dr.", "given": "Jane", "family": "Smith", "suffix": "MRes"}, + classification="fix(#1516)", + ambiguities=("suffix-or-name",)), + Case("a_mixed_case_credential_behind_a_maiden_clause", + "Jane Smith née Brown, MRes", + {"given": "Jane", "family": "Smith", "maiden": "Brown", "suffix": "MRes"}, + classification="fix(#1516)", + ambiguities=("suffix-or-name",)), + Case("two_mixed_case_credentials_after_a_comma", + "Jane Smith, MRes AuD", + {"given": "Jane", "family": "Smith", "suffix": "MRes AuD"}, + classification="fix(#1516)", + ambiguities=("suffix-or-name",)), + Case("a_lowercase_first_word_ending_in_a_capital_is_the_shape", + "Jane Smith, iOS", + {"given": "Jane", "family": "Smith", "suffix": "iOS"}, + classification="fix(#1516)", + ambiguities=("suffix-or-name",), + notes="rules/S9's spelling reads the word's ends: 'tDPT' and 'qMD' are typed so"), + Case("a_word_opening_with_two_capitals_and_a_plural_is_the_shape", + "Jane Smith, LLMs", + {"given": "Jane", "family": "Smith", "suffix": "LLMs"}, + classification="fix(#1516)", + ambiguities=("suffix-or-name",)), + Case("a_lowercase_first_word_with_one_capital_inside_stays_a_name", + "Jane Smith, mRes", + {"given": "mRes", "family": "Jane Smith"}), + Case("a_title_case_spelling_of_a_credential_stays_a_name", + "Jane Smith, Mres", + {"given": "Mres", "family": "Jane Smith"}), + Case("an_apostrophe_less_given_name_after_a_comma_is_read_as_the_shape", + "Alex Lee, ONeill", + {"given": "Alex", "family": "Lee", "suffix": "ONeill"}, + classification="fix(#1516)", + ambiguities=("suffix-or-name",), + notes="accepted in rules/C6, as 'Alex Lee, ONEILL' reads"), + Case("a_mixed_case_word_ending_the_given_part_stays_a_middle_name", + "Smith, Jane MRes", + {"given": "Jane", "middle": "MRes", "family": "Smith"}), + Case("a_mixed_case_word_after_an_empty_head_is_the_given_name", + ", MRes", + {"given": "MRes"}), + Case("a_name_word_behind_a_mixed_case_word_keeps_the_listing", + "Jane Smith, MRes Jones", + {"given": "MRes", "middle": "Jones", "family": "Jane Smith"}), + Case("a_name_written_mixed_case_is_no_company_for_initials", + "Smith, J.P. LeBron", + {"given": "J.", "middle": "P. LeBron", "family": "Smith"}, + classification="fix(#1238)", + ambiguities=("suffix-or-name",), + notes="1.4.0 read first 'J.P.', middle 'LeBron'; rules/C16 parts " + "the run (T7)"), + Case("mixed_case_chunks_joined_by_a_slash_stay_a_name", + "Jane Smith, MRes/AuD", + {"given": "MRes/AuD", "family": "Jane Smith"}), + Case("a_de_name_with_a_capital_inside_stays_a_name", + "Jane Smith, DeShawn", + {"given": "DeShawn", "family": "Jane Smith"}), + Case("a_mixed_case_credential_under_a_family_first_order", + "Jane Smith, MRes", + {"given": "Smith", "family": "Jane", "suffix": "MRes"}, + policy=Policy(name_order=FAMILY_FIRST), + classification="fix(#1516)", + ambiguities=("suffix-or-name",)), + Case("a_decomposed_mixed_case_surname_ending_a_name_stays_the_family", + "Alex Lee DSouza\u0301", + {"given": "Alex", "middle": "Lee", "family": "DSouza\u0301"}, + policy=Policy(unlisted_caps_suffixes=CapsSuffixes.EVERYWHERE), + notes="classify's trailing tag passes mixed_case=False: only a " + "decomposed word reaches it there (#1516's test review)"), Case("an_apostrophe_less_surname_ending_a_name_stays_the_family", "Alex Lee ONeill", {"given": "Alex", "middle": "Lee", "family": "ONeill"}, diff --git a/tests/v2/test_cases.py b/tests/v2/test_cases.py index 7cb5b3dac..c9cc84c8a 100644 --- a/tests/v2/test_cases.py +++ b/tests/v2/test_cases.py @@ -527,9 +527,11 @@ def test_the_field_sweep_sees_the_claims_it_checks() -> None: # its review's 'PETR JAN DIS' under three orders; 2275 -> 2278 the # same day, its second review's 'Jan DIS' under three orders; 2278 # -> 2296 on 2026-11-21, #1516's six caps-shape rows reporting - # suffix-or-name under three orders. - assert claims == 2296, ( - f"the field sweep checks {claims} claims, recorded as 2296 on " + # suffix-or-name under three orders; 2296 -> 2321 the same day, its + # test review's eight rows under three orders and its family-first + # row under its declared policy. + assert claims == 2321, ( + f"the field sweep checks {claims} claims, recorded as 2321 on " f"2026-11-21") @@ -1030,8 +1032,9 @@ def test_the_alternative_sweep_sees_the_fields_it_checks() -> None: # three DiS rows after a comma under three orders; 629 -> 632 the same # day, its review's 'PETR JAN DIS' under three orders; 632 -> 647 on # 2026-11-21, #1516's five caps-shape rows under three orders, - # 'Smith, M.B. ChB' being a stand-in reread - assert (checked, skipped) == (647, 512), (checked, skipped) + # 'Smith, M.B. ChB' being a stand-in reread; 647 -> 669 the same + # day, its test review's rows + assert (checked, skipped) == (669, 512), (checked, skipped) def test_every_case_name_is_unique() -> None: diff --git a/tools/differential/corpus_rules.jsonl b/tools/differential/corpus_rules.jsonl index 710e879a3..b8e4bd7fc 100644 --- a/tools/differential/corpus_rules.jsonl +++ b/tools/differential/corpus_rules.jsonl @@ -450,6 +450,8 @@ "García Juan Carlos" "García López, Ana" "García López, Ana María" +"García López, DANDRE" +"García López, DAndre" "García Márquez Ana María" "García Márquez Gabriel" "García Márquez López, Juan" @@ -739,8 +741,10 @@ "Jane Smith née V" "Jane Smith, AuD" "Jane Smith, Dr / PhD" +"Jane Smith, EdD MRes" "Jane Smith, LeBron" "Jane Smith, MRes" +"Jane Smith, PhD, MRes" "Jane Smith, PhD/NP-C" "Jane Smith, PhDc" "Jane Smith, Pharm-D" @@ -764,6 +768,8 @@ "Jansen, Ir. J.P." "Jansen, Ir. J.P. van" "Jansen, J.P." +"Jansen, J.P. IJsbrand" +"Jansen, J.P. Ijsbrand" "Jansen, J.P., M.D." "Jansen, j.p." "Jean 'JD' Smith" @@ -1074,6 +1080,7 @@ "John Smith, MS-OMPT" "John Smith, MS-V" "John Smith, Ma" +"John Smith, McDONALD" "John Smith, Md-Rn" "John Smith, Mr." "John Smith, Mr. Jr." diff --git a/tools/differential/snapshot.jsonl b/tools/differential/snapshot.jsonl index 18696aa1b..59c2abdb1 100644 --- a/tools/differential/snapshot.jsonl +++ b/tools/differential/snapshot.jsonl @@ -1335,6 +1335,8 @@ {"name": "García Juan Carlos", "given": "García", "middle": "Juan", "family": "Carlos", "initials": "G. J. C."} {"name": "García López, Ana", "given": "Ana", "family": "García López", "initials": "A. G. L."} {"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 López, DANDRE", "given": "García", "family": "López", "suffix": "DANDRE", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: name as given (position)"], "initials": "G. L."} +{"name": "García López, DAndre", "given": "García", "family": "López", "suffix": "DAndre", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: name as given (position)"], "initials": "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."} @@ -1947,8 +1949,10 @@ {"name": "Jane Smith née V", "given": "Jane", "family": "Smith", "maiden": "V", "initials": "J. S."} {"name": "Jane Smith, AuD", "given": "Jane", "family": "Smith", "suffix": "AuD", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: name as given (position)"], "initials": "J. S."} {"name": "Jane Smith, Dr / PhD", "title": "Dr", "given": "Jane", "family": "Smith", "suffix": "PhD", "initials": "J. S."} +{"name": "Jane Smith, EdD MRes", "given": "Jane", "family": "Smith", "suffix": "EdD MRes", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: name as given (position)"], "initials": "J. S.", "capitalized_force": "Jane Smith, EDD MRes"} {"name": "Jane Smith, LeBron", "given": "LeBron", "family": "Jane Smith", "initials": "L. J. S.", "capitalized_force": "Lebron Jane Smith"} {"name": "Jane Smith, MRes", "given": "Jane", "family": "Smith", "suffix": "MRes", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: name as given (position)"], "initials": "J. S."} +{"name": "Jane Smith, PhD, MRes", "given": "Jane", "family": "Smith", "suffix": "PhD, MRes", "ambiguities": ["COMMA_STRUCTURE"], "initials": "J. S.", "capitalized_force": "Jane Smith, PhD, Mres"} {"name": "Jane Smith, PhD/NP-C", "given": "Jane", "family": "Smith", "suffix": "PhD/NP-C", "initials": "J. S."} {"name": "Jane Smith, PhDc", "given": "PhDc", "family": "Jane Smith", "initials": "P. J. S.", "capitalized_force": "Phdc Jane Smith"} {"name": "Jane Smith, Pharm-D", "given": "Pharm-D", "family": "Jane Smith", "initials": "P. J. S."} @@ -1976,6 +1980,8 @@ {"name": "Jansen, Ir. J.P.", "title": "Ir.", "given": "J.", "middle": "P.", "family": "Jansen", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: credential as suffix (vocabulary)"], "initials": "J. P. J."} {"name": "Jansen, Ir. J.P. van", "title": "Ir.", "given": "J.", "middle": "P.", "family": "van Jansen", "ambiguities": ["PARTICLE_OR_GIVEN", "SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: credential as suffix (vocabulary)", "PARTICLE_OR_GIVEN: name as middle (declared)"], "initials": "J. P. J."} {"name": "Jansen, J.P.", "given": "J.", "middle": "P.", "family": "Jansen", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: credential as suffix (vocabulary)"], "initials": "J. P. J."} +{"name": "Jansen, J.P. IJsbrand", "family": "Jansen", "suffix": "J.P. IJsbrand", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: name as given (position)"], "initials": "J."} +{"name": "Jansen, J.P. Ijsbrand", "given": "J.", "middle": "P. Ijsbrand", "family": "Jansen", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: credential as suffix (vocabulary)"], "initials": "J. P. I. J."} {"name": "Jansen, J.P., M.D.", "given": "J.", "middle": "P.", "family": "Jansen", "suffix": "M.D.", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: credential as suffix (vocabulary)"], "initials": "J. P. J."} {"name": "Jansen, j.p.", "family": "Jansen", "suffix": "j.p.", "initials": "J.", "capitalized_force": "Jansen, J.P."} {"name": "Jardin, Aldephonse Alexandre Félix du", "given": "Aldephonse", "middle": "Alexandre Félix", "family": "du Jardin", "ambiguities": ["PARTICLE_OR_GIVEN"], "alternatives": ["PARTICLE_OR_GIVEN: name as middle (declared)"], "initials": "A. A. F. J."} @@ -2415,6 +2421,7 @@ {"name": "John Smith, MS-OMPT", "given": "John", "family": "Smith", "suffix": "MS-OMPT", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: name as given (position)"], "initials": "J. S."} {"name": "John Smith, MS-V", "given": "John", "family": "Smith", "suffix": "MS-V", "initials": "J. S."} {"name": "John Smith, Ma", "given": "John", "family": "Smith", "suffix": "Ma", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: name as given (declared)"], "initials": "J. S.", "capitalized_force": "John Smith, MA"} +{"name": "John Smith, McDONALD", "given": "John", "family": "Smith", "suffix": "McDONALD", "ambiguities": ["SUFFIX_OR_NAME"], "alternatives": ["SUFFIX_OR_NAME: name as given (position)"], "initials": "J. S."} {"name": "John Smith, Md-Rn", "given": "Md-Rn", "family": "John Smith", "initials": "M. J. S."} {"name": "John Smith, Mr.", "title": "Mr.", "given": "John", "family": "Smith", "initials": "J. S."} {"name": "John Smith, Mr. Jr.", "title": "Mr.", "given": "John", "family": "Smith", "suffix": "Jr.", "initials": "J. S.", "generation": "Jr."} From afc865667e2d4dc30d13223a4e951857cfcfed74 Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Sat, 21 Nov 2026 15:36:09 -0800 Subject: [PATCH 4/5] Number the change's references #1517, its pull request Co-Authored-By: Claude Opus 5.5 --- ...a-credential-after-one-word-and-a-comma.md | 4 +-- ...caps-word-needs-the-names-case-contrast.md | 6 ++-- .../R4-case-repair-reads-the-unjoined-mark.md | 2 +- ...-that-join-the-ambiguous-class-by-shape.md | 4 +-- docs/release_log.rst | 2 +- nameparser/AGENTS.md | 2 +- nameparser/_pipeline/_vocab.py | 2 +- nameparser/_render.py | 2 +- tests/v2/cases.py | 34 +++++++++---------- tests/v2/pipeline/test_vocab.py | 2 +- tests/v2/test_cases.py | 6 ++-- tests/v2/test_config_diff.py | 2 +- tests/v2/test_locales.py | 2 +- tests/v2/test_parser.py | 2 +- tests/v2/test_render.py | 2 +- 15 files changed, 37 insertions(+), 37 deletions(-) diff --git a/docs/design/decisions/C16-initials-spelling-a-credential-after-one-word-and-a-comma.md b/docs/design/decisions/C16-initials-spelling-a-credential-after-one-word-and-a-comma.md index 57381ae68..d69672aef 100644 --- a/docs/design/decisions/C16-initials-spelling-a-credential-after-one-word-and-a-comma.md +++ b/docs/design/decisions/C16-initials-spelling-a-credential-after-one-word-and-a-comma.md @@ -11,7 +11,7 @@ Open: none in this file. ## Log -- 2026-11-10 (Derek), #1238 (its acceptance of `Smith, M.B. ChB` as given 'M.' superseded by 2026-11-21 #1516) — INITIALS RUN TOGETHER BEHIND ONE WORD ARE THE GIVEN NAME WHATEVER THEY SPELL. `Jansen, J.P.` read suffix 'J.P.' and no given name, where `Jansen, J.Q.` read given 'J.', middle 'Q.' (rules/T7 parting it): a listed credential never reached C4's count, so the comma was a suffix comma before C5's exception was asked. Dutch lists write every name `Surname, Initials`, and a pair of initials spells a listed credential as often as letters fall together. The issue's three questions were decided on these measures, taken 2026-11-10 against master d4a8a884: +- 2026-11-10 (Derek), #1238 (its acceptance of `Smith, M.B. ChB` as given 'M.' superseded by 2026-11-21 #1517) — INITIALS RUN TOGETHER BEHIND ONE WORD ARE THE GIVEN NAME WHATEVER THEY SPELL. `Jansen, J.P.` read suffix 'J.P.' and no given name, where `Jansen, J.Q.` read given 'J.', middle 'Q.' (rules/T7 parting it): a listed credential never reached C4's count, so the comma was a suffix comma before C5's exception was asked. Dutch lists write every name `Surname, Initials`, and a pair of initials spells a listed credential as often as letters fall together. The issue's three questions were decided on these measures, taken 2026-11-10 against master d4a8a884: GAIN. The Tweede Kamer's open data (3,083 members, initials, particle, title and surname in separate boxes; `Persoon` from the OData feed, read 2026-11-08), composed as `Surname, Initials`: 82 of 1,236 members with dotted initials lost the given name on master, 1 on the branch (`de Roo van Alderwerelt, J.K.H`, three letters behind two name words, C5's Accepted case); `Surname, Initials particle` 23 of 305 → 0; `particle Surname, Initials` 24 of 305 → 1 (`de Nerée tot Babberich, F.J.F.M.`, the same case); `Surname, Title Initials` 41 of 461 → 13, each a degree in front of the initials (`Biekman, MSc A.N.`), which reads as the credential run. COST. `snapshot.py --local --base `: ClinicalTrials.gov officials move 11 of 352,104 distinct names, every one a lone surname before `M.D`/`M.D.`/`M.S` (`Ferguson, M.D.` → given 'M.', middle 'D.', reported); FEC's 2026 individual contributors move 160 of 1,893,964 names, of which 65 are lone runs spelling no common credential (`BATES, D.M.`, `OWENS, J.P.`), 26 `J.D.`, 6 `M.S.`, 2 `M.D.`, 5 another lone two-letter credential, 33 a credential then a name past a second comma (`ARENAS, M.D., MAGDALENA C.`, which read the name as a suffix on master and reads the credential as initials now, as its unlisted twin does), and 23 a run with more behind it (`CLAYTON, A.M. TONY`, `RINEHART, J.D. JR.`, `WRIGHT, M.S. III`); PSC individuals, UK Electoral Commission donors and TSE donors move none. The committed corpora move 2 names (`Andrews, M.D.`, `Smith, A.B.C.`). WHICH HEADS. Every comma head was declined: the 24 ClinicalTrials.gov officials with two words before the comma and a dotted credential (`Bin Zhang, M.D.`, `Le Shen, M.D., Ph.D.`) are all credentials, and would all have moved. One name word is C4's count, and one word as written too, since the count passes over a title word and reads a capitalized particle with its surname as one: the first build moved `Ashley Knight, M.S. BME` (family 'Ashley Knight') and `Bin Zhang, M.D.`, found by the ClinicalTrials.gov run and the grid. So a title word is a word here, and a particle is none only written in lower case before a word with a capital, the Dutch tussenvoegsel's writing (`de Waart, J.P.`); a lower-case particle before a word with no capital keeps the credential (`du juan, M.D.`), while a one-word head in lower case is one word (`smith, M.D.` → given 'M.'). The second review found the numeral strip dropping any word shaped like one (`Le Vi, M.D.`, `Dr. Vi, M.D.`) and a listed single letter (`Smith V, M.D.`, a whole name to C1): a numeral is passed over only in capitals, a suffix word only of two or more letters behind a word, and a title left alone is no surname (`Dr. VI, M.D.`). The code review found a lone capitalized particle (`Le, J.P.`, a Vietnamese surname) and a numeral of two or more letters ending the head (`Jansen VI, J.P.`, C3's count) kept out; both now read as one word. A suffix word is passed over only where it ends the head: one in front of a word is a word (`Dr.B. Akila., M.D`, found by the ClinicalTrials.gov run of that fix). @@ -21,4 +21,4 @@ Open: none in this file. WHERE IT SITS. The first draft amended rules/C5, and the design-docs review found it outside C5's When (two letters, unlisted) and its Signal, overriding C13 and contradicting C11 with neither saying so; it is rules/C16, with a precedence line in C8 and C13, a sentence in C11's first Then bullet, and a line in C1's map. HOW. `_comma.decide` gathers the first such run and passes it to `segment_suffix_reading`, which returns no reading where the run stands in the part's leading run of titles, so the part is the given part; the run is then tagged `initial`, as a run written apart is, so the given part's walk does not peel it as a trailing suffix behind a title, and the report is made there, where the decision was taken. ACCEPTED: `Smith, M.D.` reads given 'M.', middle 'D.', the credential named in the report, the 11 ClinicalTrials.gov names and FEC's handful of lone `M.D.`/`M.S.` the cost; 1.4.0 read all of these given 'J.P.' or 'M.D.' whole, 2.0.0 through 3.0.1 suffix (wheels, 2026-11-10). RECOMPUTE: the Tweede Kamer figures compose `Achternaam`, `Tussenvoegsel`, `Titels` and `Initialen` from the feed's `Persoon` entity in the four forms above and count the parses with an empty given name, in each tree; the local ones are `uv run python tools/differential/snapshot.py --local ctgov-officials --base ` and the same for `fec-individuals`, `psc-individuals`, `ukec-individuals` and `tse-donors`. -- 2026-11-21 #1516 — A MIXED-CASE CREDENTIAL BEHIND THE RUN IS ITS COMPANY. Decided 2026-11-21. `Smith, M.B. ChB` reads suffix 'M.B. ChB', reported, where the #1238 entry accepted given 'M.', middle 'B. ChB' (as 1.4.0 read given 'M.B.', middle 'ChB'), because the caps shape now reads a word in mixed case that opens with two capitals or ends in one after a comma (decisions/C6's 2026-11-21 #1516 entry), and an unlisted capitals word C6 admits behind the run is company, as `Smith, J.P. AUD` read already. A credential written in neither shape stays a name word behind the run (`Smith, M.D. PhDc`, `Smith, M.D. M. Sc.` → given 'M.'), as the rule's Accepted bullet now states. The cost: a given name written in the shape behind the run is company too, so `Jansen, J.P. IJsbrand` reads suffix 'J.P. IJsbrand' and no given name, where ad9d5d20 read given 'J.', as `Jansen, J.P. IJSBRAND` already read; accepted in the rule, a list writing initials and then such a name being rarer than the credentials written so behind initials. SUPERSEDES: the #1238 entry's acceptance of `Smith, M.B. ChB`. +- 2026-11-21 #1517 — A MIXED-CASE CREDENTIAL BEHIND THE RUN IS ITS COMPANY. Decided 2026-11-21. `Smith, M.B. ChB` reads suffix 'M.B. ChB', reported, where the #1238 entry accepted given 'M.', middle 'B. ChB' (as 1.4.0 read given 'M.B.', middle 'ChB'), because the caps shape now reads a word in mixed case that opens with two capitals or ends in one after a comma (decisions/C6's 2026-11-21 #1517 entry), and an unlisted capitals word C6 admits behind the run is company, as `Smith, J.P. AUD` read already. A credential written in neither shape stays a name word behind the run (`Smith, M.D. PhDc`, `Smith, M.D. M. Sc.` → given 'M.'), as the rule's Accepted bullet now states. The cost: a given name written in the shape behind the run is company too, so `Jansen, J.P. IJsbrand` reads suffix 'J.P. IJsbrand' and no given name, where ad9d5d20 read given 'J.', as `Jansen, J.P. IJSBRAND` already read; accepted in the rule, a list writing initials and then such a name being rarer than the credentials written so behind initials. SUPERSEDES: the #1238 entry's acceptance of `Smith, M.B. ChB`. diff --git a/docs/design/decisions/C6-unlisted-all-caps-word-needs-the-names-case-contrast.md b/docs/design/decisions/C6-unlisted-all-caps-word-needs-the-names-case-contrast.md index e0ad61d4a..68f1e6aa2 100644 --- a/docs/design/decisions/C6-unlisted-all-caps-word-needs-the-names-case-contrast.md +++ b/docs/design/decisions/C6-unlisted-all-caps-word-needs-the-names-case-contrast.md @@ -2,7 +2,7 @@ ## Standing -- After a comma, an unlisted word of letters in mixed case that opens with two capitals or ends in one is the caps shape as an all-caps word is, in C4's count, C6's contrast and C16's company (`Jane Smith, MRes` → suffix 'MRes'); a capital only inside the word, or a hyphen or slash in it, keeps it a name word (`Jane Smith, LeBron`, `Jane Smith, Pharm-D` → given), and the trailing positions under `CapsSuffixes.EVERYWHERE` read capitals alone (`Alex Lee ONeill` → family 'ONeill') — 2026-11-21 #1516. +- After a comma, an unlisted word of letters in mixed case that opens with two capitals or ends in one is the caps shape as an all-caps word is, in C4's count, C6's contrast and C16's company (`Jane Smith, MRes` → suffix 'MRes'); a capital only inside the word, or a hyphen or slash in it, keeps it a name word (`Jane Smith, LeBron`, `Jane Smith, Pharm-D` → given), and the trailing positions under `CapsSuffixes.EVERYWHERE` read capitals alone (`Alex Lee ONeill` → family 'ONeill') — 2026-11-21 #1517. Elsewhere: this rule's decision, that an unlisted all-caps word after the comma joins the ambiguous credential class by default behind two name words, where the name carries a case contrast (`John Smith, XYZ` → suffix 'XYZ'; `Smith, XYZ` → given 'XYZ'; `MÜLLER WEIß, HANS` → given 'HANS'), with its two-letter rule (narrowed for two capitals followed by credentials by decisions/C5's 2026-11-11 #1323 entry, and for two capitals alone before a later part's listed credential by its 2026-11-15 #1392 entry) and the mixed-run membership — decisions/S9's 2026-10-01 (Derek), #564 entry, where the caps shape's switch is decided; the contrast test reused for a suffix word ending the name before the comma — decisions/C12's 2026-10-18 (Derek), #656 entry. @@ -12,11 +12,11 @@ Open: none in this file. - 2026-10-01 (Derek), #564 — AN UNLISTED ALL-CAPS WORD IS A CREDENTIAL IN THE PART AFTER A COMMA BEHIND TWO NAME WORDS, BY DEFAULT. The decision, its two-letter rule and the mixed-run membership are recorded under decisions/S9 (#564), where the caps shape's switch has always been decided; this bullet is C6's pointer to it. - 2026-10-18 #728 — SPLIT FROM decisions/C1 with the rule. The entries above were written under decisions/C1 while this rule was part of rules/C1, and moved here unchanged but for the pointers the move broke, the measurement paragraphs, each cut to one line naming its population, counts, baseline and PR, and the superseded passages, each cut to its decision and what replaced it; where one says rules/C1 or C1, it means the rule as it then stood, which held this one. -- 2026-11-21 #1516 — A WORD IN MIXED CASE WRITTEN THE WAY A CREDENTIAL IS JOINS THE CAPS SHAPE AFTER A COMMA. Decided 2026-11-21. An unlisted word of letters in mixed case that opens with two capitals or ends in one (`MRes`, `DClinPsy`, `AuD`, `BScN`) is the caps shape wherever an all-caps word is read after a comma: C4's count, C6's contrast and C16's company (`Jane Smith, MRes` → given 'Jane', family 'Smith', suffix 'MRes', reported, where 1.4.0 through 3.1.0 read given 'MRes', family 'Jane Smith'). Such a word is written neither in capitals nor the way a name is, and no vocabulary lists every degree written so. A capital only inside the word is a name's writing (`LeBron`, `McKenzie`, `DeShawn`), and a word in mixed case holding a hyphen or a slash is left out: a first build took joined chunks too, and given boxes are full of names joined so (`Cheng-I`, `I-Chun`, `Jay-R` in hundreds of ORCID given boxes, `Gul-E` and `Noor-E` in PSC's), so `Pharm-D` stays the given name, as does `PhDc`, whose ends hold one capital. +- 2026-11-21 #1517 — A WORD IN MIXED CASE WRITTEN THE WAY A CREDENTIAL IS JOINS THE CAPS SHAPE AFTER A COMMA. Decided 2026-11-21. An unlisted word of letters in mixed case that opens with two capitals or ends in one (`MRes`, `DClinPsy`, `AuD`, `BScN`) is the caps shape wherever an all-caps word is read after a comma: C4's count, C6's contrast and C16's company (`Jane Smith, MRes` → given 'Jane', family 'Smith', suffix 'MRes', reported, where 1.4.0 through 3.1.0 read given 'MRes', family 'Jane Smith'). Such a word is written neither in capitals nor the way a name is, and no vocabulary lists every degree written so. A capital only inside the word is a name's writing (`LeBron`, `McKenzie`, `DeShawn`), and a word in mixed case holding a hyphen or a slash is left out: a first build took joined chunks too, and given boxes are full of names joined so (`Cheng-I`, `I-Chun`, `Jay-R` in hundreds of ORCID given boxes, `Gul-E` and `Noor-E` in PSC's), so `Pharm-D` stays the given name, as does `PhDc`, whose ends hold one capital. GAIN. `snapshot.py --local --base `: ClinicalTrials.gov officials 915 moved of 539,368, 776 gaining the credential (`AuD`, `DClinPsy`, `DNSc`, `MBBChir`, `MRes`, `BMedSci` among the words taken, and `PhD` behind them), one reading `MDs` as the credential where it had read `Abd`, and 138 moving only the forced case view or a report's alternative; contacts 652 moved, 580 gaining the credential (`AuD`, `MEd`, `BScN`, `HBSc`) and 72 a case view or an alternative only; ORCID researchers 24 moved, all credentials (`CEng`, `PGDip`, `MAEd`), `local_agreement.py orcid-researchers --base` scoring 5 fixed, 0 broken, 2 changed (wrong either way); FEC, GOV.UK people, UK Electoral Commission donors, DOF signatures, PSC and PatentsView 0 moved, and PSC's and PatentsView's agreement unchanged. COST. One name of the moved reads wrong, a Catalan given name typed with a doubled capital (`LLuís`) behind a two-word head. Beyond the moved, the shape costs a given name written in it what the all-caps shape costs one written in capitals, in two forms. Behind two or more name words and a comma, the listing form reads it as the credential (`García Márquez, JOSE` and `García López, DAndre` → suffix), which reaches a given name typed without its apostrophe (`DAndre`, `ONeill`) and a surname in capitals behind a lowercase prefix (`McDONALD`, `DiCAPRIO`), each recorded as accepted in rules/C6; narrowing the spelling to spare the second would cost about 190 of the credentials the moved names gained (ClinicalTrials.gov officials 126, contacts 63, ORCID 1), which end in a run of capitals behind a lowercase letter too (`MScPT`, `PhDMD`, `MBBChBAO`). And behind one word, a run of initials spelling a listed credential takes such a name as company, so the list loses its given name (`Jansen, J.P. IJsbrand` → suffix 'J.P. IJsbrand'; rules/C16's Accepted bullet), where ad9d5d20 read given 'J.'. A given box holding a word of the shape, unlisted, in a record of mixed case, is in 577 of ORCID's 1,831,533 records (typos such as `MAria`, initials glued to a name, and real spellings, Dutch `IJsbrand` and Serbo-Croatian `LJiljana`), 55 PatentsView records and no PSC record; no fielded corpus composes either form, so the boxes bound the exposure rather than count it. WHY NOT EVERYWHERE'S TRAILING POSITIONS. Ending a name without a comma the shape is how a surname typed without its apostrophe is written (`ONeill`, `DSouza`, `OReilly`), and how `McCAFFREY` is: about 770 ORCID family boxes hold such a word alone, each of which would lose its family name in a name of three words under `CapsSuffixes.EVERYWHERE`. So the predicate takes the mixed-case arm only where the comma's decision asks (`caps_shape_candidate`'s `mixed_case`), and classify's trailing tag reads capitals alone (`Alex Lee ONeill` → family 'ONeill' under EVERYWHERE). CASE REPAIR (rules/R4). A shape word in mixed case is kept as written, forced or not, where the shape's mark would otherwise send it to the acronym clause's capitals (`MRES`; on ad9d5d20 the word was the given name, forced `Mres`); and the company a C16 run takes now carries the shape's marks the count gives, so `Smith, J.P. AUD` and `Ashley Knight, M.S. BME` keep their capitals forced, where master wrote `Aud` and `Bme`. - C16. `Smith, M.B. ChB` reads suffix 'M.B. ChB', as `Smith, J.P. AUD` already did; the reversal of that part of decisions/C16's 2026-11-10 #1238 entry is decisions/C16's 2026-11-21 #1516 entry. + C16. `Smith, M.B. ChB` reads suffix 'M.B. ChB', as `Smith, J.P. AUD` already did; the reversal of that part of decisions/C16's 2026-11-10 #1238 entry is decisions/C16's 2026-11-21 #1517 entry. THE FILTER'S OWN NARROWING. The comma's C-level filter first widened `isupper()` to `not islower() and not istitle()`, which drops a word of capitals split by a caseless letter (`istitle()` reads `XיZ` title-shaped): the corpus run found the one such word ctgov-contacts holds moved from the suffix to the given name, and the filter keeps `isupper()` as an arm of its own (case row `a_caps_word_holding_a_caseless_letter_stays_a_credential`). RECOMPUTE: the moves, `snapshot.py --local ctgov-officials --base ` and likewise `ctgov-contacts`, `orcid-researchers`, `fec-individuals`, `govuk-people`, `ukec-individuals`, `dof-signatures`, `psc-individuals`, `patentsview-inventors`; the box counts, over each fielded corpus's `raw.jsonl` in the tools cache (ORCID's and PatentsView's `given` box, PSC's `forename` and `middle_name`; for the 770, ORCID's `family` box holding the word alone), the words that this PR's `_vocab._mixed_capitals` admits once NFC-composed and `in_any_wordlist` refuses under the default lexicon, in records whose composed `name` is neither all upper nor all lower case, measured on 2026-11-21. diff --git a/docs/design/decisions/R4-case-repair-reads-the-unjoined-mark.md b/docs/design/decisions/R4-case-repair-reads-the-unjoined-mark.md index 278fba016..9b53b60b6 100644 --- a/docs/design/decisions/R4-case-repair-reads-the-unjoined-mark.md +++ b/docs/design/decisions/R4-case-repair-reads-the-unjoined-mark.md @@ -129,4 +129,4 @@ Accepted costs, deferred to the rescoped #459 rather than relitigated here: the - 2026-11-09 #1280 — AN ELIDED PARTICLE IN A HYPHENATED WORD KEEPS ITS LOWERCASE. #1224's hyphen clause wrote the first word of a hyphenated word's opening part with the particle arm left out, and the per-word walk splits `'s` at its apostrophe, so `WILLEM 'S-GRAVESANDE` repaired to "Willem 'S-Gravesande" and the lowercase `willem 's-gravesande` was made wrong the same way, as 3.0.1 did; spaced, the whole-token particle test already kept `'s Gravesande` lowercase. Dutch writes the elided articles `'s` (des) and `'t` (het) lowercase whether a space or a hyphen joins them (Wikidata labels: Arent van 's-Gravesande, G.H. 's-Gravesande; no committed corpus outside the rules' own example rows, and no local corpus, writes a hyphenated `'s-` or `'t-`, decisions/N2's 2026-11-09 entry; re-measured over the local corpora, 2026-11-09, the same detector finding 96 spaced `'t`; a hyphen before the particle, `-'s`, found in none). Decided by the word's form, not a new property: the particles whose listed spelling opens with an apostrophe are exactly `'s`, `'t` and their typographic twins (`Lexicon.default()._sets.particles`, 2026-11-09), so a part of a hyphenated word that is such a particle, asked whole by the particle arm, keeps its lowercase, and every other particle opening a hyphenated word keeps #1224's capital (`Ter-Petrosyan`). Any part, not the opening one only: the per-word walk splits the particle at its apostrophe in every part, and a plain particle after the first hyphen already keeps its lowercase (`JUAN GARCIA-DE-VEGA` → 'Juan Garcia-de-Vega'), so `Smit-'s-Gravesande` keeps it too; the first draft lowered the opening part alone, and review found forced repair still rewriting `Willem Smit-'s-Gravesande` to `'S-`. A hyphenated word of particles alone carries no unjoined mark, so rules/R4's all-particle Except does not reach it (`JAN 'S-VAN` → "Jan 's-van", as `MARIA VAN-DER` → 'Maria Van-der' under #1224). The particle arm's own limits stand: a given name opening `'s-` takes its capital (`'S-JACOB SMIT` → "'S-Jacob Smit"). Compared with the parent commit's snapshot, two committed entries move, both in the forced view: `Arent van 's-Gravesande`, which forced repair had rewritten to `'S-`, now comes back as written; and THE COST, `Aaron 'T-Bone Walker` (decisions/N2's `'T-Bone` row), whose middle word forced repair now writes "'t-Bone": a nickname spelled with the listed `'t` and a hyphen is read as that particle, nothing in a one-case `'T-BONE` telling it from `'T-HART`; written in mixed case it is left as written (rules/R5). Pinned by rules/R4's examples and test_an_elided_particle_in_a_hyphenated_word_keeps_its_lowercase. - 2026-11-12 #1256 — THE NO-CAPITAL SCRIPT IS READ FROM THE SCRIPT-PROPERTY TABLE. The 2026-11-08 #1223 test (a first letter whose single-letter lower case title-cases to itself) is replaced by the Georgian row of `_policy._SCRIPT_PROPERTIES`: a first letter in a row with no case is written in its lower case. Over every codepoint it changes the same 46 Mtavruli letters (decisions/script-properties). - 2026-11-12 #1222 (#1256) — DECIDED: A NAME MIXING MTAVRULI WITH MKHEDRULI IS WRITTEN IN MKHEDRULI. Georgian has no case, so its standard writing is Mkhedruli throughout, and a name holding Mtavruli beside Mkhedruli is one case to the contrast like any other caseless name (rules/R5's gate reads the script-property table's Georgian row, decisions/script-properties); `capitalized()` then writes it in Mkhedruli, as `capitalized(force=True)` already did since #1223. Two shapes move on the default path, each kept as written by 1.4.0 through 3.0.1 (run against the wheels from a scratch directory, 2026-11-12): a Mtavruli first letter on Mkhedruli in the Latin habit, `Უჩა გოგოლაძე` → 'უჩა გოგოლაძე' (4 of 5,242 Wikidata labels of Georgian citizens write one, per #1222, counted on 2026-11-07), and a Mtavruli surname beside a Mkhedruli given name, the capitals of emphasis, `ნინო ᲑᲣᲠᲯᲐᲜᲐᲫᲔ` → 'ნინო ბურჯანაძე'. The second differs from Latin, where `capitalized()` keeps a surname written in capitals in a name of mixed case (`Jean DUPONT`): Latin's capitals are case, a choice the writer makes against the rest of the name, while Mtavruli is a style of a caseless script, so the gate sees no contrast and the emphasis is not kept (rules/R5's Accepted bullet). #1223's test pinning the first shape as kept on the default path moved with this entry (tests/v2/test_render.py). -- 2026-11-21 #1516 — A CREDENTIAL READ BY ITS MIXED CASE IS KEPT AS WRITTEN, FORCED OR NOT, and the company of rules/C16's run carries the caps shape's marks (`Smith, J.P. AUD` and `Ashley Knight, M.S. BME` keep their capitals forced, where ad9d5d20 wrote `Aud` and `Bme`). The reason and the measurement are decisions/C6's 2026-11-21 #1516 entry, its CASE REPAIR paragraph; this bullet is R4's pointer to it. A word of that writing read as a credential past a second comma still repairs as any suffix (`Jane Smith, PhD, MRes` forced → `Mres`), as rules/R4 now states. +- 2026-11-21 #1517 — A CREDENTIAL READ BY ITS MIXED CASE IS KEPT AS WRITTEN, FORCED OR NOT, and the company of rules/C16's run carries the caps shape's marks (`Smith, J.P. AUD` and `Ashley Knight, M.S. BME` keep their capitals forced, where ad9d5d20 wrote `Aud` and `Bme`). The reason and the measurement are decisions/C6's 2026-11-21 #1517 entry, its CASE REPAIR paragraph; this bullet is R4's pointer to it. A word of that writing read as a credential past a second comma still repairs as any suffix (`Jane Smith, PhD, MRes` forced → `Mres`), as rules/R4 now states. diff --git a/docs/design/decisions/S9-unlisted-words-that-join-the-ambiguous-class-by-shape.md b/docs/design/decisions/S9-unlisted-words-that-join-the-ambiguous-class-by-shape.md index ff76c1081..4e3aafb54 100644 --- a/docs/design/decisions/S9-unlisted-words-that-join-the-ambiguous-class-by-shape.md +++ b/docs/design/decisions/S9-unlisted-words-that-join-the-ambiguous-class-by-shape.md @@ -19,7 +19,7 @@ Examples name each field as the default order reads it; under the family-first o Not standing: the split of 2026-10-17 #682, carried out. -Elsewhere: the caps shape's mixed-case spelling, read after a comma only (`Jane Smith, MRes` → suffix 'MRes'; under EVERYWHERE `Alex Lee ONeill` keeps family 'ONeill') — decisions/C6's 2026-11-21 #1516 entry. The wordlist roster the caps entry names, eleven of the thirteen vocabulary fields, corrected to all of them (a caller's surname keeps `Jean Pierre DUPONT` its family under EVERYWHERE) — decisions/S6's 2026-09-18, WHOLE-PR REVIEW ROUND entry; `De La Cruz, M.J. K.L.` → given names 'M.J. K.L.' behind a one-word particle surname (the middle since decisions/S3's 2026-10-24 #864 entry) — decisions/C3's 2026-10-01 (Derek), #575 entry; the three listed and dotted runs the caps entry kept apart (`John Smith, Ed Ma`, `John Smith, ma do`, `John Smith, X.Y.Z. A.B.`), credential runs by C4's count — decisions/S7's 2026-09-27 (Derek), #544 entry headed A CREDENTIAL RUN KEEPS ITS AMBIGUOUS MEMBERS; the contrast test reused for a suffix word ending the name before the comma — decisions/C12's 2026-10-18 (Derek), #656 entry. +Elsewhere: the caps shape's mixed-case spelling, read after a comma only (`Jane Smith, MRes` → suffix 'MRes'; under EVERYWHERE `Alex Lee ONeill` keeps family 'ONeill') — decisions/C6's 2026-11-21 #1517 entry. The wordlist roster the caps entry names, eleven of the thirteen vocabulary fields, corrected to all of them (a caller's surname keeps `Jean Pierre DUPONT` its family under EVERYWHERE) — decisions/S6's 2026-09-18, WHOLE-PR REVIEW ROUND entry; `De La Cruz, M.J. K.L.` → given names 'M.J. K.L.' behind a one-word particle surname (the middle since decisions/S3's 2026-10-24 #864 entry) — decisions/C3's 2026-10-01 (Derek), #575 entry; the three listed and dotted runs the caps entry kept apart (`John Smith, Ed Ma`, `John Smith, ma do`, `John Smith, X.Y.Z. A.B.`), credential runs by C4's count — decisions/S7's 2026-09-27 (Derek), #544 entry headed A CREDENTIAL RUN KEEPS ITS AMBIGUOUS MEMBERS; the contrast test reused for a suffix word ending the name before the comma — decisions/C12's 2026-10-18 (Derek), #656 entry. Open: none in this file. @@ -53,4 +53,4 @@ Open: none in this file. - 2026-10-25 #752 — THE CAPS SHAPE'S JOINED SPELLING (phase 2d, the unlisted half of item 5 of decisions/vocabulary-model's 2026-10-23 #752 entry, agreed by Derek on 2026-10-23; #797's half A). An unlisted word of capitals in letter chunks joined by `-` or `/`, one chunk of two or more letters, is the caps shape: `John Smith, PU-PH` reads suffix 'PU-PH' with the class's report where 1.4.0 through 2.6.0 read given 'PU-PH', family 'John Smith'. It joins the class exactly where and as the unjoined word does, so the C4 count and C6's case contrast gate it after a comma by default (`JOHN SMITH, PU-PH`, `Smith, PU-PH` → given) and EVERYWHERE takes it at every suffix position, its cost the unjoined word's (`Jean Pierre DUPONT-MORETTI` reads as `Jean Pierre DUPONT` does); keeping it to the comma under EVERYWHERE too was not built, since it would make one shape two by position. "Unlisted" is the whole word in no wordlist, as for the unjoined word; a word whose every chunk counts as a suffix as written is rules/S3's joined credential, read unambiguously before this shape is asked (`MD-PHD`), so the two overlap in no reading. Single-letter chunks alone are how initials are joined (`A-B`) and stay out, and a chunk holding a digit or a period is no letter chunk. REACHABILITY: the comma's candidate list, C12's case-repair marks and classify under EVERYWHERE each ask `isalpha()` and `isupper()` in C before calling the predicate, and the joined spelling fails `isalpha()`, so each pre-filter widened with it to a capitals word holding a joiner; the 2026-10-23 measurement's first run moved nothing for the same reason. MEASURED (2026-10-25, against the phase 2c commit 15d5426f, every local corpus recorded from it with `--tree`): `tools/differential/snapshot.py` moves nothing but the rules' own new examples; `cldr_agreement.py` matches every record; `local_agreement.py psc-individuals` matches its record; tse-donors and fec-individuals, none (FEC is written in one case, so the contrast never admits a word there); ctgov-officials, 529 of 352,104 entries. Of the 529, 519 are a joined capitals word after a comma, now the suffix with a suffix-or-name report (5 of them in a third part, where the comma-structure report stays): 516 had read it as the given name with the name reversed around it, and 3 had read a listed credential opening the part as the given name and the joined word as the middle (`John Smith, MSN ACNP-BC`), the whole part now the suffix. 10 move only in `capitalized(force=True)`, a joined capitals word already in a suffix run now keeping its capitals (rules/R4). The words are 104 distinct credentials and job titles, `PU-PH` (258) and `MCU-PH` (30), the French hospital-university ranks, and `MS-OMPT` (32) the commonest; none is a name. The 2026-10-23 figure, 759, was measured without phase 2c, which now reads about 230 of them as listed credentials. One of the 516 also takes a word before the comma into the suffix, as the unjoined twin reads: a capitals word between a listed credential and the comma (`Jean Claude MD DUPONT, PU-PH` → family 'Claude', suffix 'MD DUPONT, PU-PH', reported), where the part before the comma reads as the name without it (rules/C1) and `Jean Claude MD DUPONT` alone already gives suffix 'MD DUPONT' by rules/S8's run; ACCEPTED here, since it is S8's reading of a capitals surname behind a credential, the same with `XYZ` or `PhD` after the comma. COST: a capitals word holding a joiner pays the caps shape's path, as an unjoined capitals word already does (`SMITH-JONES, MARY-JANE` 175 → 189 profiler frames, py3.11), and a word with a lowercase letter or no joiner pays nothing new (`Mary Smith-Jones` 159, `John Smith, XYZ` 264, before and after). Pinned by the #752 rows of tests/v2/cases.py and `test_caps_shape_candidate_reads_joined_capitals` (tests/v2/pipeline/test_vocab.py). - 2026-10-28 #357 — NO V1 CALLER IS LEFT FOR THE SWITCHES TO MISS (decisions/3-0-reevaluations' 2026-10-28 #357, REMOVAL entry): the 2026-09-14 and 2026-10-01 #564 entries recorded that the shim translated neither switch, so `HumanName` followed both defaults; with the facade removed, every caller reaches both through `Policy`. SUPERSEDES: the v1-shim consequence the 2026-09-14 (Derek), corrected 2026-09-18 and 2026-10-01 (Derek), #564 entries recorded. - 2026-11-11 #1323 — THE UNDOTTED PAIR BEFORE CREDENTIALS IS THE CREDENTIAL RUN, behind two or more name words carrying the contrast. SUPERSEDES, for that one shape, the 2026-10-01 (Derek), #564 entry's '(3)' reading of a two-letter word inside a longer part 'exactly as #563 reads the dotted pair': `Jane Doe, BM PhD` → suffix 'BM PhD', where `John Smith, A.B. Ph.D.` keeps given names 'A.B.'. The measurement and what moved are decisions/C5's 2026-11-11 #1323 entry; a lone two-letter word is still never admitted at the comma. -- 2026-11-21 #1516 — THE CAPS SHAPE READS A WORD IN MIXED CASE AFTER A COMMA, AND NOWHERE ELSE. The decision and its measurement are decisions/C6's 2026-11-21 #1516 entry; this bullet is S9's pointer to it, the trailing positions of `CapsSuffixes.EVERYWHERE` being this rule's. +- 2026-11-21 #1517 — THE CAPS SHAPE READS A WORD IN MIXED CASE AFTER A COMMA, AND NOWHERE ELSE. The decision and its measurement are decisions/C6's 2026-11-21 #1517 entry; this bullet is S9's pointer to it, the trailing positions of `CapsSuffixes.EVERYWHERE` being this rule's. diff --git a/docs/release_log.rst b/docs/release_log.rst index 3e79e8ef3..c2d03624e 100644 --- a/docs/release_log.rst +++ b/docs/release_log.rst @@ -4,7 +4,7 @@ Release Log nameparser 3.2 is under development. - - **Read an unlisted credential written in mixed case after a full name and a comma, such as MRes or AuD.** ``parse("Jane Smith, MRes")`` gives suffix ``MRes``, where 1.4.0 through 3.1.0 gave given ``MRes``, family ``Jane Smith``; the word must open with two capitals or end in one, so ``LeBron`` and ``PhDc`` stay given names, while a given name written so after a two-word surname reads as the credential (``García López, DAndre``). Behind one word it stays the given name (``Smith, MRes``), save behind initials spelling a credential, which read as the credential with it (``Smith, M.B. ChB``, and ``Jansen, J.P. IJsbrand``, which loses its given name). The positions only ``CapsSuffixes.EVERYWHERE`` reads still take words in capitals alone (``Alex Lee ONeill`` keeps family ``ONeill``). :issue:`1516` + - **Read an unlisted credential written in mixed case after a full name and a comma, such as MRes or AuD.** ``parse("Jane Smith, MRes")`` gives suffix ``MRes``, where 1.4.0 through 3.1.0 gave given ``MRes``, family ``Jane Smith``; the word must open with two capitals or end in one, so ``LeBron`` and ``PhDc`` stay given names, while a given name written so after a two-word surname reads as the credential (``García López, DAndre``). Behind one word it stays the given name (``Smith, MRes``), save behind initials spelling a credential, which read as the credential with it (``Smith, M.B. ChB``, and ``Jansen, J.P. IJsbrand``, which loses its given name). The positions only ``CapsSuffixes.EVERYWHERE`` reads still take words in capitals alone (``Alex Lee ONeill`` keeps family ``ONeill``). :issue:`1517` - **Add French dit and dite as connectives under a French choice.** With ``languages=frozenset({"fr"})`` chosen, ``Jean Dupont dit Lebrun`` gives family ``Dupont dit Lebrun``, where the default, as 1.4.0 through 3.1.0, gives middle ``Dupont dit``, family ``Lebrun``; a West African alias joins the given name the same way (``Mamadou dit Madou``), and the default is unchanged, ``Dit`` and ``Dite`` being names too. :issue:`1159` - **Add Brazilian Portuguese familiar forms, found in the names Brazil's election candidates put on the ballot.** With ``familiar-form`` accepted, ``Tião Alves`` / ``Sebastião Alves`` and ``Cida Silva`` / ``Aparecida Silva`` are consistent, where 3.1.0 read a conflict. They are filed under ``pt-BR``, so a strict choice of another language leaves them out, and one name spelled two ways (``Elizangela`` / ``Elisangela``) is not among them. :issue:`1495` - **Add the Czech and Slovak post-nominals DiS., DrSc. and ArtD. as credentials.** ``parse("Jan Novák, DiS.")`` gives suffix ``DiS.``, where 1.4.0 through 3.1.0 gave title ``DiS.``; DiS., which is also a surname, reads as the credential after a full name and a comma, and written as ``DiS.`` or ``Dis`` it stays a name word at the end of a name of mixed case without one (``Jan Novák DiS.``), while a surname written ``DIS`` there reads as the credential (``Jan DIS``). :issue:`969` diff --git a/nameparser/AGENTS.md b/nameparser/AGENTS.md index ef7ff06bf..e0057c3bb 100644 --- a/nameparser/AGENTS.md +++ b/nameparser/AGENTS.md @@ -76,7 +76,7 @@ Capitals between two name words have the same second reading: some writers put t ### A word written in capitals -A rule that reads a word's capitals meets spellings the plain `isupper()` misjudges both ways, and a gate measured before #659's rule (rules/O9) found each in real data on 2026-11-12: a title or a placeholder written in capitals (`DR.` opening 192 given boxes of the 2025-10 ORCID dump, `N/A` in every one of `psc-individuals`' 128 such names), which a full stop or a slash rules out; a surname written in capitals behind a lowercase prefix (`McDONALD`, `d'ESTAING`), which `isupper()` refuses; and a name whose only lowercase letters stand in a title or a particle (`Dr. ANITA ROY`, `MARIA de SOUZA LIMA`), which a whole-name case test calls mixed. Put each in the grid, with a lowercase and a Title-case twin of every example (the twins must not move), and the NFD spelling. And a filter written as "neither lower nor title case" is not a wider `isupper()`: `istitle()` passes over a caseless letter, so a word of capitals split by one (`XיZ`) is title-shaped to it, and #1516's first build, widening the comma's `isupper()` filter to `not islower() and not istitle()` for mixed-case credentials, dropped the one such word ctgov-contacts holds from the suffix; keep `isupper()` as its own arm when widening a case filter, and put a caps word with a caseless letter in the grid. +A rule that reads a word's capitals meets spellings the plain `isupper()` misjudges both ways, and a gate measured before #659's rule (rules/O9) found each in real data on 2026-11-12: a title or a placeholder written in capitals (`DR.` opening 192 given boxes of the 2025-10 ORCID dump, `N/A` in every one of `psc-individuals`' 128 such names), which a full stop or a slash rules out; a surname written in capitals behind a lowercase prefix (`McDONALD`, `d'ESTAING`), which `isupper()` refuses; and a name whose only lowercase letters stand in a title or a particle (`Dr. ANITA ROY`, `MARIA de SOUZA LIMA`), which a whole-name case test calls mixed. Put each in the grid, with a lowercase and a Title-case twin of every example (the twins must not move), and the NFD spelling. And a filter written as "neither lower nor title case" is not a wider `isupper()`: `istitle()` passes over a caseless letter, so a word of capitals split by one (`XיZ`) is title-shaped to it, and #1517's first build, widening the comma's `isupper()` filter to `not islower() and not istitle()` for mixed-case credentials, dropped the one such word ctgov-contacts holds from the suffix; keep `isupper()` as its own arm when widening a case filter, and put a caps word with a caseless letter in the grid. ### Adjacent pairs of words diff --git a/nameparser/_pipeline/_vocab.py b/nameparser/_pipeline/_vocab.py index c05ac2539..9aeab0ba4 100644 --- a/nameparser/_pipeline/_vocab.py +++ b/nameparser/_pipeline/_vocab.py @@ -2051,7 +2051,7 @@ def caps_shape_candidate(text: str, lexicon: Lexicon, policy: Policy, `mixed_case` admits a mixed-case word as well (`_mixed_capitals`: 'DClinPsy', 'AuD'): `_comma.decide` passes True for the part after - a comma (rules/C6, decisions/C6 (#1516)); classify passes False at + a comma (rules/C6, decisions/C6 (#1517)); classify passes False at every slot it tags, `CapsSuffixes.EVERYWHERE`'s trailing positions included, a surname typed without its apostrophe ('ONeill', 'DSouza') ending a name there. diff --git a/nameparser/_render.py b/nameparser/_render.py index ab4dd19c9..a426b8977 100644 --- a/nameparser/_render.py +++ b/nameparser/_render.py @@ -707,7 +707,7 @@ def _cap_word(word: str, role: Role, tags: frozenset[str], # mixed case (C6) is kept as written, forced or not" -- the # caps shape's mark on a word in more than one case ('MRes', # 'AuD'; the dotted shape, S3, sets the same tag, hence the - # period test); decisions/C6 (#1516) + # period test); decisions/C6 (#1517) if (SHAPE_ACRONYM_TAG in tags and "." not in word and not word.isupper()): return word diff --git a/tests/v2/cases.py b/tests/v2/cases.py index 01cb91608..f3cb651bd 100644 --- a/tests/v2/cases.py +++ b/tests/v2/cases.py @@ -7120,41 +7120,41 @@ def _check_cjk_shape_purity(self) -> None: "capitals after a comma behind a full name, so the " "default reads the comma position (rules/C6, S9). " "2.3.0 read given 'XYZ', family 'John Smith'"), - # #1516: a word in mixed case written as a credential is -- opening + # #1517: a word in mixed case written as a credential is -- opening # with two capitals or ending in one -- is the caps shape after a # comma (rules/C6); the words the narrower all-caps test refused # that stay names keep a row each below. Case("a_mixed_case_word_opening_with_two_capitals_is_a_credential", "Jane Smith, MRes", {"given": "Jane", "family": "Smith", "suffix": "MRes"}, - classification="fix(#1516)", + classification="fix(#1517)", ambiguities=("suffix-or-name",), notes="rules/C6's mixed-case bullet; 3.1 read given 'MRes', " "family 'Jane Smith'"), Case("a_mixed_case_word_ending_in_a_capital_is_a_credential", "Jane Smith, AuD", {"given": "Jane", "family": "Smith", "suffix": "AuD"}, - classification="fix(#1516)", + classification="fix(#1517)", ambiguities=("suffix-or-name",), notes="rules/C6; 3.1 read given 'AuD', family 'Jane Smith'"), Case("a_decomposed_mixed_case_credential_is_read_composed", "Jane Smith, MRE\u0301s", {"given": "Jane", "family": "Smith", "suffix": "MRE\u0301s"}, - classification="fix(#1516)", + classification="fix(#1517)", ambiguities=("suffix-or-name",), notes="the accent typed as a combining mark (#652): the comma's " "C-level filter asks the composed word"), Case("a_mixed_case_credential_beside_a_listed_one", "Jane Smith, MRes PhD", {"given": "Jane", "family": "Smith", "suffix": "MRes PhD"}, - classification="fix(#1516)", + classification="fix(#1517)", ambiguities=("suffix-or-name",)), Case("a_caps_word_holding_a_caseless_letter_stays_a_credential", "John Smith, X\u05d9Z", {"given": "John", "family": "Smith", "suffix": "X\u05d9Z"}, classification="fix(#564)", ambiguities=("suffix-or-name",), - notes="#1516's guard: `istitle()` holds a word of capitals " + notes="#1517's guard: `istitle()` holds a word of capitals " "split by a caseless letter title-shaped, so the comma's " "widened filter keeps `isupper()` as an arm of its own; " "its first build read given here"), @@ -7196,40 +7196,40 @@ def _check_cjk_shape_purity(self) -> None: Case("a_mixed_case_credential_is_company_for_initials_spelling_one", "Smith, M.B. ChB", {"family": "Smith", "suffix": "M.B. ChB"}, - classification="fix(#1516)", + classification="fix(#1517)", ambiguities=("suffix-or-name",), notes="rules/C16's Except, as 'Smith, J.P. AUD' reads; 3.1 read " "given 'M.', middle 'B. ChB'"), Case("a_mixed_case_credential_behind_a_generation", "Jane Smith Jr., MRes", {"given": "Jane", "family": "Smith", "suffix": "Jr., MRes"}, - classification="fix(#1516)", + classification="fix(#1517)", ambiguities=("suffix-or-name",)), Case("a_mixed_case_credential_behind_a_title_and_a_name", "Dr. Jane Smith, MRes", {"title": "Dr.", "given": "Jane", "family": "Smith", "suffix": "MRes"}, - classification="fix(#1516)", + classification="fix(#1517)", ambiguities=("suffix-or-name",)), Case("a_mixed_case_credential_behind_a_maiden_clause", "Jane Smith née Brown, MRes", {"given": "Jane", "family": "Smith", "maiden": "Brown", "suffix": "MRes"}, - classification="fix(#1516)", + classification="fix(#1517)", ambiguities=("suffix-or-name",)), Case("two_mixed_case_credentials_after_a_comma", "Jane Smith, MRes AuD", {"given": "Jane", "family": "Smith", "suffix": "MRes AuD"}, - classification="fix(#1516)", + classification="fix(#1517)", ambiguities=("suffix-or-name",)), Case("a_lowercase_first_word_ending_in_a_capital_is_the_shape", "Jane Smith, iOS", {"given": "Jane", "family": "Smith", "suffix": "iOS"}, - classification="fix(#1516)", + classification="fix(#1517)", ambiguities=("suffix-or-name",), notes="rules/S9's spelling reads the word's ends: 'tDPT' and 'qMD' are typed so"), Case("a_word_opening_with_two_capitals_and_a_plural_is_the_shape", "Jane Smith, LLMs", {"given": "Jane", "family": "Smith", "suffix": "LLMs"}, - classification="fix(#1516)", + classification="fix(#1517)", ambiguities=("suffix-or-name",)), Case("a_lowercase_first_word_with_one_capital_inside_stays_a_name", "Jane Smith, mRes", @@ -7240,7 +7240,7 @@ def _check_cjk_shape_purity(self) -> None: Case("an_apostrophe_less_given_name_after_a_comma_is_read_as_the_shape", "Alex Lee, ONeill", {"given": "Alex", "family": "Lee", "suffix": "ONeill"}, - classification="fix(#1516)", + classification="fix(#1517)", ambiguities=("suffix-or-name",), notes="accepted in rules/C6, as 'Alex Lee, ONEILL' reads"), Case("a_mixed_case_word_ending_the_given_part_stays_a_middle_name", @@ -7269,21 +7269,21 @@ def _check_cjk_shape_purity(self) -> None: "Jane Smith, MRes", {"given": "Smith", "family": "Jane", "suffix": "MRes"}, policy=Policy(name_order=FAMILY_FIRST), - classification="fix(#1516)", + classification="fix(#1517)", ambiguities=("suffix-or-name",)), Case("a_decomposed_mixed_case_surname_ending_a_name_stays_the_family", "Alex Lee DSouza\u0301", {"given": "Alex", "middle": "Lee", "family": "DSouza\u0301"}, policy=Policy(unlisted_caps_suffixes=CapsSuffixes.EVERYWHERE), notes="classify's trailing tag passes mixed_case=False: only a " - "decomposed word reaches it there (#1516's test review)"), + "decomposed word reaches it there (#1517's test review)"), Case("an_apostrophe_less_surname_ending_a_name_stays_the_family", "Alex Lee ONeill", {"given": "Alex", "middle": "Lee", "family": "ONeill"}, policy=Policy(unlisted_caps_suffixes=CapsSuffixes.EVERYWHERE), notes="the mixed-case shape is read after a comma only " "(rules/S9), so EVERYWHERE's trailing position reads capitals " - "alone (#1516)"), + "alone (#1517)"), Case("a_d_surname_without_its_apostrophe_stays_the_family", "Alex Lee DSouza", {"given": "Alex", "middle": "Lee", "family": "DSouza"}, diff --git a/tests/v2/pipeline/test_vocab.py b/tests/v2/pipeline/test_vocab.py index e4244119e..ba5e1d5a4 100644 --- a/tests/v2/pipeline/test_vocab.py +++ b/tests/v2/pipeline/test_vocab.py @@ -602,7 +602,7 @@ def test_caps_shape_candidate_reads_joined_capitals( ]) def test_caps_shape_candidate_reads_mixed_case_only_where_asked( text: str, expected: bool) -> None: - # #1516: the mixed-case arm, which only the part after a comma asks + # #1517: the mixed-case arm, which only the part after a comma asks # for; the trailing position under EVERYWHERE never does lex = Lexicon.default() pol = Policy() diff --git a/tests/v2/test_cases.py b/tests/v2/test_cases.py index c9cc84c8a..a17039b0b 100644 --- a/tests/v2/test_cases.py +++ b/tests/v2/test_cases.py @@ -526,7 +526,7 @@ def test_the_field_sweep_sees_the_claims_it_checks() -> None: # rows' suffix-or-name under three orders; 2272 -> 2275 the same day, # its review's 'PETR JAN DIS' under three orders; 2275 -> 2278 the # same day, its second review's 'Jan DIS' under three orders; 2278 - # -> 2296 on 2026-11-21, #1516's six caps-shape rows reporting + # -> 2296 on 2026-11-21, #1517's six caps-shape rows reporting # suffix-or-name under three orders; 2296 -> 2321 the same day, its # test review's eight rows under three orders and its family-first # row under its declared policy. @@ -617,7 +617,7 @@ def test_the_field_sweep_sees_the_claims_it_checks() -> None: ("John Smith MA VI Jones", None), ("John Smith MA VI Jones", 2), # a name word in a mixed-case credential's place leaves the initials # in front of it no company, so they are the given name (rules/C16, - # #1516) + # #1517) ("Smith, M.B. ChB", None), ("Smith, M.B. ChB", 1), ("Smith, M.B. ChB", 2), } @@ -1031,7 +1031,7 @@ def test_the_alternative_sweep_sees_the_fields_it_checks() -> None: # and #1284's rows under three orders; 620 -> 629 the same day, #969's # three DiS rows after a comma under three orders; 629 -> 632 the same # day, its review's 'PETR JAN DIS' under three orders; 632 -> 647 on - # 2026-11-21, #1516's five caps-shape rows under three orders, + # 2026-11-21, #1517's five caps-shape rows under three orders, # 'Smith, M.B. ChB' being a stand-in reread; 647 -> 669 the same # day, its test review's rows assert (checked, skipped) == (669, 512), (checked, skipped) diff --git a/tests/v2/test_config_diff.py b/tests/v2/test_config_diff.py index 3ea977d97..b00f1f2bb 100644 --- a/tests/v2/test_config_diff.py +++ b/tests/v2/test_config_diff.py @@ -125,7 +125,7 @@ def test_a_name_whose_tokens_differ_is_tallied_as_retokenized() -> None: def test_the_tally_counts_moves_by_input_fields_and_word() -> None: # 'Phd' after the comma: unlisted, 'PhD' is read by the caps shape's - # mixed-case arm and stays a suffix (#1516) + # mixed-case arm and stays a suffix (#1517) texts = ["Ana Souza PhD", "Bo Lima, Phd", "Ana Souza", "Cy Dias Ph.D."] names = [(t, None, frozenset({"one"} if i % 2 else {"one", "two"})) for i, t in enumerate(texts)] diff --git a/tests/v2/test_locales.py b/tests/v2/test_locales.py index d856d6a5b..59e8c1062 100644 --- a/tests/v2/test_locales.py +++ b/tests/v2/test_locales.py @@ -3363,7 +3363,7 @@ def test_no_exclusion_is_pack_shaped_any_more() -> None: ("", "MgA", "Jana", "Malá", "", "", ()), ("MgA", "Jana", "", "Malá", "", "", ())), # the default reads it after a two-word head by the caps shape's - # mixed-case arm, as the credential it is (#1516); the pack, as the + # mixed-case arm, as the credential it is (#1517); the pack, as the # title it lists ("cs", None, "Jana Malá, MgA", ("", "Jana", "", "Malá", "MgA", "", ("SUFFIX_OR_NAME",)), diff --git a/tests/v2/test_parser.py b/tests/v2/test_parser.py index e1623d876..310112db2 100644 --- a/tests/v2/test_parser.py +++ b/tests/v2/test_parser.py @@ -3523,7 +3523,7 @@ def test_a_caller_removes_a_mul_word_as_any_other() -> None: assert kept.parse("Dr Ana Souza").title == "Dr" lexicon = Lexicon.default().remove("phd", kind="credential") # written 'Phd', as a name is: 'PhD' unlisted is still read by the - # caps shape's mixed-case arm after a comma (#1516) + # caps shape's mixed-case arm after a comma (#1517) assert Parser(lexicon=lexicon).parse("Ana Souza, Phd").given == "Phd" assert Parser(lexicon=lexicon).parse("Ana Souza, PhD").suffix == "PhD" for strict in (False, True): diff --git a/tests/v2/test_render.py b/tests/v2/test_render.py index 6b36bc1e0..0622c2e01 100644 --- a/tests/v2/test_render.py +++ b/tests/v2/test_render.py @@ -2306,7 +2306,7 @@ def test_a_caps_credential_after_a_comma_keeps_its_capitals_in_every_setting( def test_a_mixed_case_credential_is_kept_as_written_when_forced() -> None: - # rules/R4 (#1516): a word the caps shape read after a comma in mixed + # rules/R4 (#1517): a word the caps shape read after a comma in mixed # case ('MRes', 'AuD') keeps its writing, forced or not: no mask # lists it, and the acronym clause's capitals would write 'MRES'. # Its all-caps twin still repairs to capitals, and the company of a From 9d909a19808539fabeacc4411b8dd3b313bfc898 Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Sat, 21 Nov 2026 15:41:55 -0800 Subject: [PATCH 5/5] Restore the mixed arm of the caps marks behind a generation The fix review found it reachable: behind a generation with a title before the surname, C12 reads the word and the count marks nothing, so 'Dr. Smith Jr., AuD' forced gave 'Aud'. Its rows fail without the arm. Co-Authored-By: Claude Opus 5.5 --- nameparser/_pipeline/_comma.py | 6 ++++++ tests/v2/test_render.py | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/nameparser/_pipeline/_comma.py b/nameparser/_pipeline/_comma.py index 19a25f5e9..98a61a1e9 100644 --- a/nameparser/_pipeline/_comma.py +++ b/nameparser/_pipeline/_comma.py @@ -1060,6 +1060,12 @@ def decide(state: ParseState, splits: bool | None = True) -> ParseState: and (text.isupper() and (text.isalpha() or "-" in text or "/" in text) + # the mixed case C12 reads where the + # count marked nothing ('Dr. Smith + # Jr., AuD', #1517) + or not text.islower() + and not text.istitle() + and is_mixed_caps_word(text) or not unicodedata.is_normalized( "NFC", text) and is_caps_word(text))): caps.add(i) diff --git a/tests/v2/test_render.py b/tests/v2/test_render.py index 0622c2e01..e73b6bd70 100644 --- a/tests/v2/test_render.py +++ b/tests/v2/test_render.py @@ -2318,7 +2318,13 @@ def test_a_mixed_case_credential_is_kept_as_written_when_forced() -> None: ("Jane Smith, MRE\u0301s", "Jane Smith, MRE\u0301s"), ("Smith, M.B. ChB", "Smith, M.B. ChB"), ("Smith, J.P. AUD", "Smith, J.P. AUD"), - ("Ashley Knight, M.S. BME", "Ashley Knight, M.S. BME")): + ("Ashley Knight, M.S. BME", "Ashley Knight, M.S. BME"), + # behind a generation where a title stands before the + # surname, C12 reads it and the count marks nothing (#1517's + # fix review) + ("Dr. Smith Jr., AuD", "Dr. Smith Jr., AuD"), + ("Dr. Smith III, MScPT", "Dr. Smith III, MScPT"), + ("Dr. Smith Jr., AD", "Dr. Smith Jr., AD")): assert str(parse(text).capitalized(force=True)) == rendered, text assert str(parse(text).capitalized()) == rendered, text # a word written as a name is, read as the given name, still repairs