Skip to content

Simplify _group.py with no reading moved - #1529

Merged
derek73 merged 4 commits into
masterfrom
refactor/simplify-group
Nov 22, 2026
Merged

derek73 merged 4 commits into
masterfrom
refactor/simplify-group

Conversation

@derek73

@derek73 derek73 commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Release checklist step 0's /simplify pass over nameparser/_pipeline/_group.py, covering the code it gained since v3.1.0 (git diff v3.1.0 -- nameparser/_pipeline/_group.py, 456 lines, chiefly rules/N4's alias take, #1164). It is quality only: no reading moves.

It touches _group.py, two tests in tests/v2/test_benchmark.py, a test in tests/v2/pipeline/test_group.py, a type annotation in tests/v2/pipeline/test_pieces.py (the renamed ClauseIndices) and a dated entry and a Standing line in decisions/parse-cost. It does not touch _vocab.py, _pieces.py, _state.py, _classify.py, _tokenize.py or _suggest.py, and none of these changes needed them.

Changes

  • A quadratic in the alias take, now linear. In the given part after a family comma, an alias stops before a title that opens the part's closing run of titles and post-nominals.
    • The old code asked this per title by scanning to the part's end, so a run of titles after an alias was quadratic.
    • _closing_run_start now finds the run's start once, walking back from the end, and asks the same predicate per piece.
    • Measured in is_title_piece calls on "Smith, Jane @ Bob " + "Dr " * k + "Xavier " + "Dr " * k: 59 at k=8 and 599 at k=32 (10.2x) on af58ca0, and 97 and 1,129 (11.6x) with the run found once per title, against 25 and 73 (2.9x) here.
    • Guard: test_titles_after_an_alias_in_the_given_part_cost_linearly. Its probe asserts that the walk found the closing run, once.
  • A C-level quadratic in a refused take. Where every alias take is refused ("a @ Jr " * n), each marker asked leading_titles of a slice of the part. That is C-level work no frame ratio sees: 7.2x to 8.5x for 4x the input on master.
    • A refused alias marker that the run stops at now bounds the run, as a take already did. _bounds_the_title_run is the run's own test, negated.
    • _clause_take's lead stand-in becomes the flag run_ended.
    • leading_titles is now asked once per part: 1 call where master made 2, 8 and 32 at 2, 8 and 32 markers.
    • Guard: test_a_refused_alias_take_asks_the_title_run_once, a count rather than a clock. A _SHAPES row was tried first, but master read within 15% of its bound on a loaded host.
  • Smaller tidies:
    • The alias boundary scan is a plain loop over one tag set, _ALIAS_ENDS (_MARKER_TAGS plus the patronymic tag), instead of a generator calling _ends_an_alias, a third spelling of the marker tags. That is two frames fewer per piece.
    • _clause_take derives its report words from the role, so words is one parameter fewer.
    • The take types MaidenTake/MaidenIndices become ClauseTake/ClauseIndices, since they carry alias takes too.
    • given becomes kind where it named a role.
    • _apply_take's taken gets a default.
    • The clause drop builds its token starts before the loop.
  • Docs:
    • The module docstring now names N4 in Consumes: (the extracted pass drops an alias marker too), Produces: and its "Implements" line.
    • _clause_take's docstring had a stray sentence; it is fixed.
    • A frame measurement in _apply_take's comment moves to a dated decisions/parse-cost entry, which also records the two scaling controls.
    • The Reads: line already matched tools/stage_reads.py --stage group: Lexicon.given_name_titles, Policy.name_order and Policy.extra_suffix_delimiters, plus _comma.decide's.

