From aab9a215e2786146ce8987fa5156fead8bc9be93 Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Sun, 22 Nov 2026 12:35:39 -0800 Subject: [PATCH 1/3] Collect what the 3.2 prose sweep's parts left for each other rules/C6's Then line says the caps shape it has read since #1517, and the quote in `_comma` moves with it, gaining its clause line and decisions pointer. Three measurements that lived only in code comments (M1's clause bisect, `_extract._overlaps`, the compiled script sweep) move into dated decisions/parse-cost bullets, the comments left as pointers, and mechanisms.md's growth-guard bullet records that the control says which unit a ratio is in. Four case rows labelled as fixes read 1.4.0's fields and are parity rows, noted as #1467's are; two parity rows note 1.4.0's comma-joined suffix; a duplicate row goes. CONTRIBUTING.md's corpus count is retaken, and root AGENTS.md notes locales.MS reading Puan as a title. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 2 +- CONTRIBUTING.md | 4 ++-- docs/design/decisions/parse-cost.md | 4 ++++ docs/design/mechanisms.md | 2 +- ...caps-word-needs-the-names-case-contrast.md | 2 +- nameparser/_pipeline/_comma.py | 8 ++++++-- nameparser/_pipeline/_extract.py | 7 ++++--- nameparser/_pipeline/_group.py | 14 ++++--------- nameparser/_pipeline/_vocab.py | 9 +++------ tests/v2/cases.py | 20 +++++++------------ 10 files changed, 33 insertions(+), 39 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index daf642672..0048b2eed 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -343,7 +343,7 @@ The 2.0 rewrite landed as underscore-private modules beside the v1 code, which 2 **The `nameparser/config` vocabulary constants are frozen** (2.2, #293; private since 3.0, #1007) — `_compiled.TITLES.add("dean")` raises `AttributeError` at the line that writes it, so a runtime addition goes on a config OBJECT instead: `Parser(lexicon=Lexicon.default().remove("dean", kind="given"))`. What the freeze buys: `Lexicon.default()` is `functools.cache`d and reads the constants once, so pre-freeze an edit after the first parse was invisible to `parse()` while one before it was not, which depended on nothing the reader could see (through 2.x the v1 `Constants` copied the constants at every construction too, a third moment). -**Titles permanently shadow first names — be conservative** — any word in `TITLES` is always consumed as a title and can never be parsed as a first name. `"Dean"` is the canonical example: it's a common academic title *and* a common given name, so it is not in `TITLES` but in `TITLES_AMBIGUOUS`, a title only inside a title phrase (`Dean of Students`, `Associate Dean`; rules/H9, #752 phase 2i), and users who need it everywhere add it to a `Lexicon` of their own. A title that is also a given name now has that machinery: a `given` reading on the word moves it there, decided word by word in measured batches (decisions/vocabulary-model's 2026-10-24 order). A rule that reads a title by its neighbours in the title run meets more phrase shapes than the qualifier-then-head it was designed on: the object of a connective (`President of the United States`, `the Queen's Bench`, whose `united`, `states` and `bench` are modifiers with no head after them), a head before `of` (`Member of Parliament`), and a qualifier written after its head (`Chargé d'Affaires`, `Princess Royal`). Phase 2i's first build, "a modifier needs a head title after it", broke `President of the United States`, `Chargé d'Affaires` and the committed `Queen's Bench` row, found by the case table and the committed corpora, and then read a modifier ENDING the name out of H5's trailing run (`Jane Smith Vice.`), found by the design-docs review; put each shape, and the trailing position, in the grid of any such rule. Before adding a word to `TITLES`, ask: "Could this plausibly be someone's given name in any culture?" If yes, don't add it globally; it belongs in a caller-supplied `Lexicon` instead. This same caution applies to international honorifics — `Frau` is a first name in some contexts, and `Prince` and `Sheikh` were titles until 2.7 gave them a `given` reading, which moved them to `TITLES_AMBIGUOUS` (rules/H9). It also applies to any prefix sub-set gated on "never a first name": obscure-looking foreign particles are surprisingly often real given names — `Von` (Von Miller), `Vander` (Brazilian, also the Arcane character). When unsure, exclude — a missing member just means that name isn't auto-handled, whereas a wrong member misparses a real person. The decided exception is a word borne as a name only RARELY in the leading position — mostly a surname written last (`graf`, `greve`, `knight`), a few with small given-name or surname-first counts (`herra`, `hrabia`): the title claim acts only in front, so it ships, and a name that begins with it (`Greve Anna`, `Herra Wijaya` → title) is the accepted cost. That is a judgment by incidence, made per word, with the counts taken recorded on the word's entry in `nameparser/vocab/` (herra's, hrabia's; graf, which predates #606, and greve and knight, which #606 proposed, carry none) and the class in `decisions/salutation-titles` (rules/H1's Accepted clause states the cost), not a rule a sweep can apply: a word that commonly leads a real name (Vietnamese `Ông`, the given names `thiru`, `puan`) is still out of `TITLES`; `marshal` reads as a title only in a phrase (`Field Marshal`). `tools/name_usage.py` produces the counts this judgment starts from (role counts, plus Wikidata citizenship to tell where a family name is written first); its Wikidata column is a lower bound (Shehu Shagari has no given-name statement), so a small count there proves little and a zero proves nothing, and its nam_dict row gives a band per country rather than a count, with a missing name proving nothing either. +**Titles permanently shadow first names — be conservative** — any word in `TITLES` is always consumed as a title and can never be parsed as a first name. `"Dean"` is the canonical example: it's a common academic title *and* a common given name, so it is not in `TITLES` but in `TITLES_AMBIGUOUS`, a title only inside a title phrase (`Dean of Students`, `Associate Dean`; rules/H9, #752 phase 2i), and users who need it everywhere add it to a `Lexicon` of their own. A title that is also a given name now has that machinery: a `given` reading on the word moves it there, decided word by word in measured batches (decisions/vocabulary-model's 2026-10-24 order). A rule that reads a title by its neighbours in the title run meets more phrase shapes than the qualifier-then-head it was designed on: the object of a connective (`President of the United States`, `the Queen's Bench`, whose `united`, `states` and `bench` are modifiers with no head after them), a head before `of` (`Member of Parliament`), and a qualifier written after its head (`Chargé d'Affaires`, `Princess Royal`). Phase 2i's first build, "a modifier needs a head title after it", broke `President of the United States`, `Chargé d'Affaires` and the committed `Queen's Bench` row, found by the case table and the committed corpora, and then read a modifier ENDING the name out of H5's trailing run (`Jane Smith Vice.`), found by the design-docs review; put each shape, and the trailing position, in the grid of any such rule. Before adding a word to `TITLES`, ask: "Could this plausibly be someone's given name in any culture?" If yes, don't add it globally; it belongs in a caller-supplied `Lexicon` instead. This same caution applies to international honorifics — `Frau` is a first name in some contexts, and `Prince` and `Sheikh` were titles until 2.7 gave them a `given` reading, which moved them to `TITLES_AMBIGUOUS` (rules/H9). It also applies to any prefix sub-set gated on "never a first name": obscure-looking foreign particles are surprisingly often real given names — `Von` (Von Miller), `Vander` (Brazilian, also the Arcane character). When unsure, exclude — a missing member just means that name isn't auto-handled, whereas a wrong member misparses a real person. The decided exception is a word borne as a name only RARELY in the leading position — mostly a surname written last (`graf`, `greve`, `knight`), a few with small given-name or surname-first counts (`herra`, `hrabia`): the title claim acts only in front, so it ships, and a name that begins with it (`Greve Anna`, `Herra Wijaya` → title) is the accepted cost. That is a judgment by incidence, made per word, with the counts taken recorded on the word's entry in `nameparser/vocab/` (herra's, hrabia's; graf, which predates #606, and greve and knight, which #606 proposed, carry none) and the class in `decisions/salutation-titles` (rules/H1's Accepted clause states the cost), not a rule a sweep can apply: a word that commonly leads a real name (Vietnamese `Ông`, the given names `thiru`, `puan`) is still out of `TITLES`, a pack that settles the reading taking it in (`locales.MS` reads `Puan` as a title, decisions/salutation-titles, 2026-11-19 #1179); `marshal` reads as a title only in a phrase (`Field Marshal`). `tools/name_usage.py` produces the counts this judgment starts from (role counts, plus Wikidata citizenship to tell where a family name is written first); its Wikidata column is a lower bound (Shehu Shagari has no given-name statement), so a small count there proves little and a zero proves nothing, and its nam_dict row gives a band per country rather than a count, with a missing name proving nothing either. **The period-abbreviation title inference runs at the head of the GIVEN-NAME part, not the head of the name** — an unrecognized multi-letter word ending in a single trailing period (`_pieces._PERIOD_ABBREV`, v1's `period_abbreviation` regex, imported from `_vocab`, `{2,}` letters — it was assign's until #424 and group's until #439) is treated as a title in the leading title run, e.g. `"Insp. Jane Morse"` → `title='Insp.'`. "Leading" is per SEGMENT: `_peel_leading_titles` is called for NO_COMMA segment 0, SUFFIX_COMMA segment 0, and FAMILY_COMMA **segment 1**, so `"Morse, Det. Insp. Jane"` → `title='Det. Insp.'` and a lone `"Smith, Xyz."` → `title='Xyz.'` — long-standing, verified against 1.4.0, and the mechanism behind #296 (`"Smith, Jr."` read title in 1.4.0; the comma's credential read takes it as suffix `Jr.` now). The docs said "leading word" until 2026-08-01 and were wrong for every comma path. FAMILY_COMMA **segment 0** peels too since #701, but by VOCABULARY only (rules/H6, in assign's family-comma branch rather than `_peel_leading_titles`): `Dr. Smith, John` → `title='Dr.'`, while `Xyz. Smith, John` keeps family `Xyz. Smith`, and a title-particle (`St`, `Freiherr`) stops the run, as does a title with nothing but post-nominals behind it (`Dr. Jr., John` keeps family `Dr.`); a title/suffix dual with a name word behind it still peels (`Rev. Sr. Smith, Mary`). It adds nothing to the `Lexicon`, so the periodless form (`"Insp"`) is unaffected elsewhere. The `{2,}` length requirement — not a separate initials check — is what excludes single-letter initials like `"J."`, and since #1136 a closed list of transliteration digraphs (`_vocab._DIGRAPH_INITIALS`, e.g. `Yu.`, `Zh.`, `Kh.`; not `Ts.`, `Ch.` or `Sh.`, which are also titles written short) is declined by spelling in both `is_leading_title` and `is_title_shaped` (rules/H2's transliteration-digraph Except), reading as a name word rather than as T5's initial; the same word after the given name is left as a middle name. **The inference OUTRANKS vocabulary where it runs**: `"Esq. Smith"` → `title='Esq.'` even though `esq` is suffix-only vocabulary, because the shape rule fires before anything consults the suffix sets. The one vocabulary it yields to, since #789 (phase 2k of #752), is a given name written short (a `given` reading with `same_as`, in the TOML or a caller's `add(w, kind="given", same_as=...)`, compiled into the internal `Lexicon._sets.given_name_abbreviations`): `"Chas. Smith"` → `given='Chas.'`, read off classify's `vocab:given-abbreviation` tag in `is_leading_title` and off the lexicon in `_vocab.is_title_shaped`, the two spellings of one test that `test_is_title_shaped_and_is_leading_title_agree` holds together. The second spelling is what rules/C4's comma count and the title phrase's head run ask, so a change to the shape moves comma names nobody wrote it for: #789's first grid held no comma and missed `Chas. Smith, Ed` (given 'Ed', family 'Chas. Smith' before, suffix 'Ed' after), which only mutating `is_title_shaped`'s half alone showed. Put a word of the ambiguous class after a comma behind the shaped word (`X. Smith, Ed`), and a modifier in front of it (`Vice X. Smith, Ed`), in the grid of any change to the shape, and mutate each spelling separately. **The INFERENCE still runs in one direction only, and that is what the two slots share and where they part** (rewritten 2026-09-08, #316): a period-marked word is claimed by SHAPE at the front and by VOCABULARY at the back, so an unlisted abbreviation opening a name is a title while an unlisted abbreviation ending one is a NAME word (`"John Smith Xyz."` → `family='Xyz.'`). A trailing period-marked word the vocabulary knows as a title now IS one (`"John Smith Prof."` → `title='Prof.'`, `rules/H5`) — the comma path read a lone `Smith, Prof.` that way already, and the given part's `Smith, John Prof.` since 2.3.0 (1.4.0 through 2.2.0 read `Doe, Jane Mrs.` middle 'Mrs.'), so the two agree now — and a trailing period-marked word the UNAMBIGUOUS SUFFIX vocabulary knows is still a suffix, the suffix run being peeled first (`"John Smith Esq."` → `suffix='Esq.'`). A BARE trailing title word stays a name word (`"John Smith Sir"`, `"Mary Jane Pope"`), which is the doctrine line below, save a listed salutation ending the given part after a family comma (rules/H8, `"Doe, Jane Mrs"` → `title='Mrs'`). Meanwhile `period_joined_vocab` resolves INTERIOR-period tokens (`Lt.Gov.`, `Msc.Ed.`) to title-or-suffix by vocabulary, and `_extract._period_escape` treats any period-final delimited content that rules/S1 does not set apart as not-a-nickname. The trailing chain's SHAPE is wider than the front's since #1116: a word ending in a period may hold periods or hyphens inside it (`_vocab._TRAILING_TITLE_SHAPE`), so a listed title written that way and a `period_joined_vocab` title ending a name chain (`"Hans Meier Priv.-Doz."`, `"John Smith Lt.Gov."` → title), while H2's front shape stays letters only; a title listed whole with a period inside it needs no final period there (`"Maria Rossi Dott.ssa"`, classify's `JOINED_TITLE_TAG`, #1104). Four sites, and the trailing one now resolves by two vocabularies in order rather than one; a fifth, rules/H10 (#490), reads a run of single letters joined by full stops at the head by vocabulary looked up without its stops, as the title it spells where the vocabulary marks that title `dotted` and a title the run keeps follows it (`U.S. District Judge`, but `U.S. Grant` given 'U.', middle 'S.', its given names 'U.S.'); unifying the rest is open design work, not settled. (#109; see `docs/shapes.rst` "Titles you didn't configure") diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3fdd81c0e..d1788ed03 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -24,9 +24,9 @@ Why the maintainer makes the changes Most changes here also move documented rules, the design records and a snapshot of thousands of parsed names. The maintainer checks every change -against about 9 million records of real names from sixteen sources +against about 9.4 million records of real names from eighteen sources (election candidates, donors, researchers, patent inventors, company filings; -counted 2026-11-16). +counted 2026-11-22). The tools that fetch them are in this repository, but the names are not: the cache is about 12 GB, and one source alone takes about twelve hours to download. A change that passes the committed tests can still move thousands diff --git a/docs/design/decisions/parse-cost.md b/docs/design/decisions/parse-cost.md index 5bf11c2cf..7887067fd 100644 --- a/docs/design/decisions/parse-cost.md +++ b/docs/design/decisions/parse-cost.md @@ -21,6 +21,10 @@ Open: none in this file. ## Log +- 2026-07-19 4e02fa4e — `_extract._overlaps` BISECTS. The closer sweep tests one span per delimiter character found, so a linear probe over the masked spans was quadratic in the number of matched pairs: 400 pairs spent 5.4ms in it, against 2.5ms before the sweep existed. No recipe was kept beyond those figures; the guards are tests/v2/test_benchmark.py's `delimiter_pairs` and `unmatched_closes` rows (moved here from the function's docstring, 2026-11-22). +- 2026-07-28 a102c868 — THE SCRIPT SWEEP IS A COMPILED CLASS. `single_script`'s sweep was first written per character on `_tokenize`'s `_EMOJI_RANGES` precedent, on the theory that a range test needs no regex; measured at token scale the compiled regex won by 3-9x, and by roughly 70x on long tokens. No recipe was kept beyond those figures. The precedent has since gone the same way: tokenize scans for its separators with a compiled class (#1436) (moved here from `_vocab`'s comment above `_SCRIPT_MATCHERS`, 2026-11-22). +- 2026-08-02 #329 — M1's CLAUSE CONTAINMENT BISECTS. Scanning the token list per delimited clause is quadratic in the number of pairs: `"(a) " * 3200`, 4x test_benchmark's base and not a doubling, cost 14.1x against the 4.1x the same shape holds under a policy with no `maiden_delimiters`, the control that says the ratio is per 4x (linear reads about 4 for 4x the input and about 2 for a doubling, so a 4.1x control cannot be per doubling). Re-measured 2026-08-03 at 11.2x against 4.2x (3.2x against 2.1x per doubling): the separation replicates, the exact ratio moves with the runner. No recipe was kept beyond those figures; the guard is test_benchmark's `maiden_pairs` row (moved here from `_group`'s comment at the clause walk, 2026-11-22). + - 2026-08-31 #475 (its rows superseded by 2026-09-26 #546; its facade entry point superseded by 2026-10-28 #357; its reverted role-index repair taken up by 2026-11-05 #1089) — the benchmark bounds FUNCTION CALLS per parse, not seconds, as a per-interpreter BAND of ±2%. A loose 5s wall-clock backstop stays over BOTH entry points for what frame counts cannot see: a compiled regex that starts backtracking emits no `call` event, and neither does C-level work. (A quadratic inside a comprehension or generator IS visible — `call` fires once per generator resume.) WHY THE CLOCK HAD TO GO. The 1.0s bound failed four times across #466 and #474, always on CI's 3.12 job, always between 1.01s and 1.08s, with master re-running green each time. Three local methods disagreed with CI and with each other: uninstrumented ~1% branch-over-parent (inside the parent's own spread), coverage-instrumented indistinguishable, and the whole benchmark file under `--cov` made the branch FASTER. The same harness measured `origin/master` at 94-96ms and again at 89-92ms twenty minutes later. A check that cannot separate a 1% change from a busy runner does not fail safe; it fails expensively. WHY A BAND AND NOT A CEILING, which is the correction the review forced. A ceiling with headroom is ANOTHER threshold that happens to break — the failure this replaced. The first draft set 470 against a 408 baseline, and measured, that catches nothing smaller than +61 calls on 3.11 and +84 on 3.12: it would have missed the very regression it was built for on four of five interpreters. The cycle's +67 arrived across a dozen PRs at roughly five calls each, and no ceiling loose enough to be safe can see five. A ±2% band trips at +5, verified by injection. A DROP trips it too, which is intended: an unexplained fall is as much a signal as a rise. diff --git a/docs/design/mechanisms.md b/docs/design/mechanisms.md index 4bc7bcaf9..c81a695a5 100644 --- a/docs/design/mechanisms.md +++ b/docs/design/mechanisms.md @@ -476,6 +476,6 @@ A second axis cuts across the jobs: whether the names are real or invented, labe - An invariant judged on the part a JOIN PRODUCED is satisfied by whatever the join absorbed. #397's both-sides condition was stated as "a name word stands on each side of the link", and the invariant written from that sentence walks the joined part and asks whether a non-connective word stands on each side of the letter — which a swallowed credential answers yes to, being that word. `Josep Lluis Carod i III` read family 'Carod i III' and PASSED it. The merge has already destroyed the evidence, so the question cannot be re-asked downstream at all. Judge on the PRE-join classes, or against a second parse with the rule turned off — the off-switch parse puts the credential in `suffix`, and "no word the off-switch reading calls a suffix lands inside a joined name part" caught it on 639 parses of the shipped grid where the first invariant caught none (960 over the full cross product, a dated snapshot before the grid was trimmed by shape). The same pairing is worth reaching for whenever a rule MERGES tokens. - A detector that re-implements a rule's grouping will get the grouping wrong. Derive the boundary from the same vocabulary the rule reads, not from the half you happen to be thinking about: walking a particle run over the NEVER-GIVEN set alone (the rule chains through ANY particle) split "de la Vega" after "de la" and reported 50 false movers for #364, where the true count is one. Both wrong answers were plausible and printed cleanly. - Guard the whole family, parametrize over it: a defect on one of N parallel entry points hides behind a per-example test — three times in one session (a guard on one class of two, a decode hint on 3 of 5 entry points, a sync roster missing 4 copies) — and a {class}×{field}×{bad-value} parametrization is what caught each. -- A growth guard needs calibration, not just existence: benchmark guards that compare n vs 4n catch the quadratic the absolute-time tests are blind to, but calibrate against the WEAKEST signal you must detect and confirm a planted regression fails across repeated runs, not once — a stochastic check "verified" on one sample verifies nothing. And a clock's clean column is the machine's: a term that moves memory rather than running Python is cheap where memory is fast, so it calibrates INTO the clean column on a dev machine and fails only on slower runners. #1036's slice shift read 4.1-4.4x for 4x the input on a dev machine and 7.5-8.3x on CI's runners, for four weeks; count the work instead where it can be counted (decisions/parse-cost, 2026-11-03). +- A growth guard needs calibration, not just existence: benchmark guards that compare n vs 4n catch the quadratic the absolute-time tests are blind to, but calibrate against the WEAKEST signal you must detect and confirm a planted regression fails across repeated runs, not once — a stochastic check "verified" on one sample verifies nothing. And a clock's clean column is the machine's: a term that moves memory rather than running Python is cheap where memory is fast, so it calibrates INTO the clean column on a dev machine and fails only on slower runners. #1036's slice shift read 4.1-4.4x for 4x the input on a dev machine and 7.5-8.3x on CI's runners, for four weeks; count the work instead where it can be counted (decisions/parse-cost, 2026-11-03). And run a control beside the ratio: the control says which unit the ratio is in, linear reading about 4 for 4x the input and about 2 for a doubling, so #329's 14.1x for `"(a) " * 3200` read as a quadratic per 4x only beside the 4.1x the same shape held under a policy that skips the path (decisions/parse-cost, 2026-08-02 #329). - A frame BUDGET pinned on one reference name cannot see algorithmic blowup; a frame RATIO over two input sizes can. #531's first implementation had a trailing walk re-enter the predicate that owns it, so a run of k ambiguous credentials cost 2**k — `'Doe, John ' + 'MA '*24` took about 6s, wall clock, where the parent commit took 0.24ms (two runs of that one measurement, 5.8s and 5.9s, which is the spread the guard below quotes them at) — while every absolute figure beside the change stayed correct and unmoved: `tools/perf/call_count.py`'s 412/449 on its reference name, and +0 frames on a comma name carrying no class member. The budget is a claim about ONE input and the defect is a claim about a family of them, so no budget is the instrument. The guard that catches it counts frames at 8 members against 16 and bounds THAT ratio (`tests/v2/test_benchmark.py::test_a_trailing_credential_run_does_not_cost_exponentially`): 2,347 → 394,671 frames unfixed, 168x, against 865 → 1,497 and 1.73x fixed, with the bound at 6x. ONE pair does not see every curve, though, and the fix round measured how badly: at 2× the input the per-member linear work swamps a quadratic, so the per-member memo the first fix shipped — a genuine quadratic — reads 2.08x at that pair, inside any bound this one can carry. Separating those needs 4× the input, where the same memo reads 7.42x against the linear 3.53x, so the guard carries a second pair (16 against 64) and asserts the cheap one FIRST: an exponential does not return from a run of 64. Frames rather than a clock for two reasons — the recursion IS frame entries, so the count is the defect rather than a proxy, and the input length that separates an exponential from a linear on a timing test does not finish. It needs the reachability assertion a `_POLICY_SHAPES` row carries, for the same reason: the walk under measurement runs only while every unit still reads as a credential, and a precedence change that routes them elsewhere leaves a green test measuring a walk that no longer happens. - Mind the optional-extra environment split: a local venv's incidental namedivider makes `if available` branches run PRESENT locally and ABSENT in CI, so a locally-green suite proves nothing about the no-extra path (this broke #337's first landing). Run the decisive check in both states or gate the example. 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 6c6667a30..89336ba6b 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 @@ -2,7 +2,7 @@ **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. +**Then:** an unlisted word in the caps shape (S9), written in capitals or in a credential's mixed case, 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. - **A word written the way a name is** holds a capital with its last cased letter lowercase — read after composing the word, passing over every non-letter and caseless letter and any lowercase letter whose capital is not a single letter, as ß's is not — with no period and not claimed by the vocabulary as a title, particle, connective, credential or generation. ``` diff --git a/nameparser/_pipeline/_comma.py b/nameparser/_pipeline/_comma.py index 1bc3412df..e91aa51e1 100644 --- a/nameparser/_pipeline/_comma.py +++ b/nameparser/_pipeline/_comma.py @@ -891,8 +891,12 @@ def decide(state: ParseState, splits: bool | None = True) -> ParseState: letters_one_case=state.one_case, members=split_at) if names >= 2: - # rules/C6: "An unlisted all-caps word joins the ambiguous - # credential class [...] only where the name carries the contrast" + # rules/C6: "an unlisted word in the caps shape (S9), written in + # capitals or in a credential's mixed case, joins the ambiguous + # credential class (C4, S9) in the part after the comma only where + # the name carries the contrast" -- the part after the comma's + # half, read once two name words stand before it (decisions/C6 + # (#564, #1517)) for i in maybe: text = texts[i] if SHAPE_ACRONYM_TAG in tokens[i].tags: diff --git a/nameparser/_pipeline/_extract.py b/nameparser/_pipeline/_extract.py index 9078688df..c28977a55 100644 --- a/nameparser/_pipeline/_extract.py +++ b/nameparser/_pipeline/_extract.py @@ -214,9 +214,10 @@ def _overlaps(span: Span, taken: list[Span], starts: list[int]) -> bool: """`taken` sorted and non-overlapping (both hold by construction), `starts` its start offsets. Bisect rather than scan: the closer sweep tests one span per delimiter character found, so a linear - probe is quadratic in the number of matched pairs (400 pairs spent - 5.4ms here, against 2.5ms before the sweep existed). Same idiom, and - the same reason, as the origin resolution in _tokenize.""" + probe is quadratic in the number of matched pairs + (decisions/parse-cost, 2026-07-19 4e02fa4e, holds the measurement). + Same idiom, and the same reason, as the origin resolution in + _tokenize.""" i = bisect.bisect_right(starts, span.start) - 1 # the only candidates are the last span starting at or before us and # its successor -- anything earlier ends before it, anything later diff --git a/nameparser/_pipeline/_group.py b/nameparser/_pipeline/_group.py index e864ebb8f..0ce51509d 100644 --- a/nameparser/_pipeline/_group.py +++ b/nameparser/_pipeline/_group.py @@ -1990,16 +1990,10 @@ def group(state: ParseState) -> ParseState: # sub-slices, so containment stays exact. # # Bisect rather than scan the token list per clause: that is - # quadratic in the number of delimited pairs, and "(a) " * 3200 -- - # 4x test_benchmark's base, NOT a doubling -- measured a 14.1x cost - # against the 4.1x the same shape holds under a policy with no - # maiden_delimiters. The control is what says which unit a ratio is - # in: linear is ~4 for 4x the input and ~2 for a doubling, so a 4.1x - # control cannot be per doubling. Re-measured 2026-08-03 at 11.2x - # against 4.2x (3.2x against 2.1x per doubling) -- the separation - # replicates, the exact ratio moves with the runner. Same idiom, - # and the same reason, as _extract._overlaps and _tokenize's origin - # resolution. test_benchmark's maiden_pairs shape is the guard. + # quadratic in the number of delimited pairs (decisions/parse-cost, + # 2026-08-02 #329, holds the measurement). Same idiom, and the same + # reason, as _extract._overlaps and _tokenize's origin resolution. + # test_benchmark's maiden_pairs shape is the guard. # rules/N4: "the marker dropped as M3 drops it" -- a nickname # clause opening with an alias marker, by the same walk (decisions/N4 (#1164)). # A plain loop over a map of a C getter, no frame: a name with no diff --git a/nameparser/_pipeline/_vocab.py b/nameparser/_pipeline/_vocab.py index 97eb344de..5323ca4fd 100644 --- a/nameparser/_pipeline/_vocab.py +++ b/nameparser/_pipeline/_vocab.py @@ -104,12 +104,9 @@ # The codepoint table lives in _policy beside Script -- one copy # importable from the pipeline and the locale packs alike; everything -# here DERIVES from it. (single_script's sweep was first written -# per-char on the _EMOJI_RANGES precedent in _tokenize.py, on the -# theory that a range test needs no regex; measured at token scale the -# compiled regex wins by 3-9x, and by roughly 70x on long tokens. The -# precedent has since gone the same way: tokenize scans for its -# separators with a compiled class, #1436.) +# here DERIVES from it. (A compiled class, not a per-character range +# test: decisions/parse-cost, 2026-07-28 a102c868, holds the +# measurement.) # Derived, never hand-written -- even the class construction goes # through the shared factory: one wholly-of predicate per script, in # the table's key order -- the FIRST-covering-entry rule _classify diff --git a/tests/v2/cases.py b/tests/v2/cases.py index df3e5024d..a2472d940 100644 --- a/tests/v2/cases.py +++ b/tests/v2/cases.py @@ -7816,7 +7816,8 @@ def _check_cjk_shape_purity(self) -> None: Case("a_cyrillic_doctorate_past_a_second_comma", "Петренко, Іван, д-р", {"given": "Іван", "family": "Петренко", "suffix": "д-р"}, - classification="fix(#1128)"), + notes="#1128 restores 1.4.0's reading: 3.1.0 read title " + "'д-р'"), Case("a_cyrillic_doctorate_before_a_generation", "Іван Петренко д-р мл.", {"given": "Іван", "family": "Петренко", "suffix": "д-р мл."}, @@ -14179,12 +14180,6 @@ def _check_cjk_shape_purity(self) -> None: notes="P12 reads a list, not the article: a nisba surname opens " "with ال too, and joined it would read family 'عبد القريشي' " "(decisions/P12)"), - Case("bound_given_latin_past_the_start_stays_apart", "Tariq Abdul Aziz", - {"given": "Tariq", "middle": "Abdul", "family": "Aziz"}, - notes="#694's Latin half: abdul lists no completed_by, and its " - "completes_any reading is long_names_only (#1464), so in a " - "name of three words the pair stays apart, a middle name " - "as often as a family (decisions/P12)"), Case("mr_and_mrs", "Mr. and Mrs. John Smith", {"title": "Mr. and Mrs.", "given": "John", "family": "Smith"}), Case("roman_suffix", "John Smith V", @@ -17956,7 +17951,6 @@ def _check_cjk_shape_purity(self) -> None: Case("md_in_capitals_before_a_title_word_reads_it_as_the_family", "JOHN SMITH MD PROF", {"given": "JOHN", "middle": "SMITH MD", "family": "PROF"}, - classification="fix(#1394)", ambiguities=("suffix-or-name",), notes="Accepted (rules/S8): a title behind it is a name word, as " "behind a Title-case acronym ('John Smith Md Dr'); 2.4.0 " @@ -18005,7 +17999,6 @@ def _check_cjk_shape_purity(self) -> None: Case("md_in_capitals_behind_a_particle_chain_still_reports", "JOHN VAN MD MA DE", {"given": "JOHN", "middle": "VAN MD MA", "family": "DE"}, - classification="fix(#1394)", ambiguities=("suffix-or-name", "suffix-or-name"), notes="S8 (#1394's second review): the decline's report survives " "group's rebuilt read where the chain took a member the " @@ -18045,11 +18038,13 @@ def _check_cjk_shape_purity(self) -> None: Case("md_in_capitals_before_a_credential_stays_the_credential", "JOHN SMITH MD PHD", {"given": "JOHN", "family": "SMITH", "suffix": "MD PHD"}, - notes="boundary: a credential behind it is no name word"), + notes="boundary: a credential behind it is no name word; 1.4.0 " + "joins the suffix with a comma, 'MD, PHD'"), Case("md_in_capitals_before_a_generation_stays_the_credential", "JOHN SMITH MD JR", {"given": "JOHN", "family": "SMITH", "suffix": "MD JR"}, - notes="boundary: a suffix word behind it is no name word"), + notes="boundary: a suffix word behind it is no name word; 1.4.0 " + "joins the suffix with a comma, 'MD, JR'"), Case("md_in_capitals_with_its_periods_starts_the_run", "JOHN SMITH M.D. JONES", {"given": "JOHN", "family": "SMITH", "suffix": "M.D. JONES"}, @@ -23105,8 +23100,7 @@ def _check_cjk_shape_purity(self) -> None: "Mr Masters", {"title": "Mr", "family": "Masters"}, ambiguities=("title-or-name",), - classification="fix(#1457)", - notes="H4: a name of title words alone reports which one names " + notes="H4: 1.4.0's fields; a name of title words alone reports which one names " "the person, as 'Mr. Bishop' does; reported nothing " "through 3.1"), Case("occupation_alone_after_a_family_comma_leaves_no_given_name", From cf8f454389eee75601193f6341ebb4741129e971 Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Sun, 22 Nov 2026 12:41:52 -0800 Subject: [PATCH 2/3] Give the moved measurements their commits, interpreters and recipes The script-sweep figure "roughly 70x" was 08026d35's rewording of a102c868's 89x, its commit message saying 5x and 35x; the bullet now says so. All three bullets note that no interpreter was recorded, and the two with a guard say the guard, run against the fix's parent, is the recipe. C6's mixed-case Then bullet now carries what the widened Then does not: the spelling is the caps shape's after a comma alone, and a word the shape refuses stays a name word. Co-Authored-By: Claude Opus 5.5 --- docs/design/decisions/parse-cost.md | 6 +++--- ...-unlisted-all-caps-word-needs-the-names-case-contrast.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/design/decisions/parse-cost.md b/docs/design/decisions/parse-cost.md index 7887067fd..7a468a2b1 100644 --- a/docs/design/decisions/parse-cost.md +++ b/docs/design/decisions/parse-cost.md @@ -21,9 +21,9 @@ Open: none in this file. ## Log -- 2026-07-19 4e02fa4e — `_extract._overlaps` BISECTS. The closer sweep tests one span per delimiter character found, so a linear probe over the masked spans was quadratic in the number of matched pairs: 400 pairs spent 5.4ms in it, against 2.5ms before the sweep existed. No recipe was kept beyond those figures; the guards are tests/v2/test_benchmark.py's `delimiter_pairs` and `unmatched_closes` rows (moved here from the function's docstring, 2026-11-22). -- 2026-07-28 a102c868 — THE SCRIPT SWEEP IS A COMPILED CLASS. `single_script`'s sweep was first written per character on `_tokenize`'s `_EMOJI_RANGES` precedent, on the theory that a range test needs no regex; measured at token scale the compiled regex won by 3-9x, and by roughly 70x on long tokens. No recipe was kept beyond those figures. The precedent has since gone the same way: tokenize scans for its separators with a compiled class (#1436) (moved here from `_vocab`'s comment above `_SCRIPT_MATCHERS`, 2026-11-22). -- 2026-08-02 #329 — M1's CLAUSE CONTAINMENT BISECTS. Scanning the token list per delimited clause is quadratic in the number of pairs: `"(a) " * 3200`, 4x test_benchmark's base and not a doubling, cost 14.1x against the 4.1x the same shape holds under a policy with no `maiden_delimiters`, the control that says the ratio is per 4x (linear reads about 4 for 4x the input and about 2 for a doubling, so a 4.1x control cannot be per doubling). Re-measured 2026-08-03 at 11.2x against 4.2x (3.2x against 2.1x per doubling): the separation replicates, the exact ratio moves with the runner. No recipe was kept beyond those figures; the guard is test_benchmark's `maiden_pairs` row (moved here from `_group`'s comment at the clause walk, 2026-11-22). +- 2026-07-19 4e02fa4e — `_extract._overlaps` BISECTS. The closer sweep tests one span per delimiter character found, so a linear probe over the masked spans was quadratic in the number of matched pairs: 400 pairs spent 5.35ms in it, against 2.52ms before the sweep existed, growing 2.55x per doubling, and 1.9x per doubling with the bisect, 800 pairs in 5.2ms (4e02fa4e's commit message; interpreter not recorded). The guards, which re-run the shape against 4e02fa4e's parent, are tests/v2/test_benchmark.py's `delimiter_pairs` and `unmatched_closes` rows (moved here from the function's docstring, 2026-11-22). +- 2026-07-28 a102c868 — THE SCRIPT SWEEP IS A COMPILED CLASS. `single_script`'s sweep was first written per character on `_tokenize`'s `_EMOJI_RANGES` precedent, on the theory that a range test needs no regex; measured at token scale the compiled regex won by 3-9x, and by 89x on long tokens, as a102c868's comment recorded (its commit message: 5x faster on ordinary CJK tokens, 35x on long ones), a comment 08026d35 rewrote on 2026-07-29 as "roughly 70x" with no re-measurement recorded; interpreter not recorded and no recipe kept. The precedent has since gone the same way: tokenize scans for its separators with a compiled class (#1436) (moved here from `_vocab`'s comment above `_SCRIPT_MATCHERS`, 2026-11-22). +- 2026-08-02 #329 — M1's CLAUSE CONTAINMENT BISECTS. Scanning the token list per delimited clause is quadratic in the number of pairs: `"(a) " * 3200`, 4x test_benchmark's base and not a doubling, cost 14.1x against the 4.1x the same shape holds under a policy with no `maiden_delimiters` (6fe92d12; interpreter not recorded), the control that says the ratio is per 4x (linear reads about 4 for 4x the input and about 2 for a doubling, so a 4.1x control cannot be per doubling). Re-measured 2026-08-03 at 11.2x against 4.2x (3.2x against 2.1x per doubling): the separation replicates, the exact ratio moves with the runner. The guard is the recipe: test_benchmark's `maiden_pairs` row, `"(a) "` under `Policy(maiden_delimiters=frozenset({("(", ")")}))` at its base of 800 and four times it, run against 6fe92d12's parent (moved here from `_group`'s comment at the clause walk, 2026-11-22). - 2026-08-31 #475 (its rows superseded by 2026-09-26 #546; its facade entry point superseded by 2026-10-28 #357; its reverted role-index repair taken up by 2026-11-05 #1089) — the benchmark bounds FUNCTION CALLS per parse, not seconds, as a per-interpreter BAND of ±2%. A loose 5s wall-clock backstop stays over BOTH entry points for what frame counts cannot see: a compiled regex that starts backtracking emits no `call` event, and neither does C-level work. (A quadratic inside a comprehension or generator IS visible — `call` fires once per generator resume.) WHY THE CLOCK HAD TO GO. The 1.0s bound failed four times across #466 and #474, always on CI's 3.12 job, always between 1.01s and 1.08s, with master re-running green each time. Three local methods disagreed with CI and with each other: uninstrumented ~1% branch-over-parent (inside the parent's own spread), coverage-instrumented indistinguishable, and the whole benchmark file under `--cov` made the branch FASTER. The same harness measured `origin/master` at 94-96ms and again at 89-92ms twenty minutes later. A check that cannot separate a 1% change from a busy runner does not fail safe; it fails expensively. 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 89336ba6b..f8ce58620 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 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. +- **The mixed-case spelling is the caps shape's after the comma alone** (S9: 'MRes', 'DClinPsy', 'AuD'), the contrast gating it as it gates capitals, and a word the shape refuses stays a name word ('LeBron', 'PhDc', 'Pharm-D'). ``` "Jane Smith, MRes" → suffix="MRes" "Jane Smith, AuD" → suffix="AuD" From 026b4c3db322ffb754dba39e070f2878ef2231c9 Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Sun, 22 Nov 2026 12:45:14 -0800 Subject: [PATCH 3/3] Say which guard reproduces which quadratic, and that M1's draft left none Co-Authored-By: Claude Opus 5.5 --- docs/design/decisions/parse-cost.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/design/decisions/parse-cost.md b/docs/design/decisions/parse-cost.md index 7a468a2b1..a3fc8e9f4 100644 --- a/docs/design/decisions/parse-cost.md +++ b/docs/design/decisions/parse-cost.md @@ -21,9 +21,9 @@ Open: none in this file. ## Log -- 2026-07-19 4e02fa4e — `_extract._overlaps` BISECTS. The closer sweep tests one span per delimiter character found, so a linear probe over the masked spans was quadratic in the number of matched pairs: 400 pairs spent 5.35ms in it, against 2.52ms before the sweep existed, growing 2.55x per doubling, and 1.9x per doubling with the bisect, 800 pairs in 5.2ms (4e02fa4e's commit message; interpreter not recorded). The guards, which re-run the shape against 4e02fa4e's parent, are tests/v2/test_benchmark.py's `delimiter_pairs` and `unmatched_closes` rows (moved here from the function's docstring, 2026-11-22). +- 2026-07-19 4e02fa4e — `_extract._overlaps` BISECTS. The closer sweep tests one span per delimiter character found, so a linear probe over the masked spans was quadratic in the number of matched pairs: 400 pairs spent 5.35ms in it, against 2.52ms before the sweep existed, growing 2.55x per doubling, and 1.9x per doubling with the bisect, 800 pairs in 5.2ms (4e02fa4e's commit message; interpreter not recorded). The guards are tests/v2/test_benchmark.py's `delimiter_pairs` and `unmatched_closes` rows, added the next day (17e101b3); `delimiter_pairs`' shape, `"(a) "` at 800 and 3200 units, run on 4e02fa4e's parent reads 11.63x against 4.16x on the fix, while `unmatched_closes` reads 4.07x on both, guarding the unmatched sweep instead (best of 7, py3.11, measured 2026-11-22 by #1537's review) (moved here from the function's docstring, 2026-11-22). - 2026-07-28 a102c868 — THE SCRIPT SWEEP IS A COMPILED CLASS. `single_script`'s sweep was first written per character on `_tokenize`'s `_EMOJI_RANGES` precedent, on the theory that a range test needs no regex; measured at token scale the compiled regex won by 3-9x, and by 89x on long tokens, as a102c868's comment recorded (its commit message: 5x faster on ordinary CJK tokens, 35x on long ones), a comment 08026d35 rewrote on 2026-07-29 as "roughly 70x" with no re-measurement recorded; interpreter not recorded and no recipe kept. The precedent has since gone the same way: tokenize scans for its separators with a compiled class (#1436) (moved here from `_vocab`'s comment above `_SCRIPT_MATCHERS`, 2026-11-22). -- 2026-08-02 #329 — M1's CLAUSE CONTAINMENT BISECTS. Scanning the token list per delimited clause is quadratic in the number of pairs: `"(a) " * 3200`, 4x test_benchmark's base and not a doubling, cost 14.1x against the 4.1x the same shape holds under a policy with no `maiden_delimiters` (6fe92d12; interpreter not recorded), the control that says the ratio is per 4x (linear reads about 4 for 4x the input and about 2 for a doubling, so a 4.1x control cannot be per doubling). Re-measured 2026-08-03 at 11.2x against 4.2x (3.2x against 2.1x per doubling): the separation replicates, the exact ratio moves with the runner. The guard is the recipe: test_benchmark's `maiden_pairs` row, `"(a) "` under `Policy(maiden_delimiters=frozenset({("(", ")")}))` at its base of 800 and four times it, run against 6fe92d12's parent (moved here from `_group`'s comment at the clause walk, 2026-11-22). +- 2026-08-02 #329 — M1's CLAUSE CONTAINMENT BISECTS. Scanning the token list per delimited clause is quadratic in the number of pairs: `"(a) " * 3200`, 4x test_benchmark's base and not a doubling, cost 14.1x against the 4.1x the same shape holds under a policy with no `maiden_delimiters` (6fe92d12; interpreter not recorded), the control that says the ratio is per 4x (linear reads about 4 for 4x the input and about 2 for a doubling, so a 4.1x control cannot be per doubling). Re-measured 2026-08-03 at 11.2x against 4.2x (3.2x against 2.1x per doubling): the separation replicates, the exact ratio moves with the runner. No tree reproduces the 14.1x: the per-clause scan was a draft of #329 never committed, the clause walk arriving bisected in 6fe92d12 (4.3x there by its message), so 6fe92d12's parent has no walk to time. The guard is test_benchmark's `maiden_pairs` row, `"(a) "` under `Policy(maiden_delimiters=frozenset({("(", ")")}))` at its base of 800 and four times it (moved here from `_group`'s comment at the clause walk, 2026-11-22). - 2026-08-31 #475 (its rows superseded by 2026-09-26 #546; its facade entry point superseded by 2026-10-28 #357; its reverted role-index repair taken up by 2026-11-05 #1089) — the benchmark bounds FUNCTION CALLS per parse, not seconds, as a per-interpreter BAND of ±2%. A loose 5s wall-clock backstop stays over BOTH entry points for what frame counts cannot see: a compiled regex that starts backtracking emits no `call` event, and neither does C-level work. (A quadratic inside a comprehension or generator IS visible — `call` fires once per generator resume.) WHY THE CLOCK HAD TO GO. The 1.0s bound failed four times across #466 and #474, always on CI's 3.12 job, always between 1.01s and 1.08s, with master re-running green each time. Three local methods disagreed with CI and with each other: uninstrumented ~1% branch-over-parent (inside the parent's own spread), coverage-instrumented indistinguishable, and the whole benchmark file under `--cov` made the branch FASTER. The same harness measured `origin/master` at 94-96ms and again at 89-92ms twenty minutes later. A check that cannot separate a 1% change from a busy runner does not fail safe; it fails expensively.