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
12 changes: 10 additions & 2 deletions docs/design/decisions/vocabulary-collisions.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/design/decisions/vocabulary-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The vocabulary was a set of base sets plus marker subsets (`particles` and `part
- The vocabulary redesign comes before adding many packs: it is designed for 3.0, and what is safe is pulled forward in four phases, (1) the data format and a compiler, snapshot-neutral, (2) derived ambiguity with the gate on every reading kind, (3) pack semantics, (4) the rules menu, order and shapes, and the output model — 2026-10-15/16.
- Each word is described by its readings (word → reading → properties), each kind belonging to one category that decides the compiled field it feeds; detailed kinds are recorded even where the kinds of a category behave alike, generation and credential being separate kinds of the suffix category (its kinds are the entries `CATEGORY` in `nameparser/_reading_index.py` maps to `suffix`) — 2026-10-15/16; 2026-10-18 #737.
- A language file holds the words the parser might meet in names written in that language, immigrant particles included, not the words of its etymology, and a word sits in the file of every language whose names it occurs in, a Latin transliteration in its source language's file; `mul.toml` holds the words shared on purpose instead (the generations `i` to `v`, `2` and `jr` with `junior` and `jnr`, `&`, the European titles below, and the degrees and salutations every country's data writes alike), a word joining it where it harms no language and would otherwise be duplicated into every language's file — 2026-10-15/16; 2026-10-18 #737; 2026-10-19 #749; 2026-10-19 #750, title kinds; 2026-11-02 #1005 (Derek); 2026-11-03 #1005, the strict-gap batches (Derek).
- The default loads every language and keeps working for names of any language. Choosing a language narrows it since 3.0's phase 3 (#753): a pack settles only the clashes where its language has a vocabulary reading (`locales.VI` and `locales.MY` excepted: each fragment removes readings of syllables no reading in its file can settle, Vietnamese 2026-11-05 #1108, Burmese decisions/vocabulary-collisions' 2026-11-19 #1231 entry), a strict choice reads only the chosen languages' files, `mul.toml` and native-script words' readings as a plain choice of the same languages keeps them (name readings included), and a pack's preferred reading can outrank one a shape rule derives — 2026-10-15/16; 2026-10-30 #753, file-strict; 2026-11-02 #1005 (Derek); 2026-11-07 #1148.
- The default loads every language and keeps working for names of any language. Choosing a language narrows it since 3.0's phase 3 (#753): a pack settles only the clashes where its language has a vocabulary reading (`locales.VI` excepted: its fragment removes readings of Vietnamese syllables no reading in its file can settle, 2026-11-05 #1108; `locales.MY`'s fragment, 2026-11-19 #1231, was dropped the same day for a strict choice, decisions/vocabulary-collisions' #1483 entry), a strict choice reads only the chosen languages' files, `mul.toml` and native-script words' readings as a plain choice of the same languages keeps them (name readings included), and a pack's preferred reading can outrank one a shape rule derives — 2026-10-15/16; 2026-10-30 #753, file-strict; 2026-11-02 #1005 (Derek); 2026-11-07 #1148.
- `e`, `y` and `i` stay in the default; choosing a language settles their one-case fork for that language's own reading, `may_be_initial` not holding on a chosen file's conjunction, as `locales.PT`, `locales.PT_BR` and `locales.PT_PT` do for `e` — 2026-10-15/16; 2026-10-29 #753, phase 3b; 2026-10-30 #753, phase 3g.
- A patronymic field came in 3.0, as a view that names its words without emptying `family`, and the particle kinds already draw the `clan`/`patronymic` line for it: a patronymic is followed by a parent's name, a clan prefix by a family name the lineage shares — 2026-10-15/16; 2026-10-19 #749; 2026-10-28 #754 (Derek); landed as rules/R9, 2026-10-29 #754, sub-phase 4c.
- A shipped pack that is only a choice of languages declares no `DEVIATES`, its surface the words its choice changes; `ga` turns on `nic`, `mhic`, `mic` and `uí` as clan particles, `gd` `nic`, and `pt-BR` `sb` as Sobrinho's spelling, while the single letters `f` and `n` are excluded, the pack included, the letter abbreviating a surname more often than the agnomen in the filings that write it — 2026-10-30 #753, phase 3h.
Expand Down Expand Up @@ -97,7 +97,7 @@ Open: [#1145](https://github.com/derek73/python-nameparser/issues/1145), the dis
3. Detailed kinds are recorded during the migration even where every kind of a category behaves alike at first; generation and credential are separate kinds (#326).
4. A language file means "the words the parser might encounter in names in that language" — what occurs in names and records written in it, including particles common there through immigration — not words of that language's etymology.
5. The default loads every language and keeps working for names of any language, as today; choosing a language narrows it.
6. Packs prefer and strict packs restrict: a pack settles only the clashes where its language has a VOCABULARY reading, and a strict variant also drops other languages' name-level readings. (Excepted for two packs, 2026-11-05 #1108, below: `locales.VI`'s fragment removes readings of Vietnamese syllables where vi.toml holds none; and `locales.MY`'s of Burmese syllables, decisions/vocabulary-collisions' 2026-11-19 #1231 entry.)
6. Packs prefer and strict packs restrict: a pack settles only the clashes where its language has a VOCABULARY reading, and a strict variant also drops other languages' name-level readings. (Excepted for one pack, 2026-11-05 #1108, below: `locales.VI`'s fragment removes readings of Vietnamese syllables where vi.toml holds none. `locales.MY`'s removed Burmese syllables' readings from 2026-11-19 #1231 until #1483 the same day, which read a wholly Burmese list strictly instead, decisions/vocabulary-collisions.)
7. `e`/`y`/`i` stay in the default, at least to start; choosing a language settles the one-case fork.
8. A patronymic field belongs in 3.0.
9. Gender is recorded only where a word gives a definitive clue.
Expand All @@ -106,7 +106,7 @@ Open: [#1145](https://github.com/derek73/python-nameparser/issues/1145), the dis
12. Bearer counts are structured provenance (source + count), never used to compute a reading: two data sets deciding one reading would make the decision unclear. A new census flags changed names for review.
13. `Dean Smith` reads given `Dean`, as today.
14. Order and shape are separate: a language supplies only a default order; the shapes (where titles, suffixes, particles and commas sit) belong to each order and live in the core.
15. Vocabulary readings settle a clash; name readings only keep the gate on. (Bent for two packs, 2026-11-05 #1108, below: `locales.VI`'s fragment removes the particle, connective and credential readings of Vietnamese syllables, the settling no reading in vi.toml can do; and `locales.MY`'s the particle readings of Burmese syllables and `do`'s credential, decisions/vocabulary-collisions' 2026-11-19 #1231 entry.)
15. Vocabulary readings settle a clash; name readings only keep the gate on. (Bent for one pack, 2026-11-05 #1108, below: `locales.VI`'s fragment removes the particle, connective and credential readings of Vietnamese syllables, the settling no reading in vi.toml can do. `locales.MY`'s removed the particle readings of Burmese syllables and `do`'s credential from 2026-11-19 #1231 until #1483 the same day, decisions/vocabulary-collisions.)
16. The contested-head rule covers only words outside `titles` today (`dean`, `justice`, `major`); a title that is also a given name today is decided one word at a time, like the graf class (decisions/salutation-titles).
17. `cased` and `same_as` replace a "canonical" spelling, and `cased` replaces `capitalization_exceptions`; both default to the word, and a reading's `native` spelling is for surfacing.
18. `acronym` is a reading property, replacing the `suffix_acronyms`/`suffix_words` split; `expands` records the meaning an entry was added for, not every meaning.
Expand Down
4 changes: 2 additions & 2 deletions docs/design/mechanisms.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,9 @@ rules/O8's letters are the same shape at the family's other edge: the family wri

**Problem shape.** Language-specific behavior needs a home that cannot drift from the core.

**Contract statement.** A locale pack is pure data — a choice of languages, a Lexicon fragment of ADDITIONS (two packs' of removals, `locales.VI`'s and `locales.MY`'s, below) and a Policy patch — applied by parser_for, a shipped pack's patch compiled from its language file's `[rules]` table where one is written, each key the `Policy` field of its name: the packs' languages union with the base's recorded choice into one choice, recorded on the `Lexicon`, which selects among the base's shipped readings by the file each sits in, the fragments join in pack order and the caller's lexicon after them, its own readings applying after the choice, and the patches fold in order (set-valued fields union, `script_orders` merges by script, scalars override); packs contain no code paths of their own. A vocabulary pack's deviations are derived from the reading index, the words whose compiled readings its choice changes; a policy or segmentation pack declares its own in its docstring and `DEVIATES`.
**Contract statement.** A locale pack is pure data — a choice of languages, a Lexicon fragment of ADDITIONS (one pack's of removals, `locales.VI`'s, below) and a Policy patch — applied by parser_for, a shipped pack's patch compiled from its language file's `[rules]` table where one is written, each key the `Policy` field of its name: the packs' languages union with the base's recorded choice into one choice, recorded on the `Lexicon`, which selects among the base's shipped readings by the file each sits in, the fragments join in pack order and the caller's lexicon after them, its own readings applying after the choice, and the patches fold in order (set-valued fields union, `script_orders` merges by script, scalars override); packs contain no code paths of their own. A vocabulary pack's deviations are derived from the reading index, the words whose compiled readings its choice changes; a policy or segmentation pack declares its own in its docstring and `DEVIATES`.

**How it works.** What is policy for every language (an order constant) is policy, not pack data; packs are lowercase modules exposing uppercase constants; a pack error is wrapped with the pack's code (rule D2). A choice changes the base's readings only by selection, never by a list of removals (a pack's fragment may remove, as a caller's lexicon may, and two shipped packs' do: `locales.VI` takes out the particle, connective and credential readings of the Vietnamese syllables its order would otherwise chain or cut off, `Van` in `Nguyen Van Anh`, a settling no reading in its file can do, decisions 6 and 15 of decisions/vocabulary-model, bent there on 2026-11-05 #1108; `locales.MY` the particle readings of the Burmese syllables, `San` in `Aung San Win`, and `do`'s credential reading, which the particle chain had kept from ending `AUNG SAN DO`, decisions/vocabulary-collisions, 2026-11-19 #1231): a chosen language's `default = false` readings join; on a word a chosen language holds a vocabulary reading of, other languages' vocabulary readings leave, save `mul.toml`'s; and a chosen language's conjunction loses `may_be_initial`, its clash with the initial being a shape reading a preference outranks, which is how a `pt` choice drops `e` from `conjunctions_ambiguous` (decisions/vocabulary-model, 2026-10-27 #753, items 1, 2 and 7; built 2026-10-29, phase 3b). A strict choice, `parser_for(..., strict=True)`, selects by file alone: only the chosen files, `mul.toml` and native-script words' readings as a plain choice of the same languages keeps them (name readings included) compile, `und.toml`'s readings leaving with every other file's (decisions/vocabulary-model, 2026-10-30 #753, file-strict; built 2026-10-31, phase 3j; `mul.toml` kept since 2026-11-02 #1005). So a bad default is routed around only by choosing the language whose reading is right, which is why #342-class fixes still change shipped vocabulary. The choice filters the base's shipped readings and the caller's own `add` and `remove` calls apply after it, so a choice never drops a caller's word, and one that clashes with a reading the choice turns on is refused at `parser_for`, naming the edit; a lexicon built from `Lexicon.empty()` holds no shipped reading, so a choice turns none on in it; a pack choosing no language leaves the base's exactly as it was. The choice is recorded on the `Lexicon`, so `parser_for(EN, base=parser_for(PT))` chooses both, as `parser_for(PT, EN)` does (decisions/vocabulary-model, 2026-11-02 #754, the `Lexicon` surface, items 3 and 4; built 2026-11-02, sub-phase 4i-c). Pure data means a pack can be audited: a vocabulary pack's whole content is its tag, but what it changes reaches other files too, prefer dropping their readings of its words (a `de` choice drops `ca.toml`'s conjunction `i`), so the audit is the derived surface, `changed_words`, not the pack's file alone. A country pack is the same data with a region tag: `locales.ES_AR` chooses `es-AR`, which selects `es.toml` by ancestry until a reading is Argentina's own, names its language's `[rules]` (`rules_patch("es")`) rather than inheriting them, and carries its own lexicon fragment, so stacked on its language's pack it reads as itself where its fragment holds the language pack's (decisions/O6, 2026-11-04). A country that turns on a rule its language leaves off writes the table in a file of its own, which may hold nothing else: `locales.PT_BR` reads `pt-BR.toml`'s and `locales.PT_PT` `pt-PT.toml`'s, while `locales.PT` reads none, and the two country packs share one lexicon fragment (decisions/O6, 2026-11-19).
**How it works.** What is policy for every language (an order constant) is policy, not pack data; packs are lowercase modules exposing uppercase constants; a pack error is wrapped with the pack's code (rule D2). A choice changes the base's readings only by selection, never by a list of removals (a pack's fragment may remove, as a caller's lexicon may, and one shipped pack's does: `locales.VI` takes out the particle, connective and credential readings of the Vietnamese syllables its order would otherwise chain or cut off, `Van` in `Nguyen Van Anh`, a settling no reading in its file can do, decisions 6 and 15 of decisions/vocabulary-model, bent there on 2026-11-05 #1108; `locales.MY`'s fragment did the same for Burmese syllables until a strict choice of `my` replaced it, which settles those clashes by reading no other language's file, decisions/vocabulary-collisions, 2026-11-19 #1231 and #1483): a chosen language's `default = false` readings join; on a word a chosen language holds a vocabulary reading of, other languages' vocabulary readings leave, save `mul.toml`'s; and a chosen language's conjunction loses `may_be_initial`, its clash with the initial being a shape reading a preference outranks, which is how a `pt` choice drops `e` from `conjunctions_ambiguous` (decisions/vocabulary-model, 2026-10-27 #753, items 1, 2 and 7; built 2026-10-29, phase 3b). A strict choice, `parser_for(..., strict=True)`, selects by file alone: only the chosen files, `mul.toml` and native-script words' readings as a plain choice of the same languages keeps them (name readings included) compile, `und.toml`'s readings leaving with every other file's (decisions/vocabulary-model, 2026-10-30 #753, file-strict; built 2026-10-31, phase 3j; `mul.toml` kept since 2026-11-02 #1005). So a bad default is routed around only by choosing the language whose reading is right, which is why #342-class fixes still change shipped vocabulary. The choice filters the base's shipped readings and the caller's own `add` and `remove` calls apply after it, so a choice never drops a caller's word, and one that clashes with a reading the choice turns on is refused at `parser_for`, naming the edit; a lexicon built from `Lexicon.empty()` holds no shipped reading, so a choice turns none on in it; a pack choosing no language leaves the base's exactly as it was. The choice is recorded on the `Lexicon`, so `parser_for(EN, base=parser_for(PT))` chooses both, as `parser_for(PT, EN)` does (decisions/vocabulary-model, 2026-11-02 #754, the `Lexicon` surface, items 3 and 4; built 2026-11-02, sub-phase 4i-c). Pure data means a pack can be audited: a vocabulary pack's whole content is its tag, but what it changes reaches other files too, prefer dropping their readings of its words (a `de` choice drops `ca.toml`'s conjunction `i`), so the audit is the derived surface, `changed_words`, not the pack's file alone. A country pack is the same data with a region tag: `locales.ES_AR` chooses `es-AR`, which selects `es.toml` by ancestry until a reading is Argentina's own, names its language's `[rules]` (`rules_patch("es")`) rather than inheriting them, and carries its own lexicon fragment, so stacked on its language's pack it reads as itself where its fragment holds the language pack's (decisions/O6, 2026-11-04). A country that turns on a rule its language leaves off writes the table in a file of its own, which may hold nothing else: `locales.PT_BR` reads `pt-BR.toml`'s and `locales.PT_PT` `pt-PT.toml`'s, while `locales.PT` reads none, and the two country packs share one lexicon fragment (decisions/O6, 2026-11-19).

**Lives in.** nameparser/locales/ (packs), nameparser/_parser.py (parser_for, the one applier), nameparser/_lexicon.py (the compile under a recorded choice, `_chosen_pool` and `_built`), nameparser/_reading_index.py (the selection, `choose`, and the derived surface, `changed_words`), nameparser/_locale.py (`rules_patch`, a file's compiled `[rules]` as a patch) and tools/vocab/build.py (`RULE_KEYS`, the rules a file may turn on, and `PACK_RULES`, the files the shipped packs read; decisions/vocabulary-model, 2026-10-29 4f). A rule a file turns on is a `Policy` field; a new rule kind is a core change, never code in a pack: a new `Policy` field (with `ADDED_IN`), a row in build.py's `RULE_KEYS` and in `_locale._RULE_VALUES`, and a mechanisms.md entry of its own for the rule kind.

Expand Down
Loading