Proof that nothing moved

  • Snapshot: tools/differential/snapshot.jsonl is byte-identical (sha256 47d678ce…) and was not re-recorded.
  • Tree against master (PYTHONSAFEPATH=1, each __file__ checked):
    • What was compared: every distinct text of the committed corpus*.jsonl files plus 5,434 alias and maiden shapes (nineteen heads, among them period-shaped titles and markers, × eleven marker writings × twenty-six tails). That is 13,046 texts, each under the three orders × middle_as_family × two_family_names, comparing repr(tokens) and repr(ambiguities).
    • Result: 0 of 156,552 lines differ.
    • Controls: this PR's first commit moves 1,925 lines (161 texts; see Reviews), and planting run_ended always true moves 3,987 (334 texts).
  • After merging master (9c06606f, Simplify _tokenize.py with no reading moved #1527's tokenize pass, merged as 1990eb73): the same sweep against 9c06606f differs in 0 of 156,552 lines, and the snapshot equals master's.
  • Corpus checks: measure.py --base reports no moves in any of its 30 steps, against af58ca0 for the first commit and against 9c06606f after the merge (committed snapshot, CLDR/GND, every local snapshot, box agreement and the alike checks). Nothing shared was re-recorded.
  • Suite: 57,938 passed on 3.11; no test expectation was edited. On 3.15, the touched modules pass (28,198).
  • Serial benchmarks: uv run pytest -n0 -m serial passes 39 of 39, so the _CALL_BASELINE band holds.
  • Lint and types: ruff and mypy are clean.

Frames per parse (py3.11, each name parsed once and then counted, all in one process, af58ca0 → this branch)

name before after
Dr. Juan0001 de la Vega III (reference) 196 196
Smith, John 98 98
Jane Smith née Jones 169 169
Osman @ @ Jaki 150 150
Rahim @ Jaki bin Osman 178 174
Smith, Jane @ Bob 137 135
Smith, Jane @ Bob Dr Xavier 177 172
a @ Jr a @ Jr 258 251
Jane Smith @ Bob née Jones 223 219

The absolute counts depend on what the process parsed first; the differences do not. The 19 other names measured with each name order, comma and maiden shapes included, are unchanged. No row of the band moves, so there is no release-log bullet.

Considered and left alone

  • One helper for M2's head test, shared by _clause_take and _alias_takes' end_of_name prediction (reuse and altitude reviews). Factored exactly it moves nothing, but it adds a frame per take. The two sites also ask about different words (the prediction asks about the alias's last word), so sharing it is part of candidate 3 below, not a refactor.
  • Dropping the inline "suffix" in ptags pre-checks in front of is_suffix_piece. Each pre-check saves a frame where the tag is present, so they stay.
  • Refusing a tail part in _alias_takes before the walk (simplification review). It left _clause_take's own refusal unreachable, which codecov's project check caught, so it was reverted.

Behavior-changing candidates (not applied)

  1. The alias's title stop asking _pieces.trailing_run_start, the walk's own bound. _closing_run_start takes any title, where the walk's trailing chain takes only chain titles and after-given salutations. So a bare title is handed back, and the walk then reads it as a name word. Smith, John @ Jack Sir gives nickname Jack, middle Sir; with the shared predicate it gives nickname Jack Sir. @ Jack Lord and urf Jack Rev move the same way. rules/N4's Accepted bullet covers the current reading.

  2. The marker-behind-marker refusal on M2's side too. _alias_takes refuses an alias marker straight behind a marker of either kind, but M2's head test does not, so the maiden take counts an alias marker as the name word before née:

    • Jane Smith @ née Jones gives family @;
    • Jane Smith urf née Jones gives family urf;
    • Jane Smith née @ Jones gives maiden @ Jones.

    Moving the test into _clause_take's head would change all three and needs an amendment to rules/M2.

  3. end_of_name predicts M2's take on the pieces before the alias is removed. The real take runs after the removal and asks about a different word:

    • Jane Smith @ Bob and née Jones gives nickname Bob and, maiden Jones.
    • John Smith @ Jack Jr née Jones gives nickname Jack, suffix Jr née Jones: the marker is swallowed and the maiden name is empty.
  4. A refused first marker left as the given name. Jr. @ Bob @ Joe Smith gives title Jr., given @, family Bob, nickname Joe Smith.

Reviews

  • Simplify pass: four cleanup reviewers (reuse, simplification, efficiency, altitude). Their findings are applied above or listed as candidates.

  • PR review toolkit, first round (code-reviewer, pr-test-analyzer, comment-analyzer, design-docs-reviewer on 71bf9484):

    • code-reviewer: one reading moved. The refused bound asked is_title_piece, which a period-shaped marker fails while leading_titles takes it. Dr. Urf. Sr. Jr. @ Bob Smith read given @ where master read nickname Bob Smith. The grid held no period-shaped marker inside a title run; it now does.
    • pr-test-analyzer: the _SHAPES row's master reading was a coin flip against its bound. The title-scan test's text had no closing run, so it missed a once-per-title regression, and its probe would pass with the walk deleted.
    • comment-analyzer: docstring wording (the closing run's limits, run_ended's antecedent, "patronymic reading"), the merged starts comments, and the PR body's frame counts.
    • design-docs-reviewer: the entry head named no PR; the control covered one half of the change; the frame counts left their warm-up unstated; a Standing line was missing.
    • All fixed in 3d867b70, with codecov's project check (see above).
  • Fix commit 3d867b70 (code-reviewer): it moved no reading against af58ca0 over 231,606 systematic and 180,000 random parses across five lexicons and three orders, and the harness saw the first build's bound move 24 of them. It found:

    • the new Standing line placed under Open:;
    • a comment still naming the deleted _SHAPES row;
    • the title-scan guard's recorded ratios, which are never what fails, because the probe fails first.

    All three are fixed in 5269769e, comments and docs only, which I checked myself.

🤖 Generated with Claude Code

Release checklist step 0's pass over the code `_group.py` gained since
v3.1.0, chiefly rules/N4's alias take (#1164).

- The alias in the given part after a family comma asked, per title,
  whether every piece after it closed the part, a quadratic in a run of
  titles after an alias; the closing run's start is found once
  (`_closing_run_start`), with a frame-ratio guard.
- A refused alias take asked `leading_titles` of a slice per marker
  (C-level, quadratic); a refused marker that is no title bounds the
  run as a take does, `_clause_take`'s `lead` becoming the flag
  `run_ended`, with a `_SHAPES` row.
- The alias boundary scan is a plain loop over `_ALIAS_ENDS`
  (`_MARKER_TAGS` plus the patronymic tag) in place of `_ends_an_alias`;
  a tail part is refused before the walk; `_clause_take` derives its
  report words from the role; MaidenTake and MaidenIndices, which carry
  alias takes too, are ClauseTake and ClauseIndices; the clause drop's
  token starts are built before the loop.
- The module docstring names N4 in Consumes, Produces and Implements; a
  frame measurement in a comment moves to decisions/parse-cost.

snapshot.jsonl is byte-identical, and a policy sweep over the committed
corpora and 2,080 alias and maiden shapes reads alike against af58ca0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@derek73 derek73 added this to the 3.2 milestone Nov 22, 2026
@derek73 derek73 added the internals Refactors and parse cost with no behavior change label Nov 22, 2026
@derek73 derek73 self-assigned this Nov 22, 2026
derek73 and others added 3 commits November 22, 2026 02:12
- A refused alias marker bounds the leading title run only where the
  run stops at it, the run's own test negated (`_bounds_the_title_run`):
  the first build asked `is_title_piece`, which a period-shaped marker
  fails while the run takes it, so `Dr. Urf. Sr. Jr. @ Bob Smith` read
  given '@' where master read nickname 'Bob Smith'.
- The tail-part refusal stays in `_clause_take` alone: refusing it in
  `_alias_takes` as well left the other unreachable.
- The refused-take guard counts `leading_titles` calls (one per part)
  instead of timing a `_SHAPES` row, whose master reading sat within
  15% of the bound; the title-scan guard reads a text with a closing
  run, so finding the run once per title fails it too, and its probe
  asserts the walk found the run.
- Rows in test_group.py for where an alias stops in the given part and
  for the period-shaped marker; docstrings and comments reworded as the
  comment review asked; the decisions/parse-cost entry names #1529,
  states how its frames were counted, records both controls and gains
  a Standing line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…roup

# Conflicts:
#	docs/design/decisions/parse-cost.md
… name

- The parse-cost Standing line had landed under `Open:`; it joins the
  Standing list.
- `_clause_take`'s comment named the `refused_alias_markers` row the
  first fix round replaced with a call-count test; it names the test.
- The title-scan guard's control says its probe fails both recorded
  regressions first, the ratio backing a rewrite that renames the
  function.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@derek73
derek73 merged commit a8d997b into master Nov 22, 2026
14 checks passed
@derek73
derek73 deleted the refactor/simplify-group branch November 22, 2026 11:11
derek73 added a commit that referenced this pull request Nov 22, 2026
* Bring the contributor docs up to the 3.2 cycle

Root AGENTS.md: `_normalize`'s edges (#1335, #1151), BOUND_SECONDS_LISTED
beside the second-word phrases, NameEvidence's ADDED_IN field, and the
initial veto as a property of the script rather than of Latin alone.
nameparser/AGENTS.md: a count of name words reads roles, not tags
(#1531), and a marker written with a full stop belongs in a title-run
grid (#1529). rules/README.md's glossary and C12/C16 follow #1531's
count and C6's widening; the vocab README and the locales exemplar
table name this cycle's packs. The open-issue paragraphs in AGENTS.md
and CONTRIBUTING.md no longer say the issues are being worked on.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Bring decisions/ and mechanisms.md up to the 3.2 cycle

Two declines no decisions file recorded get dated entries: Catalan
`dels` (#1059, decided 2026-11-20) and the Bengali and Urdu honorifics
(#1469, decided 2026-11-21), with `haji` under locales.MS a Standing
line of its own. Open lines citing an issue since closed now say so
(#1268, #1231, #1178, #1179, #1468, #1149); S8's `Abd Allah` example
reads as P12's Latin join has it; P12's `عبد` count is dated; and
mechanisms.md names locales.CS beside locales.VI as a pack whose
fragment removes readings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Restore the one-word-path paragraph's history and complete the 3.2 entries

The new #1531 sentence had replaced the one that "Moving the test later"
answers to, so #1464's narrowings read as #1531's; the old sentence is
back as history and the lesson follows #1531's in the paragraph. The
#1469 Standing line no longer leaves `haji` to a caller beside the line
saying locales.MS reads it; the 2026-11-19 entry's left-out question is
noted as declined; and the 2026-11-21 entry gives haji's counts, the
populations and its recipe. The #1059 entry says its figures come from
the issue's closing comment, which names no command.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Claim only the provenance the #1469 and #1059 records hold

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Keep only the routing in the open-issue paragraphs

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internals Refactors and parse cost with no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant