From c65be2556700ee20444b0ef172a2720eded274f7 Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Sat, 21 Nov 2026 21:13:10 -0800 Subject: [PATCH 1/4] Look a word up without a ZWNJ or ZWJ typed at its edge (#1335) A zero-width non-joiner or joiner at a word's edge shapes nothing, so _normalize strips it with the edge full stops when a word is looked up or stored, and the name match's fold drops it alike. The token keeps the character, so a field still holds what the caller wrote. A joiner inside a word is untouched. Co-Authored-By: Claude Opus 5.5 --- nameparser/_lexicon.py | 30 +++++++++++++++++---- tests/v2/cases.py | 26 ++++++++++++++++++ tests/v2/pipeline/test_tokenize.py | 12 +++++++++ tests/v2/test_lexicon.py | 42 ++++++++++++++++++++++++++++++ tests/v2/test_match.py | 21 +++++++++++++++ 5 files changed, 126 insertions(+), 5 deletions(-) diff --git a/nameparser/_lexicon.py b/nameparser/_lexicon.py index 209929c75..18cd9c985 100644 --- a/nameparser/_lexicon.py +++ b/nameparser/_lexicon.py @@ -13,6 +13,7 @@ import dataclasses import functools import itertools +import re import sys import unicodedata import warnings @@ -83,6 +84,14 @@ # letter, so deleting it changes no word's identity (#1151: `الدكتــور` # is the title `الدكتور`). Token text is never rewritten. _TATWEEL = "\u0640" +# The zero-width non-joiner and joiner shape the letters on either side +# of them, so at a word's edge they shape nothing and are dropped when +# the word is looked up (#1335: `مهندس` typed with a ZWNJ after it is +# the title `مهندس`), with the edge full stops. Inside a word they stay +# (`آیت‌الله` is listed with its ZWNJ). Token text is never rewritten, +# which keeps the ZWJ Malayalam writes at a word's end. +_EDGE_JOINERS = "\u200c\u200d" +_NON_ASCII_EDGES = FULL_STOPS + _EDGE_JOINERS def _normalize(word: str) -> str: @@ -103,6 +112,8 @@ def _normalize(word: str) -> str: is what v1's lc() used, preserving which cross-spellings match. Tatweel (U+0640) is deleted, in a non-ASCII word only (#1151). + A ZWNJ or ZWJ at the word's edge is stripped with the edge full + stops, in a non-ASCII word only (#1335); one inside the word stays. NFC, since #322, and only for a non-ASCII word (ASCII is already NFC, and this runs per token on the parse path -- @@ -120,12 +131,14 @@ def _normalize(word: str) -> str: would change under its owner. v1 never re-normalized, so this only matters now that storage and match-time share one fold.""" word = word.lower() + edges = FULL_STOPS if not word.isascii(): word = unicodedata.normalize("NFC", word) if _TATWEEL in word: word = word.replace(_TATWEEL, "") + edges = _NON_ASCII_EDGES while True: - stripped = word.strip().strip(FULL_STOPS) + stripped = word.strip().strip(edges) if stripped == word: return word word = stripped @@ -719,6 +732,9 @@ def _vocab_fields(compiled: Mapping[str, Any]) -> dict[str, frozenset[str]]: #: which `_normalize` deletes too (#1151), so a name's two spellings that #: differ by one fold alike where the vocabulary and the match meet. _DROPPED = str.maketrans("", "", ".'`\u2019\u02bc\u02bb\u2018\u0640") +#: A ZWNJ or ZWJ at the edge of a word, which `_normalize` strips too +#: (#1335); one inside a word is kept, as `_normalize` keeps it. +_EDGE_JOINER = re.compile(r"(? str: the marks are read, a mark after one then attaching to the letter before it, and again after casefolding, which can write one (U+0149 `ʼn` casefolds to `ʼn`). The iota subscript U+0345 is a mark like any - other, so `ᾳ` folds to `α`. Last, the letters a keyboard lacks - are written as one types them (`_KEYBOARD`).""" + other, so `ᾳ` folds to `α`. A ZWNJ or ZWJ at a word's edge is + dropped with the full stops (`_EDGE_JOINER`), as `_normalize` drops + it. Last, the letters a keyboard lacks are written as one types them + (`_KEYBOARD`).""" if text.isascii(): # no accent, no composition, and no apostrophe but the typed # one and the backtick return text.casefold().translate(_DROPPED) - decomposed = unicodedata.normalize( - "NFD", unicodedata.normalize("NFC", text).translate(_DROPPED)) + dropped = unicodedata.normalize("NFC", text).translate(_DROPPED) + if "\u200c" in dropped or "\u200d" in dropped: + dropped = _EDGE_JOINER.sub("", dropped) + decomposed = unicodedata.normalize("NFD", dropped) kept = [] accented = False for c in decomposed: diff --git a/tests/v2/cases.py b/tests/v2/cases.py index 4cc35eed2..ffc53bbf7 100644 --- a/tests/v2/cases.py +++ b/tests/v2/cases.py @@ -1036,6 +1036,32 @@ def _check_cjk_shape_purity(self) -> None: notes="a word before the father's name (a clan name, not read " "as one) leaves the given name last, the reason the pack " "declares FAMILY_FIRST_GIVEN_LAST rather than FAMILY_FIRST"), + # #1335: a ZWNJ or ZWJ at a word's edge is dropped when the word is + # looked up, and kept in the field; each row checked against the + # 1.4.0 and 3.1.0 wheels on 2026-11-21 + Case("a_title_typed_with_a_zwnj_after_it_is_the_title", + "Dr\u200c John Smith", + {"title": "Dr\u200c", "given": "John", "family": "Smith"}, + classification="fix(#1335)", + notes="1.4.0 through 3.1.0 read given 'Dr' with its ZWNJ"), + Case("a_persian_title_typed_with_a_zwnj_after_it_is_the_title", + "\u0645\u0647\u0646\u062f\u0633\u200c \u0639\u0644\u06cc " + "\u0631\u0636\u0627\u06cc\u06cc", + {"title": "\u0645\u0647\u0646\u062f\u0633\u200c", + "given": "\u0639\u0644\u06cc", + "family": "\u0631\u0636\u0627\u06cc\u06cc"}, + classification="fix(#1335)", + notes="the issue's mohandes; 1.4.0 through 3.1.0 read it given"), + Case("a_suffix_typed_with_a_zwj_after_it_is_the_suffix", + "John Smith Jr\u200d", + {"given": "John", "family": "Smith", "suffix": "Jr\u200d"}, + classification="fix(#1335)", + notes="1.4.0 through 3.1.0 read family 'Jr' with its ZWJ"), + Case("a_title_typed_with_a_zwnj_before_it_after_a_comma", + "Smith, \u200cMrs Jane", + {"title": "\u200cMrs", "given": "Jane", "family": "Smith"}, + classification="fix(#1335)", + notes="1.4.0 through 3.1.0 read given 'Mrs'"), # #1455: the Dutch oude and ten, each row checked against the 1.4.0 # and 3.1.0 wheels on 2026-11-18 Case("a_dutch_oude_starts_the_family_name", diff --git a/tests/v2/pipeline/test_tokenize.py b/tests/v2/pipeline/test_tokenize.py index 9fadb283c..1afb50843 100644 --- a/tests/v2/pipeline/test_tokenize.py +++ b/tests/v2/pipeline/test_tokenize.py @@ -201,6 +201,18 @@ def test_joiners_and_soft_hyphen_stay_inside_the_word(ch: str) -> None: f"ab{ch}cd", "ef"] +@pytest.mark.parametrize("text", [ + "Dr\u200c John Smith", + # Malayalam writes a ZWJ at a word's end on purpose, an older + # spelling of its final consonants + "\u0d05\u0d28\u0d4d\u200d \u0d15\u0d41\u0d2e\u0d3e\u0d7c", +]) +def test_an_edge_joiner_stays_in_the_token_text(text: str) -> None: + # #1335 drops an edge joiner where a word is LOOKED UP; the token + # still holds what the caller wrote + assert " ".join(t.text for t in _tokenized(text).tokens) == text + + def test_zero_width_space_defeats_the_flank_guard_like_a_space() -> None: # #851: a separator, not a stripped mark, so beside the interpunct # it reads as whitespace does, not as U+200F does diff --git a/tests/v2/test_lexicon.py b/tests/v2/test_lexicon.py index 970c2a347..0262a8b24 100644 --- a/tests/v2/test_lexicon.py +++ b/tests/v2/test_lexicon.py @@ -196,6 +196,48 @@ def test_tatweel_is_deleted_when_a_word_is_normalized() -> None: assert _normalize("Müller") == "müller" +_ZWNJ, _ZWJ = "\u200c", "\u200d" + + +@pytest.mark.parametrize("written", [ + "مهندس" + _ZWNJ, _ZWNJ + "مهندس", "مهندس" + _ZWJ, _ZWJ + "مهندس", + "مهندس" + _ZWNJ + _ZWJ, _ZWNJ + "مهندس" + _ZWNJ, + "مهندس" + _ZWNJ + ".", "مهندس." + _ZWNJ, ". " + _ZWNJ + "مهندس", +]) +def test_an_edge_joiner_is_stripped_when_a_word_is_normalized( + written: str) -> None: + """#1335: a ZWNJ or ZWJ at a word's edge shapes nothing, so it is + stripped with the edge full stops, in any order, to a fixed point.""" + assert _normalize(written) == "مهندس" + assert _normalize(_normalize(written)) == _normalize(written) + + +def test_an_edge_joiner_strips_on_a_latin_and_a_decomposed_word() -> None: + assert _normalize("Dr" + _ZWNJ) == _normalize(_ZWJ + "Dr") == "dr" + nfd = unicodedata.normalize("NFD", "Müller") + assert _normalize(nfd + _ZWNJ) == _normalize("Müller") == "müller" + + +def test_a_joiner_inside_a_word_is_kept_and_a_lone_one_folds_away() -> None: + """A joiner between letters decides how they join (`آیت‌الله` is + listed with its ZWNJ), so it stays; a word that is nothing but + joiners folds to nothing, as a lone full stop does.""" + assert _normalize("آیت" + _ZWNJ + "الله") == "آیت" + _ZWNJ + "الله" + assert _normalize(_ZWNJ) == _normalize(_ZWJ + _ZWNJ) == "" + + +def test_a_word_added_with_an_edge_joiner_is_stored_without_it() -> None: + """Storage and lookup share the fold, so a caller's title typed with + a ZWNJ after it is the title written either way, and the lexicon + round-trips through pickle.""" + lexicon = Lexicon.default().add("Xyzt" + _ZWNJ, kind="title") + assert "xyzt" in lexicon.words(kind="title") + parser = Parser(lexicon=lexicon) + for text in ("Xyzt John Smith", "Xyzt" + _ZWJ + " John Smith"): + assert parser.parse(text).given == "John" + assert pickle.loads(pickle.dumps(lexicon)) == lexicon + + @pytest.mark.parametrize("key, value", [ ("phd", "Ph.D."), ("md", "M.D."), ("hc", "h.c"), ("ph.d", "PhD"), ("phd", "P.H.D."), ("md", "M. D."), ("dphil", "DPhil"), diff --git a/tests/v2/test_match.py b/tests/v2/test_match.py index 64d1d6dc0..ee9429548 100644 --- a/tests/v2/test_match.py +++ b/tests/v2/test_match.py @@ -361,6 +361,27 @@ def test_a_tatweel_stretching_a_name_is_no_difference() -> None: assert given.outcome is Outcome.FOLDED +@pytest.mark.parametrize("left, right", [ + ("علی\u200c رضایی", "علی رضایی"), + ("\u200dعلی رضایی", "علی رضایی"), + ("Ali\u200c\u200d Rezaei", "Ali Rezaei"), +]) +def test_a_joiner_at_a_words_edge_is_no_difference( + left: str, right: str) -> None: + """#1335: `_normalize` strips a ZWNJ or ZWJ at a word's edge, so the + match's fold does too; otherwise the vocabulary would link the two + spellings as a listed one that no list holds, as the tatweel did.""" + result = Parser().matching().check(left, right) + assert result.consistent + given = next(r for r in result.roles if r.role is Role.GIVEN) + assert given.outcome is Outcome.FOLDED + + +def test_fold_drops_a_joiner_at_a_words_edge_and_keeps_one_inside() -> None: + assert _fold("\u200cAli\u200d Reza\u200c") == "ali reza" + assert _fold("آیت\u200cالله") == "آیت\u200cالله" + + def test_fold_drops_case_accents_and_periods_but_keeps_hyphens() -> None: assert _fold("J.-P. O'Mári\u0301a") == "j-p omaria" assert _fold("María") == _fold("Mari\u0301a") == "maria" From 13cba69f5f7c32a9cf750066f81a767add55bc50 Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Sat, 21 Nov 2026 21:15:59 -0800 Subject: [PATCH 2/4] Record the edge-joiner lookup in T1, the encoding sweep and the release log (#1335) decisions/T1 gains a standing line and a 2026-11-21 entry with the corpus measurement, the shapes left open (a word of nothing but joiners, a leading joiner on a Hangul word) and the interior joiner declined for now; rules/T1's Accepted bullet says the word is looked up without an edge joiner; nameparser/AGENTS.md's encoding sweep records the three questions a character the fold strips raises. Co-Authored-By: Claude Opus 5.5 --- docs/design/decisions/T1-separators-not-joiners.md | 5 +++++ docs/design/rules/T1-separators-not-joiners.md | 3 ++- docs/release_log.rst | 1 + nameparser/AGENTS.md | 4 ++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/design/decisions/T1-separators-not-joiners.md b/docs/design/decisions/T1-separators-not-joiners.md index 579543135..5a7eb1bfa 100644 --- a/docs/design/decisions/T1-separators-not-joiners.md +++ b/docs/design/decisions/T1-separators-not-joiners.md @@ -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. @@ -18,3 +19,7 @@ Open: none in this file. - 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 or the text's edge, so the two folds read a word alike (#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 the local corpora, each name holding an edge joiner 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 31 more, 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 ‍`, 6 Nepali and 14 ORCID names, where 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 dotted and capitals credentials, the numeral `VI`, and a trailing title with its period read by shape (`John Smith Prof.‌`). 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. diff --git a/docs/design/rules/T1-separators-not-joiners.md b/docs/design/rules/T1-separators-not-joiners.md index f666e2f4c..b33644bc9 100644 --- a/docs/design/rules/T1-separators-not-joiners.md +++ b/docs/design/rules/T1-separators-not-joiners.md @@ -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. ``` diff --git a/docs/release_log.rst b/docs/release_log.rst index a37732786..2ea75040e 100644 --- a/docs/release_log.rst +++ b/docs/release_log.rst @@ -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` diff --git a/nameparser/AGENTS.md b/nameparser/AGENTS.md index e0057c3bb..33c1f2134 100644 --- a/nameparser/AGENTS.md +++ b/nameparser/AGENTS.md @@ -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 dotted and capitals credentials, the numeral `VI`, a trailing title read with its period (`John Smith Prof.`) and a glued honorific (`김민준씨`) diverge the same way. 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. From 5b6a87c5fa694e7476669abec742befa770aa35c Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Sat, 21 Nov 2026 21:23:22 -0800 Subject: [PATCH 3/4] Count a hyphen as a word's edge in the match's fold, and fill the review's gaps (#1335) The match folds a hyphenated family name's halves apart, so a fold that kept a ZWNJ before the hyphen read Smith-Jones typed with one as part-of-other against Smith-Jones; a hyphen is now an edge too. Adds rows for the dotted suffix, a title phrase, a maiden marker, a particle, a family-first order, the other comma shapes, case repair and the familiar-form index; corrects decisions/T1's count of the moves a lookup cannot reach (25, not 31), states the recipe, marks #851's exclusion superseded in part, and cites rules/T1 from _lexicon. Co-Authored-By: Claude Opus 5.5 --- .../decisions/T1-separators-not-joiners.md | 8 ++-- .../design/rules/T1-separators-not-joiners.md | 2 +- nameparser/AGENTS.md | 2 +- nameparser/_lexicon.py | 22 ++++++---- tests/v2/cases.py | 41 +++++++++++++++++++ tests/v2/test_lexicon.py | 12 +++--- tests/v2/test_match.py | 22 ++++++++++ tests/v2/test_render.py | 8 ++++ tools/differential/corpus_rules.jsonl | 1 + tools/differential/snapshot.jsonl | 1 + 10 files changed, 101 insertions(+), 18 deletions(-) diff --git a/docs/design/decisions/T1-separators-not-joiners.md b/docs/design/decisions/T1-separators-not-joiners.md index 5a7eb1bfa..165f47962 100644 --- a/docs/design/decisions/T1-separators-not-joiners.md +++ b/docs/design/decisions/T1-separators-not-joiners.md @@ -14,12 +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 or the text's edge, so the two folds read a word alike (#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 the local corpora, each name holding an edge joiner 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 31 more, 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 ‍`, 6 Nepali and 14 ORCID names, where 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 dotted and capitals credentials, the numeral `VI`, and a trailing title with its period read by shape (`John Smith Prof.‌`). No measured name holds one of those with an edge joiner, so none is changed here. +- 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 (`(? str: """Lowercase, NFC-compose, strip whitespace and EDGE full stops - (FULL_STOPS, not the ASCII period alone -- #322). Interior periods + (FULL_STOPS, not the ASCII period alone -- #322), and in a non-ASCII + word an edge ZWNJ or ZWJ with them (#1335). Interior periods survive on purpose: 'J.R.' must not collapse to 'jr' and hit the periodless vocabulary (v1 parity, pinned live 2026-07-17). Suffix-ACRONYM membership alone uses the period-free form (see @@ -732,13 +734,19 @@ def _vocab_fields(compiled: Mapping[str, Any]) -> dict[str, frozenset[str]]: #: which `_normalize` deletes too (#1151), so a name's two spellings that #: differ by one fold alike where the vocabulary and the match meet. _DROPPED = str.maketrans("", "", ".'`\u2019\u02bc\u02bb\u2018\u0640") -#: A ZWNJ or ZWJ at the edge of a word, which `_normalize` strips too -#: (#1335); one inside a word is kept, as `_normalize` keeps it. -_EDGE_JOINER = re.compile(r"(? str: the marks are read, a mark after one then attaching to the letter before it, and again after casefolding, which can write one (U+0149 `ʼn` casefolds to `ʼn`). The iota subscript U+0345 is a mark like any - other, so `ᾳ` folds to `α`. A ZWNJ or ZWJ at a word's edge is - dropped with the full stops (`_EDGE_JOINER`), as `_normalize` drops - it. Last, the letters a keyboard lacks are written as one types them + other, so `ᾳ` folds to `α`. A ZWNJ or ZWJ beside whitespace, a + hyphen or the text's edge is dropped with the full stops + (`_EDGE_JOINER`), as `_normalize` drops one at a token's edge. Last, the letters a keyboard lacks are written as one types them (`_KEYBOARD`).""" if text.isascii(): # no accent, no composition, and no apostrophe but the typed diff --git a/tests/v2/cases.py b/tests/v2/cases.py index ffc53bbf7..936d3fab1 100644 --- a/tests/v2/cases.py +++ b/tests/v2/cases.py @@ -1062,6 +1062,47 @@ def _check_cjk_shape_purity(self) -> None: {"title": "\u200cMrs", "given": "Jane", "family": "Smith"}, classification="fix(#1335)", notes="1.4.0 through 3.1.0 read given 'Mrs'"), + Case("a_dotted_credential_typed_with_a_zwnj_after_it_is_the_suffix", + "John Smith M.D.\u200c", + {"given": "John", "family": "Smith", "suffix": "M.D.\u200c"}, + classification="fix(#1335)", + notes="the acronym form; 1.4.0 through 3.1.0 read family 'M.D.'"), + Case("a_title_phrase_typed_with_a_zwnj_inside_its_run_is_the_title", + "Vice\u200c President John Smith", + {"title": "Vice\u200c President", "given": "John", "family": "Smith"}, + classification="fix(#1335)", + notes="the phrase key; 1.4.0 through 3.1.0 read given 'Vice'"), + Case("a_maiden_marker_typed_with_a_zwnj_after_it_is_the_marker", + "Jane Smith n\u00e9e\u200c Jones", + {"given": "Jane", "family": "Smith", "maiden": "Jones"}, + classification="fix(#1335)", + notes="1.4.0 through 3.1.0 read middle 'Smith née'"), + Case("a_particle_typed_with_a_zwnj_after_it_is_the_particle", + "Juan de\u200c la Vega", + {"given": "Juan", "family": "de\u200c la Vega"}, + classification="fix(#1335)", + notes="1.4.0 through 3.1.0 read middle 'de'"), + Case("a_never_given_particle_with_a_zwnj_opens_the_family_first_family", + "de\u200c Mesnil Jean", + {"given": "Jean", "family": "de\u200c Mesnil"}, + policy=Policy(name_order=FAMILY_FIRST), + classification="fix(#1335)", + notes="rules/P1's fold under a family-first order, reached by the lookup"), + Case("a_title_with_a_zwnj_after_an_empty_family_head", + ", Dr\u200c John", + {"title": "Dr\u200c", "family": "John"}, + classification="fix(#1335)", + notes="as ', Dr John' reads; 1.4.0 through 3.1.0 read given 'Dr'"), + Case("a_suffix_with_a_zwj_after_a_second_comma_was_already_the_suffix", + "Smith, John, Jr\u200d", + {"given": "John", "family": "Smith", "suffix": "Jr\u200d"}, + classification="parity", + notes="the comma's lenient suffix read never looked the word up"), + Case("a_listed_title_holding_a_zwnj_typed_with_one_after_it", + "\u0622\u06cc\u062a\u200c\u0627\u0644\u0644\u0647\u200c \u0639\u0644\u06cc \u06a9\u0631\u0645\u0627\u0646\u06cc", + {"title": "\u0622\u06cc\u062a\u200c\u0627\u0644\u0644\u0647\u200c", "given": "\u0639\u0644\u06cc", "family": "\u06a9\u0631\u0645\u0627\u0646\u06cc"}, + classification="fix(#1335)", + notes="the edge ZWNJ is dropped and the interior one kept; 1.4.0 through 3.1.0 read it given"), # #1455: the Dutch oude and ten, each row checked against the 1.4.0 # and 3.1.0 wheels on 2026-11-18 Case("a_dutch_oude_starts_the_family_name", diff --git a/tests/v2/test_lexicon.py b/tests/v2/test_lexicon.py index 0262a8b24..fc5b221f1 100644 --- a/tests/v2/test_lexicon.py +++ b/tests/v2/test_lexicon.py @@ -221,19 +221,21 @@ def test_an_edge_joiner_strips_on_a_latin_and_a_decomposed_word() -> None: def test_a_joiner_inside_a_word_is_kept_and_a_lone_one_folds_away() -> None: """A joiner between letters decides how they join (`آیت‌الله` is listed with its ZWNJ), so it stays; a word that is nothing but - joiners folds to nothing, as a lone full stop does.""" + joiners looks up as nothing, as a lone full stop does, though its + token still stands in the name (decisions/T1, 2026-11-21).""" assert _normalize("آیت" + _ZWNJ + "الله") == "آیت" + _ZWNJ + "الله" assert _normalize(_ZWNJ) == _normalize(_ZWJ + _ZWNJ) == "" def test_a_word_added_with_an_edge_joiner_is_stored_without_it() -> None: - """Storage and lookup share the fold, so a caller's title typed with - a ZWNJ after it is the title written either way, and the lexicon - round-trips through pickle.""" + """Storage and lookup share the fold, so a caller's title added with + a ZWNJ after it is the title typed with or without a joiner, and the + lexicon round-trips through pickle.""" lexicon = Lexicon.default().add("Xyzt" + _ZWNJ, kind="title") assert "xyzt" in lexicon.words(kind="title") parser = Parser(lexicon=lexicon) - for text in ("Xyzt John Smith", "Xyzt" + _ZWJ + " John Smith"): + for text in ("Xyzt John Smith", "Xyzt" + _ZWNJ + " John Smith", + "Xyzt" + _ZWJ + " John Smith"): assert parser.parse(text).given == "John" assert pickle.loads(pickle.dumps(lexicon)) == lexicon diff --git a/tests/v2/test_match.py b/tests/v2/test_match.py index ee9429548..a4cf2af30 100644 --- a/tests/v2/test_match.py +++ b/tests/v2/test_match.py @@ -365,6 +365,9 @@ def test_a_tatweel_stretching_a_name_is_no_difference() -> None: ("علی\u200c رضایی", "علی رضایی"), ("\u200dعلی رضایی", "علی رضایی"), ("Ali\u200c\u200d Rezaei", "Ali Rezaei"), + # a hyphen is an edge too, since the match folds a family name's + # halves apart (_family_words), and a given name's alike + ("Ali-\u200cReza Smith", "Ali-Reza Smith"), ]) def test_a_joiner_at_a_words_edge_is_no_difference( left: str, right: str) -> None: @@ -377,6 +380,25 @@ def test_a_joiner_at_a_words_edge_is_no_difference( assert given.outcome is Outcome.FOLDED +def test_a_joiner_before_a_hyphen_folds_alike_whole_and_by_halves() -> None: + result = Parser().matching().check("John Smith\u200c-Jones", + "John Smith-Jones") + family = next(r for r in result.roles if r.role is Role.FAMILY) + assert family.outcome is Outcome.FOLDED + assert _fold("smith\u200c-jones").split("-") == [ + _fold(h) for h in "smith\u200c-jones".split("-")] + + +def test_a_familiar_form_typed_with_an_edge_joiner_is_still_one() -> None: + """The familiar-form index files a name under its folded forms + (`_lexicon._forms`), so the joiner must fold away there too.""" + matcher = Parser().matching( + accept=Parser().matching().accept | {"familiar-form"}) + result = matcher.check("Max\u200c Smith", "Maximilian Smith") + given = next(r for r in result.roles if r.role is Role.GIVEN) + assert given.outcome is Outcome.FAMILIAR_FORM + + def test_fold_drops_a_joiner_at_a_words_edge_and_keeps_one_inside() -> None: assert _fold("\u200cAli\u200d Reza\u200c") == "ali reza" assert _fold("آیت\u200cالله") == "آیت\u200cالله" diff --git a/tests/v2/test_render.py b/tests/v2/test_render.py index a1c61f654..84bc25b6f 100644 --- a/tests/v2/test_render.py +++ b/tests/v2/test_render.py @@ -739,6 +739,14 @@ def test_capitalized_all_lower_input_v1_parity() -> None: assert [t.span for t in out.tokens] == [t.span for t in _lowercase_mac().tokens] +def test_case_repair_reads_a_word_typed_with_an_edge_joiner() -> None: + # #1335: the mask and the particle lookups fold the joiner away, and + # the repaired text keeps it + assert parse("john smith phd\u200c").capitalized().suffix == "PhD\u200c" + assert parse("juan de\u200c la vega").capitalized().family == ( + "de\u200c la Vega") + + def test_capitalized_all_upper_input() -> None: pn = _pn("JOHN SMITH", [ Token("JOHN", Span(0, 4), Role.GIVEN), diff --git a/tools/differential/corpus_rules.jsonl b/tools/differential/corpus_rules.jsonl index b7166386e..520480761 100644 --- a/tools/differential/corpus_rules.jsonl +++ b/tools/differential/corpus_rules.jsonl @@ -402,6 +402,7 @@ "Dr/Jane Smith" "Dr/MD Jane Smith" "Dr/Mrs Jane Smith" +"Dr‌ John Smith" "Duke of Edinburgh" "Dumas VI MD, Ed" "Dumas VI, Jr." diff --git a/tools/differential/snapshot.jsonl b/tools/differential/snapshot.jsonl index 1c5b15446..bd86e565e 100644 --- a/tools/differential/snapshot.jsonl +++ b/tools/differential/snapshot.jsonl @@ -1080,6 +1080,7 @@ {"name": "Dra. Andréia da Silva", "title": "Dra.", "given": "Andréia", "family": "da Silva", "initials": "A. S."} {"name": "Dra. Erika Cornelia Anna Isabelle von Brül Cabral de Melo II", "title": "Dra.", "given": "Erika", "middle": "Cornelia Anna Isabelle von Brül Cabral", "family": "de Melo", "suffix": "II", "initials": "E. C. A. I. B. C. M.", "generation": "II"} {"name": "Drífa Viðar", "given": "Drífa", "family": "Viðar", "initials": "D. V."} +{"name": "Dr‌ John Smith", "title": "Dr‌", "given": "John", "family": "Smith", "initials": "J. S."} {"name": "Duby-Blom, Gertrude", "given": "Gertrude", "family": "Duby-Blom", "initials": "G. D."} {"name": "Duke Ellington", "given": "Duke", "family": "Ellington", "initials": "D. E."} {"name": "Duke Snider", "given": "Duke", "family": "Snider", "initials": "D. S."} From 783fe9817cafb4de4b94688047b30fd7bc4e9849 Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Sat, 21 Nov 2026 21:28:26 -0800 Subject: [PATCH 4/4] Say which of decisions/T1's unreached names are Nepali (#1335) Co-Authored-By: Claude Opus 5.5 --- docs/design/decisions/T1-separators-not-joiners.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/design/decisions/T1-separators-not-joiners.md b/docs/design/decisions/T1-separators-not-joiners.md index 165f47962..a35901a4f 100644 --- a/docs/design/decisions/T1-separators-not-joiners.md +++ b/docs/design/decisions/T1-separators-not-joiners.md @@ -20,6 +20,6 @@ Open: none in this file. - 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 (`(?