diff --git a/docs/design/decisions/T1-separators-not-joiners.md b/docs/design/decisions/T1-separators-not-joiners.md index 579543135..a35901a4f 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. @@ -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 (`(? 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 @@ -103,6 +114,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 +133,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 @@ -723,6 +738,15 @@ def _vocab_fields(compiled: Mapping[str, Any]) -> dict[str, frozenset[str]]: #: below the pipeline, so the match's forms and the lexicon's pair index #: (`_forms`) read them alike; `_pipeline._vocab` reads them from here. _HYPHEN_CHARS = "-\u2010\u2011\u2012\u2013\u2212\ufe63\uff0d" +#: A ZWNJ or ZWJ beside whitespace, a hyphen or the text's edge, as +#: `_normalize` strips one at a token's edge (#1335). The hyphen counts +#: because the match cuts a family name at its hyphens and folds each +#: half (`_match._family_words`), so `Smith-Jones` with a ZWNJ before +#: its hyphen folds alike whole and by halves; one between letters is +#: kept. +_NOT_AN_EDGE = r"[^\s" + "".join(f"\\u{ord(c):04x}" for c in _HYPHEN_CHARS) + "]" +_EDGE_JOINER = re.compile( + rf"(? 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 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 # 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..936d3fab1 100644 --- a/tests/v2/cases.py +++ b/tests/v2/cases.py @@ -1036,6 +1036,73 @@ 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'"), + 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/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..fc5b221f1 100644 --- a/tests/v2/test_lexicon.py +++ b/tests/v2/test_lexicon.py @@ -196,6 +196,50 @@ 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 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 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" + _ZWNJ + " 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..a4cf2af30 100644 --- a/tests/v2/test_match.py +++ b/tests/v2/test_match.py @@ -361,6 +361,49 @@ 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"), + # 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: + """#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_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الله" + + 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" 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."}