Skip to content

Look a word up without a ZWNJ or ZWJ typed at its edge (#1335) - #1522

Merged
derek73 merged 4 commits into
masterfrom
fix/issue-1335-edge-joiner
Nov 22, 2026
Merged

derek73 merged 4 commits into
masterfrom
fix/issue-1335-edge-joiner

Conversation

@derek73

@derek73 derek73 commented Nov 22, 2026

Copy link
Copy Markdown
Owner

A zero-width non-joiner (U+200C) or joiner (U+200D) at a word's edge shapes nothing. Until now it stayed in the token, so the word missed the vocabulary. This PR drops it where a word is looked up and keeps it in the token text.

Closes #1335

What changes

  • The lookup. _lexicon._normalize strips an edge ZWNJ or ZWJ along with the edge full stops, in a non-ASCII word only, and still reaches a fixed point.
    • Dr typed with a ZWNJ after it, John Smith Jr with a ZWJ, and the issue's Persian مهندس with a ZWNJ now read as the title or suffix. 1.4.0 through 3.1.0 read them as given or family; each new tests/v2/cases.py row was checked against both wheels.
  • The token keeps the character. Malayalam writes a ZWJ at a word's end on purpose, so a field still holds what the caller wrote (test_an_edge_joiner_stays_in_the_token_text).
  • The name match folds alike. _lexicon._fold drops a joiner beside whitespace, a hyphen or the text's edge, so علی typed with a ZWNJ against علی reads folded. Master read them as a conflict.
    • Read Persian titles and Persian spellings of the Arabic ones (#1151) #1331's tatweel fix changed _normalize alone at first, and review found that the match then read two spellings as a listed one that no list held. Reverting the _fold half alone fails 4 match rows; reverting the _normalize half alone fails 16 rows.
    • The hyphen counts because the match folds a hyphenated family name's halves apart: with whitespace-only edges, Smith typed with a ZWNJ before -Jones read part-of-other against Smith-Jones (found by review; whitespace-only edges fail 2 rows). _normalize still treats a hyphen as inside the token.
  • Storage. A word a caller add()s with an edge joiner is stored without it, and the lexicon pickles. A Lexicon pickled on master holding such a word is refused on load, as Should Persian titles and Persian spellings of the Arabic ones read as titles? (دکتر محمد رضایی gives given 'دکتر') #1151's tatweel pickle was. Checked by pickling under 507a64e and loading here.
  • A joiner inside a word is untouched. The vocabulary lists آیت‌الله with its ZWNJ. Folding an interior joiner away is declined for now in decisions/T1 (separators, not joiners).

Measured (2026-11-21, against a 507a64e worktree)

Each local-corpus name holding an edge joiner was parsed in both trees, comparing fields with their edge joiners removed. Counts only: no jrc-names name is quoted here or kept outside the cache.

corpus names with an edge joiner moved by this PR moved if the joiners were removed from the text
jrc-names 362 (Arabic script 248, Malayalam 89, Bengali 19, others 6) 33, all Arabic script 33
nepal-candidates 94 (Devanagari) 0 8
orcid-researchers 53 (Latin 31, a word of only joiners 18, Hangul 3, Arabic 1) 0 17
  • No committed corpus name moves. The snapshot re-record adds one entry, rules/T1's new example, new to corpus_rules.jsonl.

  • The 25 a lookup cannot reach (the 8 and 17 in the last column) are left open, as two shapes:

    • 22 are a word of nothing but joiners standing as a name word, as in an invented Jane Doe ‍. The joiner takes the family and Doe reads middle; this is a tokenizer question.
    • 3 are Hangul names with a leading joiner (rules/W4's wholly-Hangul test reads the word with it).
  • The shape tests still see an edge joiner: H2's period abbreviation (Insp.), the unlisted dotted and capitals credentials, the numeral VI, a trailing title read with its period, a glued honorific (김민준씨), and rules/W1's surname split (김민준). A sweep found them:

    • It covered the four comma shapes × three orders × 26 spellings, with each codepoint leading and trailing, a doubled joiner, both edges and NFD, comparing each with the plain spelling.
    • 395 of 4,914 rows still differ, all on the shape path, against 2,259 on master; no row newly differs.
    • No measured name holds one of these shapes, so none is changed here.
  • Frames: identical in both trees for the reference row (229) and Smith, John (98), since both changes are C-level. The ±2% band and the serial scaling rows pass.

  • match_diff.py --base: 1,478 of 691,064 rows moved (31,412 pairs × 22 settings), only in the intended directions:

    • given conflict → folded: 110;
    • verdict False → True: 105;
    • keys: 1,394, from pairs holding a name typed with an edge joiner, whose keys lose the joiner.

    Every listed example is one of this PR's own test rows. The key guarantee holds: 0 consistent pairs share no key.

Docs

  • decisions/T1 (separators, not joiners): a standing line and a dated entry for 2026-11-21.
  • rules/T1: the Accepted bullet now says the word is looked up without its edge joiner, with an example.
  • nameparser/AGENTS.md's encoding sweep: the three questions a character the fold strips raises, and the test rows to extend.
  • A release log bullet.

Review

The PR review toolkit aspects run on this PR: code-reviewer, comment-analyzer, pr-test-analyzer, and design-docs-reviewer for docs/design/. silent-failure-hunter was skipped: the change adds no error handling.

Findings and fixes:

  • code-reviewer: a joiner before a hyphen. Fixed in 5b6a87c.
  • pr-test-analyzer: missing 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. Added.
  • design-docs-reviewer: a head note on Should a zero-width space separate words, so ​王小明 reads as 王小明 does? #851's superseded exclusion, the miscount (31 corrected to 25), the recipe, the glued honorific missing from one list, and implemented: with a citation in _lexicon. Fixed.
  • comment-analyzer: docstring wording. Fixed.

A second code-review pass over the fix commit found nothing at 80% confidence; its one wording nit is fixed in 783fe98.

🤖 Generated with Claude Code

derek73 and others added 4 commits November 21, 2026 21:13
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 <[email protected]>
…se 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 <[email protected]>
…iew'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 <[email protected]>
@derek73 derek73 added this to the 3.2 milestone Nov 22, 2026
@derek73 derek73 added bug vocabulary Fixed by a word-list entry: per-word vocabulary and language packs matching Name matching: Parser.matching(), check() and keys() non-latin-script Names written in a script other than Latin (rules/W) tokens Tokens, separators and punctuation (rules/T) labels Nov 22, 2026
@derek73 derek73 self-assigned this Nov 22, 2026
@derek73
derek73 merged commit 6ff048f into master Nov 22, 2026
14 checks passed
@derek73
derek73 deleted the fix/issue-1335-edge-joiner branch November 22, 2026 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug matching Name matching: Parser.matching(), check() and keys() non-latin-script Names written in a script other than Latin (rules/W) tokens Tokens, separators and punctuation (rules/T) vocabulary Fixed by a word-list entry: per-word vocabulary and language packs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Look a title up without a ZWNJ typed at the end of the word (Persian مهندس‌ علی رضایی gives given مهندس‌, not the title)

1 participant