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
5 changes: 4 additions & 1 deletion docs/design/decisions/W1-unspaced-cjk-division.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
- Korean division is on by default and an unrecognized word stays whole, an unsplit name being recoverable where a wrong split is not: `김민준` → family '김', given '민준', `남궁민수` → family '남궁', `뿡민준` → family '뿡민준' — 2026-07-27 #271.
- Han division is opt-in per pack, Han text not identifying its language: `毛泽东` reads family '毛泽东' by default and family '毛' under `locales.ZH`; a listed surname is a dictionary certainty and wins before a pluggable segmenter is asked — 2026-07-29 #272.
- Japanese division is delegated to namedivider, and JMnedict is not bundled as segmentation data (the log's Declined line) — 2026-07-29 #272.
- Script classification composes its input to NFC while segmentation reads the raw text, so a decomposed name degrades to no split, never a wrong one: `김민준` typed decomposed reads family '김민준'; vocabulary matching composes too since #322, the correction inside the entry — 2026-07-29.
- Script classification composes its input to NFC while segmentation reads the raw text, so a decomposed name degrades to no split, never a wrong one: `김민준` typed decomposed reads family '김민준'; vocabulary matching composes too since #322, the correction inside the entry — 2026-07-29 (ja amendment §1a).
- A segmenter's answer scoring under 0.9 carries a SEGMENTATION report, so a statistical division reports itself and a rule-based one, scored 1.0, does not — 2026-07-29 (ja amendment §3).
- A hangul word ending in jamo that compose to no syllable is hangul to the division, so `김ᄒᆞᆫ` reads family '김', given 'ᄒᆞᆫ'; decomposed modern hangul still degrades to no split — 2026-11-05 #1087.
- `ja_segmenter` declines a token holding no kanji, so `あいさわいちろう` under `parser_for(locales.JA, segmenter=locales.ja_segmenter())` stays whole, as with no segmenter, while `山田たろう` still divides 山田 + たろう — 2026-11-08 #1193.
- `locales.ZH` and `locales.JA` are corpus alternatives; stacked, a listed Chinese surname still wins before the segmenter (`高橋一郎` divides 高 + 橋一郎 under ZH+JA as under ZH alone), and kana gating follows the script function order uses, so a wholly-katakana token never gates in — 2026-08.
Expand All @@ -27,6 +28,8 @@ Open: [#981](https://github.com/derek73/python-nameparser/issues/981) (a mainlan

- 2026-07-29 (ja amendment §1a) — script CLASSIFICATION NFC-normalizes its input (NFD katakana carries combining marks outside the block; NFD hangul decomposes to jamo, which would miss the order rule for macOS-origin names) while SEGMENTATION stays raw — chosen over offset-mapping complexity because NFD then degrades to no-split, never to a wrong split. The read-only folds are the deliberate exceptions to "nothing rewrites the text" (rules.md T Background), and neither ever enters a token. (Corrected 2026-09-10, #cjk-full-stops: this read "segmentation MATCHING stays raw" and "the one deliberate exception". Vocabulary matching composes NFC too since #322 — `_lexicon._normalize` folds every lookup and every stored entry the same way — so the folds are two, and what stays raw is segmentation proper: the surname site's membership test and the peel's tail slice, which index the token's own text. The no-split degradation is what still holds there.)

- 2026-07-29 (ja amendment §3) — A SEGMENTER ANSWER SCORING UNDER 0.9 CARRIES A SEGMENTATION REPORT, the drafted floor kept after measuring namedivider 0.4.1 over 112 names (#272 Task 5; moved here from `_script_segment._SEGMENTER_CONFIDENCE_FLOOR`'s comment by the 3.1 simplify pass). The measurement found a distribution the amendment did not anticipate: the scores are BIMODAL, not clustered near 1. A rule-based division (the kana boundary in 高橋みなみ, or a two-character name) scores exactly 1.0, while a kanji-statistics division scores a softmax over the candidate cut positions, observed in 0.23-0.68 and driven more by the name's LENGTH (median 0.61 at three characters, 0.37 at five; the softmax is over len-1 candidates) than by correctness: the wrong answers in the sample scored 0.32/0.60/0.60/0.61, straddling the correct median of 0.52. So no floor inside that band separates error from success, and the only cut the data supports is between a stated certainty and a statistical guess, which is what §3's epistemic argument asks for. 0.9 sits in the empty gap (0.68 to 1.0), far from both modes, and reads as confident for a third-party segmenter with a calibrated score too. Consequence, pinned by tests: every statistically divided name carries a SEGMENTATION report, and every rule-divided one (the kana boundary, a two-character name, namedivider's specific-name rules) carries none; `locales/ja.py` says why namedivider's 1.0 for its own two-character rule is accepted as stated. Not configurable (YAGNI). The 112-name sample was not kept: the figures are a dated snapshot under namedivider 0.4.1, which nothing in the repository re-runs (`uv.lock` pins 0.4.2 since).

- 2026-11-05 #1087 — JAMO THAT COMPOSE TO NOTHING ARE HANGUL TO THE DIVISION. The script table's HANGUL took in the conjoining jamo (decisions/nfd-shapes, same date), so a token mixing a syllable with archaic or lone jamo is wholly hangul and its surname divides: `김ᄒᆞᆫ` and `김ᄀ` moved from given whole with a given-or-family report to family '김'. Decomposed modern hangul is unchanged, the 2026-07-29 no-split degradation standing: the surname match still reads the raw core.

- 2026-08 — zh and ja packs are corpus ALTERNATIVES, one per corpus; stacking them (parser_for(ZH, JA, segmenter=...)) is for genuinely mixed data that accepts the trade: a listed Chinese surname wins before the segmenter is consulted, so 高橋一郎 still divides 高 + 橋一郎 under ZH+JA exactly as under ZH alone. Kana gating resolves through the same script function order uses, so kana-licensed composites (高橋みなみ) gate in under JA while pure-katakana tokens never do (amendment 2026-07-27: activation is per script because the ambiguity is per script).
Expand Down
6 changes: 3 additions & 3 deletions nameparser/_pipeline/_assemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,9 @@ def assemble(state: ParseState) -> ParsedName:
order=order)


_INITIAL_TAGS = frozenset({"initial"})


# rules/T7: "it reads as its letters written with a space between
# them would: the letter in the given name's place in the order is the
# given name, and the others are middle names" -- decisions/T7 (#1296)
Expand Down Expand Up @@ -916,9 +919,6 @@ def _part_letter_run(whole: Token, tokens: tuple[Token, ...],
return tokens[:at] + tuple(parts) + tokens[at + 1:], reported


_INITIAL_TAGS = frozenset({"initial"})


def _listed_run(text: str, lexicon: Lexicon) -> bool:
"""Whether the lexicon lists `text`, a run of single letters, as a
word of its own, written as it is, with its full stops: in a
Expand Down
68 changes: 13 additions & 55 deletions nameparser/_pipeline/_post_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
settling S13's members with its own (#810, #792), original also read
by R1's entry pass for a comma a set-apart clause kept; and order,
the order assign read the name under, which H1, P1's fold, P6's
attachment, P10, O1, O2, O6, O7, O8 and W5's surname pair key on rather than
attachment, P10, O1, O2, O6, O7 and W5's surname pair key on rather than
Policy.name_order (#395).
Produces: tokens with roles adjusted by the post rules (among them the
TITLE and SUFFIX roles of a set-apart clause's words, rules/S1, each
Expand Down Expand Up @@ -48,7 +48,7 @@
title_modifiers, title_styles and after_given_titles.

Implements rules S1, S13, H1, M4, P1, P6 (its no-comma site), P10, O1, O2,
O6, O7, O3 and R1 of docs/design/rules/; each is cited at its code below, and
O6, O7, O8, O9, O3 and R1 of docs/design/rules/; each is cited at its code below, and
H1/P1/O1/O2's history lives in docs/design/decisions/.
`suffix_entries` is the R1 entry pass as a state-in/state-out
function, for Parser.revise to run over a forced-role sub-parse
Expand Down Expand Up @@ -598,8 +598,7 @@ def lowercase_joiner(j: int) -> bool:
return True


def _take_trailing_initials(state: ParseState,
tokens: list[WorkToken]) -> None:
def _take_trailing_initials(tokens: list[WorkToken]) -> None:
# rules/O8: "the letters ending the name are its family name" --
# under the given-first order, with no family comma, the middle
# initials standing right before a family name written as one
Expand Down Expand Up @@ -1429,56 +1428,15 @@ def post_rules(state: ParseState) -> ParseState:
_retag(tokens, middles[0], Role.FAMILY)
_, givens, middles, families = _positions(tokens)
# rules/P6: "a particle ending the name attaches to that family
# name and is written before it" -- the no-comma site (#467).
# A comma is not the only thing that names the family; a declared
# family-first order does too, and the same listing is written
# both ways ("Jong, Anke de" and "Jong Anke de" under
# FAMILY_FIRST both give family "de Jong").
#
# Keyed on the SLOT the run landed in, not on its vocabulary.
# MIDDLE is the one position that means nothing here: middles are
# further given names, and a particle is not one. Only
# FAMILY_FIRST puts a trailing piece there --
# FAMILY_FIRST_GIVEN_LAST puts it in GIVEN, where the caller's own
# declaration says it IS the given name, and P1's site above no
# longer overrides that either.
#
# Which is why no vocabulary test appears here and none is wanted.
# The comma path needs one because a comma cannot separate the
# Dutch reading from the Vietnamese; the declared ORDER can, when
# the caller declares the right one for the name: "Beethoven
# Ludwig van" under FAMILY_FIRST gives family "van Beethoven"
# though `van` is ambiguous vocabulary, and "Nguyen Thi Van" under
# FAMILY_FIRST_GIVEN_LAST keeps given "Van" though the same word
# is in the same set. (Under the WRONG order each loses: the
# Vietnamese name read as FAMILY_FIRST gives family "Van Nguyen".
# rules/P6 records that as accepted -- it is one order, not
# both.) A never-given test here would have excluded every
# ambiguous particle -- von, di, da, del, le and `van` itself,
# the flagship word of the listing this rule is named for.
#
# NO RE-LAYOUT, and that is a property of ONE order rather than a
# simplification: under FAMILY_FIRST the roles run family, given,
# middle, middle..., so dropping a trailing MIDDLE leaves every
# other piece's role untouched. It is not true of
# FAMILY_FIRST_GIVEN_LAST (family, middle..., given) and not true
# of the default order, which is why this site tests the order
# rather than trusting the slot to imply it -- review found the
# first draft firing on 52 default-order names, where a
# conjunction stops a particle's forward chain and leaves it
# standing in a middle ("Maria Luisa y de la Cruz"). An earlier
# draft still (#466) removed a piece and re-laid the leftover out,
# which lost a given name outright on "van Berg Jan de" and
# promoted a post-nominal into the given slot on
# "Berg Jan Jr. de"; neither is reachable without a re-layout.
#
# The family must still hold a base of its own -- R2's invariant,
# that a non-empty family has a non-empty base, not a ban on
# particle-before-particle. Without it "van Berg Jan de" reports
# family 'de van', whose words R2 reads as ordinary name words,
# and no rule reorders those. It does NOT stop a second particle
# joining a family that merely OPENS with one: "de Mesnil Jan de"
# gives 'de de Mesnil', which keeps its base and is accepted.
# name and is written before it" -- the no-comma site, where a
# declared family-first order names the family as a comma does.
# Keyed on the slot, not the vocabulary: a MIDDLE is the one slot
# meaning nothing here, and dropping a particle from it moves no
# other role, so no re-layout is needed; the run must also end the
# name (below). And rules/P6: "Without
# a comma, the family must hold a base of its own" -- R2's
# invariant, not a ban on a second particle ("de Mesnil Jan de"
# gives 'de de Mesnil') (decisions/P6 (#466, #467))
# every retagging block above recomputes the lists, so they are
# current here (a stale index list is the bug shape #359 fixed)
names = givens + middles + families
Expand Down Expand Up @@ -1565,7 +1523,7 @@ def post_rules(state: ParseState) -> ParseState:
capitals = (state.policy.capitals_as_family
and _family_in_capitals(state, tokens, ambiguities))
if state.policy.initials_as_family:
_take_trailing_initials(state, tokens)
_take_trailing_initials(tokens)
if state.policy.two_family_names and not capitals:
_take_second_family_name(state, tokens)
if state.policy.two_given_names:
Expand Down
Loading
Loading