Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions docs/design/decisions/parse-cost.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.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. 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.
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.
Expand Down
Loading