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
7 changes: 6 additions & 1 deletion docs/design/decisions/T1-separators-not-joiners.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- An ignorable character is a separator, never removed with its neighbors joined as v1's squash_emoji and squash_bidi did: `A😀B` reads given 'A', family 'B' — 2026-07 PR #288.
- The `strip_bidi=False` half of the opt-out carries no example, by decision; with it `John‏Smith` (a right-to-left mark between the words) reads given 'John‏Smith', the mark kept — 2026-10-20 #761.
- The zero-width space (U+200B), the invisible separator (U+2063) and the byte-order mark (U+FEFF) are separators with no opt-out; the zero-width non-joiner and joiner (U+200C, U+200D), the word joiner (U+2060), the soft hyphen (U+00AD), the invisible math operators (U+2061, U+2062, U+2064) and the Mongolian vowel separator (U+180E) stay inside the word, and an invisible character the tokenizer does not handle is reported nowhere — 2026-10-24 #851; the invisible separator and the four exclusions beside it, 2026-11-02 #1018.
- A zero-width non-joiner or joiner at a word's edge stays in the token and is dropped where the word is looked up, by the vocabulary fold and the name match's fold alike: `Dr‌ John Smith` reads title 'Dr‌'; one inside a word is not dropped, declined for now — 2026-11-21 #1335.

Open: none in this file.

Expand All @@ -13,8 +14,12 @@ Open: none in this file.
- 2026-07 (v2 core, PR #288) — v1's squash_emoji/squash_bidi REMOVED the character and joined its neighbors. (v1.3.0 had no bidi handling at all: squash_bidi entered late v1 via #266, 2026-07-07, on the emoji precedent's shape.) ('A😀B' → 'AB'); v2 makes an ignorable character a separator ('A😀B' → 'A', 'B'). The unavoidable consequence of every part being an exact positioned piece of the input: with no rewriting stage, nothing can splice two half-words together.
- 2026-10-20 (Derek), #761 — the `strip_bidi=False` half of the opt-out carries no example, by decision: the example would be a name holding an invisible direction mark (`John‏Smith`, which reads given `John‏Smith` with the marks kept), and that is not worth a new policy annotation in `tests/v2/rules_doc.py`'s registry.
- 2026-10-24 (Derek), #851 — the zero-width space and the byte-order mark join T1's set, unconditionally, like whitespace and the katakana middle dot (rules/T2): neither strip switch fits, since neither is an emoji or a direction control, and no caller would keep either. Measured over every committed corpus and the eight local corpora on 2026-10-24: U+200B stands only in `tw-donors`, at the start of 520 of its 308,667 names, each of which read `given` where its twin without the character reads `family` (`​王小明`), so splitting there moves those 520 and nothing else. U+FEFF stands in 12 `jrc-names` spellings, each beside the space between two words (`Jerome Kerviel`), web text rather than a stray byte-order mark at a field's start; separating there changes no role and takes the character out of the field. Beside the interpunct the two read as whitespace does, not as a stripped direction mark (`威廉·​莎士比亚` reads as `威廉· 莎士比亚`): no corpus holds the combination, and the simpler rule won.
- Excluded: the zero-width non-joiner and joiner, which decide how the letters beside them join and stand inside Persian (Arabic-script), Devanagari, Malayalam and Kannada names in the corpora (thousands between letters in `nepal-candidates` alone); about 575 of them stand at a word's edge (a run of joiners counted at an edge when whitespace or the string's edge is beside it), where they join nothing (`Antonio ‌Negri`), and are left to the caller. The word joiner, whose meaning is no break. The soft hyphen, mostly inside a word: of the 66 names holding one, 52 are an accented í decoded with the wrong encoding (`NATALíCIO`, and `Pri­ncipe` without the `Ã`), 10 are typesetting hyphens at a syllable break (`Puig­demont`), and 4 end the name (`Ayman al-Zawahiri­`, read with the hyphen kept in the family); none is the parser's to repair.
- Excluded (superseded in part 2026-11-21, #1335: an edge joiner stays in the token but is dropped where the word is looked up): the zero-width non-joiner and joiner, which decide how the letters beside them join and stand inside Persian (Arabic-script), Devanagari, Malayalam and Kannada names in the corpora (thousands between letters in `nepal-candidates` alone); about 575 of them stand at a word's edge (a run of joiners counted at an edge when whitespace or the string's edge is beside it), where they join nothing (`Antonio ‌Negri`), and are left to the caller. The word joiner, whose meaning is no break. The soft hyphen, mostly inside a word: of the 66 names holding one, 52 are an accented í decoded with the wrong encoding (`NATALíCIO`, and `Pri­ncipe` without the `Ã`), 10 are typesetting hyphens at a syllable break (`Puig­demont`), and 4 end the name (`Ayman al-Zawahiri­`, read with the hyphen kept in the family); none is the parser's to repair.
- Accepted (Derek, 2026-10-24, PR #874 review): the two do not count as a space where a quote or a maiden marker is recognized, which happens before words are divided and tests for whitespace, so a glued quote is no nickname (`'Bob' Smith` reads given `'Bob'`) and a marker glued to its name leaves the clause a nickname (`Jane (née​Jones) Smith` reads nickname `née Jones`) — the katakana middle dot's shape, pinned in `tests/v2/cases.py` as `marker_divided_by_a_nakaguro_keeps_the_clause_a_nickname`. `ParsedName.replace()` and the v1 setters split a value at whitespace only, as for the middle dot and emoji. A zero-width space after a hyphen, a line-break hint in typeset text, divides the name (`Mary-​Jane Smith` reads given `Mary-`, middle `Jane`, where master kept `Mary-​Jane`). No corpus holds a zero-width space or byte-order mark inside a delimited clause or after a hyphen, so widening the quote and marker tests was declined as machinery for an unwritten shape.
- Declined: an ambiguity reporting an invisible character the tokenizer leaves in a word. An ambiguity records a reading the parse had to choose; this is a fact about the data, which the caller can find as easily as the parser can. Declined too: a cleanup recipe in the user docs — cleaning input is the caller's job, and the docs would own it.
- 2026-11-02 (Derek), #1018 — THE INVISIBLE SEPARATOR JOINS THE ZERO-WIDTH SPACE: U+2063, INVISIBLE SEPARATOR, separates under every policy as U+200B and U+FEFF do, so `John⁣Smith` reads given 'John', family 'Smith' where it read given 'John⁣Smith'; found comparing the tokenizer with name_tamer's, which strips it beside U+200B, U+FEFF, the joiners and U+180E. It is the one character beside the #851 pair whose Unicode name and use say separator (in mathematical text it marks the comma between invisible indices), and every shape #851 settled for the zero-width space holds for it unchanged: it reads as whitespace beside the interpunct, does not count as a space where a quote or a maiden marker is recognized (`Jane (née⁣Jones) Smith` reads nickname 'née Jones'), and divides a hyphenated name after its hyphen. No real name holds it: none of the 13 local corpora's `raw.jsonl` holds U+2063, nor U+2061, U+2062, U+2064 or U+180E, and of the 16 committed JSONL files only `corpus_rules.jsonl` and `snapshot.jsonl` do, each holding U+2063 once, in rules/T1's example `John⁣Smith` (`grep -c` over the UTF-8 bytes, 2026-11-02), so the change moves no measured name and is robustness against text pasted from documents.
- Excluded: the invisible math operators U+2061 FUNCTION APPLICATION, U+2062 INVISIBLE TIMES and U+2064 INVISIBLE PLUS, which join their operands rather than separate words, and U+180E MONGOLIAN VOWEL SEPARATOR, which decides the shape of the Mongolian letters beside it, as the joiners #851 excluded decide how theirs join; name_tamer strips U+180E, and stripping it would change how a Mongolian name is written. Each stays inside the word, a row of `test_joiners_and_soft_hyphen_stay_inside_the_word`.
- 2026-11-21, #1335 — AN EDGE JOINER IS DROPPED WHERE A WORD IS LOOKED UP, decided: `_lexicon._normalize` strips a ZWNJ (U+200C) or ZWJ (U+200D) at a word's edge with the edge full stops, to a fixed point, in a non-ASCII word only, and `_lexicon._fold`, the name match's fold, drops one standing beside whitespace, a hyphen or the text's edge, so the two folds read a word alike (the hyphen because the match folds a hyphenated family name's halves apart, and `Smith‌-Jones` read `part-of-other` against `Smith-Jones` until review counted it) (#1331's tatweel fix first changed `_normalize` alone, and the match read `محمـــد` and `محمد` as a listed spelling no list held, found by review). The token keeps the character, as #851 kept it: Malayalam writes a ZWJ at a word's end on purpose, an older spelling of its final consonants, and a field holds what the caller wrote. `Dr‌ John Smith` reads title 'Dr‌', where 1.4.0 through 3.1.0 read given 'Dr‌'; `John Smith Jr‍` reads suffix 'Jr‍'; the issue's `مهندس‌ علی رضایی` reads title `مهندس‌`. A word a caller adds with an edge joiner is stored without it, so a `Lexicon` pickled holding one is refused on load, as #1151's tatweel was.
- Measured 2026-11-21 against master 507a64eb over every local corpus's `corpus.jsonl` (18 corpora; three hold a name with an edge joiner), counting NAMES, where #851's 575 counted joiner runs: a name holds an edge joiner where a run of ZWNJ or ZWJ has whitespace or the string's edge beside it (`(?<!\S)[\u200c\u200d]+|[\u200c\u200d]+(?!\S)`, #851's definition), each such name was parsed in both trees, and each field compared with its edge joiners removed: `jrc-names` holds 362 such names (Arabic script 248, Malayalam 89, Bengali 19, six others), of which the change moves 33, all Arabic script; `nepal-candidates` 94 (Devanagari) and `orcid-researchers` 53 (Latin 31, a word of nothing but joiners 18, Hangul 3, Arabic 1), of which it moves none. No committed corpus name moves (the snapshot is unchanged). Removing the edge joiners from the TEXT would move 25 more (8 Nepali and 17 ORCID names, none in `jrc-names`), which a lookup fix does not reach, in two shapes left open: a word that is nothing but joiners standing as a name word (`Jane Doe ‍`, 22 names, 8 Nepali and 14 ORCID, 2 of the Nepali ones holding a run of joiners left standing once the bracketed nickname after it is taken out; the joiner takes the family and `Doe` reads middle), a tokenizer question this entry does not settle; and a leading joiner on a Hangul word (3 ORCID names), which keeps the name from reading as wholly Hangul for rules/W4's order, the script test reading the word with its joiner.
- The shape tests see the joiner too, where the vocabulary fold no longer does: a period abbreviation (`Insp.‌ John Smith` reads given), the unlisted dotted and capitals credentials, the numeral `VI`, a trailing title with its period read by shape (`John Smith Prof.‌`), a glued honorific (`김민준씨` with a ZWNJ after it is not peeled), and rules/W1's surname split (`김민준` with one after it stays whole), each of which reads the token's text. No measured name holds one of those with an edge joiner, so none is changed here.
- Declined, for now: a joiner inside a word that the vocabulary spells without one, or with one where the name is typed without (`آیتالله` against the listed `آیت‌الله`). Between letters the character is spelling, and folding it away would equate spellings a Persian writer keeps apart; no measurement asked for it.
5 changes: 3 additions & 2 deletions docs/design/rules/T1-separators-not-joiners.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@

**Accepted:**

- A zero-width joiner or non-joiner stays inside the word even at its edge, where it joins nothing, since between letters it decides how they join.
- A zero-width joiner or non-joiner stays inside the word even at its edge, where it joins nothing, since between letters it decides how they join; at the edge the word is looked up without it, so a listed word typed with one is still that word.
```
"Antonio ‌Negri" → family="‌Negri"
"Dr‌ John Smith" → title="Dr‌"
```
- A zero-width space, invisible separator or byte-order mark does not count as a space where a quote or a maiden marker is recognized, as the katakana middle dot does not (rules/T2): a marker glued to its name by one leaves the clause a nickname.
```
Expand All @@ -41,4 +42,4 @@

---
**Signal:** character: whitespace, and characters that carry no name content
**history:** decisions/T1 · **implemented:** nameparser/_pipeline/_tokenize.py
**history:** decisions/T1 · **implemented:** nameparser/_lexicon.py, nameparser/_pipeline/_tokenize.py
1 change: 1 addition & 0 deletions docs/release_log.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Release Log

nameparser 3.2 is under development.

- **Fix a title or suffix typed with a zero-width non-joiner or joiner at its edge, which read as a name word.** ``parse("Dr\u200c John Smith")`` gives title ``Dr\u200c``, given ``John``, where 1.4.0 through 3.1.0 gave given ``Dr\u200c``, middle ``John``; the Persian ``مهندس`` typed with a ZWNJ after it is the title the same way, and the name match reads a name typed with one as ``folded``. The field keeps the character, and one inside a word is still part of its spelling. A ``Lexicon`` pickled with a word added with one at its edge is refused on load. :issue:`1335`
- **Read Ra as a Korean family name and given name, not only as a credential and a title.** ``parse("Sang Hak Ra")`` gives middle ``Hak``, family ``Ra``, where 1.4.0 through 3.1.0 gave family ``Hak``, suffix ``Ra``; ``RA`` ending a name after a comma in a name of mixed case, or written ``R.A.``, is still the credential, while ``Ra`` alone after a family comma (``Kim, Ra``), ``RA`` opening the part after a family comma in a name written wholly in capitals (``KING, RA``), ``RA`` in the given part after a family comma ahead of a name word (``Smith, RA John``) and ``RA`` opening a German name (Rechtsanwalt) are now the given name. :issue:`1483`
- **Keep Cheikh and Sultan as given names under a strict Arabic or Malay choice.** With ``languages=frozenset({"ar"})`` chosen and ``strict=True``, ``Cheikh Kaddari`` gives given ``Cheikh``, family ``Kaddari``, where 3.0.0 through 3.1.0 gave title ``Cheikh``, given ``Kaddari``; ``Sultan Zulkarnain`` under a strict ``ms`` choice reads given ``Sultan`` the same way. The default and every plain choice read both as before. :issue:`1463`
- **Read the Cyrillic doctorate д-р ending a name as a credential, and the Bulgarian д.м. under a Bulgarian choice.** ``parse("Іван Петренко д-р")`` gives family ``Петренко``, suffix ``д-р``, where 1.4.0 through 3.1.0 gave middle ``Петренко``, family ``д-р``; in front of the name ``д-р`` stays the title, and after a comma it is the suffix too (``Іван Петренко, д-р``). With Bulgarian chosen (``languages=frozenset({"bg"})``), ``доц. д-р Мария Петрова, д.м.`` gives title ``доц. д-р``, family ``Петрова``, suffix ``д.м.``; by default it gives given ``д.м.``, family ``доц. Мария Петрова``, suffix ``д-р``, where 1.4.0 through 3.1.0 kept ``д-р`` in the family. :issue:`1128`
Expand Down
4 changes: 4 additions & 0 deletions nameparser/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ Compose the WHOLE predicate, not one half: `is_initial` is a shape ANDed with th

A fold that drops marks by script, casefolds and removes punctuation is idempotent only if every step's output is something the steps before it would already have handled, and a sweep of single code points cannot show it: the input that breaks it is a letter FOLLOWED by a mark. #1221's `_match._fold` (`_lexicon._fold` since #1267, which the familiar-form index shares) failed three ways, each found by review rather than by its code-point test: the micro sign U+00B5 and U+2183 casefold into Greek and Latin, so a mark read as spelling before casefolding became an accent after it; a full stop or apostrophe before a mark left the mark on the letter before it once removed; and U+0149 casefolds to an apostrophe and `n`. The first fix, casefolding before reading the marks, moved 63 Greek iota-subscript letters (`ᾳ` to `αι` where it had been `α`), which no corpus holds. What held: read a letter's script as written AND casefolded, remove the punctuation both before the marks are read and after casefolding, and sweep every assigned code point with a mark after it behind a Latin letter, a hyphen and a Devanagari letter, plus a hyphen and a space on either side (`test_fold_is_idempotent_and_keeps_hyphens_over_every_code_point`). Compare any reordering against the old fold over that sweep, not over a corpus.

### A character the vocabulary fold strips is still seen by the shape path

What `_lexicon._normalize` strips from a word (the edge full stops, the tatweel since #1151, a ZWNJ or ZWJ at the word's edge since #1335), the shape tests still read in the token's text, and the name match reads through its own fold. So a stripped character is three questions: does `_lexicon._fold` drop it alike (#1331's tatweel fix changed `_normalize` alone, and the match read the two spellings as a listed one no list holds; `test_a_joiner_at_a_words_edge_is_no_difference` and `test_a_tatweel_stretching_a_name_is_no_difference` are the rows to extend), what does it store from a caller's `add()` and does that pickle round-trip (`test_a_word_added_with_an_edge_joiner_is_stored_without_it`; an older pickle holding the character is refused on load), and which shape predicates still see it. #1335's sweep of every comma shape, order and spelling found the vocabulary path consistent and the shape path not: `Insp.` with a ZWNJ after it reads given where `Insp.` is the title (H2's period abbreviation), and the unlisted dotted and capitals credentials, the numeral `VI`, a trailing title read with its period (`John Smith Prof.`), a glued honorific (`김민준씨`) and rules/W1's surname split (`김민준`) diverge the same way. And the match cuts a family name at its hyphens and folds each half, so a fold's notion of a word edge must count a hyphen: #1335's first `_fold` counted whitespace only, and `Smith-Jones` with a ZWNJ before the hyphen read `part-of-other`, found by review. No measured name holds one of those, so they were left; a change that reads one of those shapes puts an edge-joined spelling in its grid, and a change that strips another character from the fold runs the same three questions.

### An apostrophe or a hyphen inside a word

An apostrophe inside a word is an elision dividing a prefix from a name (`O'Brien`, Cyrillic `О'Коннор`), a letter of the word's own spelling (the Ukrainian and Belarusian apostrophe before a vowel, `Мар'яна`; Latin `Dem'yan`, Kikuyu `Ng'ang'a`), or a modifier letter that `\w` reads as a word character (U+02BC, the modifier letter apostrophe, and U+02BB, the okina). Case repair kept the third whole and divided a word at the other two until #1214 read the Ukrainian parliament, which joined the Cyrillic case of the second (the Latin one still divides, `Dem'Yan`), so a change to how a word is divided runs a row of each, in `'`, U+2018 and U+2019 and in U+02BC. A hyphen changes a particle's writing the same way: spaced, Dutch writes `ter Horst`; joined, `Ter-Petrosyan` and `Al-Ahmari` are written as their bearers write a name (#1224), save an elided particle, whose listed spelling opens with an apostrophe (`'s-Gravesande`, `'t-Hart`): the walk divides a word at its apostrophe, so a change to how a hyphenated word's parts are repaired runs a row with one in the opening and an inner part (#1280). And a case mapping is the script's: Georgian Mtavruli has no title case but itself (#1223), so a repair that asks `str.capitalize()` runs a row in each cased script it reaches, Georgian, Greek and Armenian beside Latin and Cyrillic.
Expand Down
Loading