Skip to content

Simplify the script, post-rule, assign and assemble stages - #1434

Merged
derek73 merged 2 commits into
masterfrom
simplify/pipeline-stages
Nov 16, 2026
Merged

derek73 merged 2 commits into
masterfrom
simplify/pipeline-stages

Conversation

@derek73

@derek73 derek73 commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Release step 0 for 3.1 (root AGENTS.md's checklist): a /simplify pass over the pipeline stages this cycle changed. It covers _script_segment.py, _post_rules.py, _assign.py, _assemble.py, _state.py, _classify.py, _tokenize.py, _extract.py and _group.py. _comma.py, _pieces.py and _vocab.py belong to another pass. No reading, ambiguity report or message moves.

Four read-only reviewers covered the nine files (reuse, simplification, efficiency, altitude), and two more reviewed the diff (a code review and a design-docs review). Their findings are applied below, or listed under what was declined or the behavior-changing candidates.

Simplifications, by file

_script_segment.py (1,189 → 1,145 lines)

  • _peel_cut (rules/W6's front peel) looks a title up by slicing. It takes the word's prefixes longest first and tests each against glued_titles, the form the tail peel and the surname match already use, instead of walking every glued title in sorted order. _longest_first goes. It costs no new frames, since the cached _longest_entry hit is C-level, and it is about 9× faster per peeled site.
  • The glued-title gate reads the cached _vocab.title_prefixes(heads) instead of rebuilding tuple(heads) on every non-ASCII parse.
  • _ends_the_name drops its text parameter, which was always texts[k].
  • The segmenter-neighbour comment is cut from 37 lines to its rules/W1 quote and the code-local reasons. It had grown stale too: it still described the neighbour test from before Should a Mongolian choice read the father's name first? (Ухнаагийн Хүрэлсүх gives given 'Ухнаагийн', family 'Хүрэлсүх') #1237. The history it held is in decisions/W3 and decisions/W4.
  • The _SEGMENTER_CONFIDENCE_FLOOR comment is cut from 25 lines to a contract line. Its measurement moves to decisions/W1 (see the docs edit below).
  • The Reads: line names the sets the module now reads directly: conjunctions, the gated titles, the modifiers and styles, and the maiden markers.

_post_rules.py (1,684 → 1,642 lines)

  • _take_trailing_initials drops its unused state.
  • The P6 comment is cut from 53 lines to the two rule quotes and the clause each implements. Every fact cut from it is in decisions/P6 or rules/P6, except de Mesnil Jan de → 'de de Mesnil', which stays. The old text claimed the order was tested; the code tests that the run ENDS the name, as the block below it says, and the cut comment no longer contradicts that.
  • The module docstring's "Implements" list gains O8 and O9. Its Consumes: line no longer lists O8 as keying on order, which it does not read.

_assemble.py (942 → 942 lines)

  • _INITIAL_TAGS moves above its first user.

_assign.py, _state.py, _classify.py, _tokenize.py, _extract.py, _group.py

No change. What was examined and declined:

  • _assign, two small local helpers. One would hold H10's lone-dotted-piece test in the H6 walk, the other O4's one-letter-chunks test. That block is inlined for the parse-cost band, its comment says so, and each copy is a few characters.

  • _classify, moving the H10 dotted loop under H9's gate. It is identical only while no dotted spelling is itself a gated title, so it is not a pure refactor.

  • _group, the ph-d merge comment. It explains the three head tests the code makes, which is code-local reasoning, not history.

  • Folds reverted in review because they cost frames per word. The first push folded four hand copies into helpers:

    • _script_segment._only_post_nominals' suffix test into _vocab._listed_whole, which also normalizes each word a second time;
    • the shared "no titles glued at their stops" test into a _not_glued_titles helper;
    • the patronymic test in rules/O9's marker set and rules/O6's veto into a _patronymic_under helper;
    • _family_in_capitals' two inline copies of its lowercase_joiner closure into calls to it.

    Each added a call per word on its path. By root AGENTS.md's frame-budget rule, a cost that multiplies with the input stays inline, so the second commit restores all four inline tests.

  • The efficiency findings: none applied. They would cut the reference row from 285 to ~234, but _CALL_BASELINE's band is two-sided. They are listed under Follow-ups.

Docs and tests

  • decisions/W1 gains a dated Log entry, "2026-07-29 (ja amendment §3)", holding the confidence floor's measurement (namedivider 0.4.1 over 112 names, bimodal scores) that only the code comment held. The entry also gets a Standing line. The §1a Standing pointer now names its entry, so it stays unambiguous.
  • The W1 entry says the 112-name sample was not kept: its figures are a dated snapshot under namedivider 0.4.1, which nothing re-runs (uv.lock pins 0.4.2).
  • tests/v2/test_layering.py is untouched. The _sets read count is back at master's 203 once the folds are reverted.

Measurements

Check Result
uv run pytest (ja extra installed) 49,818 passed, 13 skipped, 3 xfailed
uv run pytest without the ja extra 49,786 passed, 45 skipped, 3 xfailed
uv run pytest -n0 -m serial 38 passed
uv run mypy, uv run ruff check clean
git diff --stat origin/master -- tools/differential empty
tests/v2/test_snapshot.py passes
tools/differential/cldr_agreement.py every view matches the record, no move
tests/v2/pipeline/test_state.py unchanged

Both suite runs and the serial run are on the final head.

A base-versus-head grid

58 names, plus each name's NFD spelling, were each parsed under 26 configurations, in three comma shapes (as written, , Jr. appended, Smith, prepended). The names cover:

  • Thai glued titles and their dotted, modifier and vowel edges;
  • glued saint words, maiden markers and glued initials;
  • capitals and patronymic names.

The 26 configurations are each order × capitals_as_family × initials_as_family × patronymic_rules, plus RU and TR_AZ. That is 8,736 parses. Readings, roles, sources and ambiguity texts are byte-identical between master and this branch.

A reviewer also fuzzed _peel_cut old against new over 300,000 words with caller-added glued titles: 0 differences. A deliberately broken variant differed on all 175 of its inputs, so the harness can see a difference.

Frames

Fresh process per name, py3.11, _frames_for / _calls_per_parse from tests/v2/test_benchmark.py. The columns are master (90b15c84) and this branch's head.

policy name master this branch
default reference (_calls_per_parse) 285.8 285.8
default Smith, John 136 136
default 김민준 214 215
default นายสมชาย ใจดี 344 345
default Juan dela Cruz Sta.Maria Ph.D. 429 429
default John Smith A.Brown PhD 368 368
capitals_as_family Marie DUPONT 172 172
capitals_as_family Marie de LA FONTAINE y DUPONT Jr. 475 475
capitals_as_family + patronymic_rules Marie DUPONT 179 179
capitals_as_family + patronymic_rules Mammad Ali OGLU 253 253
capitals_as_family + patronymic_rules Marie de LA FONTAINE y DUPONT Jr. 490 490
capitals_as_family + patronymic_rules Anna Marie + ten capitals words 635 635
two_given_names + patronymic_rules Ivan Petrovich Sidorov 221 221

The +1 on the two non-ASCII names is title_prefixes' first, uncached call: the benchmark's warm-up name is ASCII and never reaches that gate. After one non-ASCII warm-up parse, both trees read the same: 김민준 212, นายสมชาย ใจดี 343, José García 177.

These absolute counts differ from figures taken with another warm-up (decisions/parse-cost, 2026-11-09 #1170). The comparison is between columns. No path gains a frame that grows with its word count. _CALL_BASELINE is not edited.

Stage headers

Every stage's Reads: line was checked against grep -oE '\b(policy|lexicon|lex)(\._sets)?\.[a-z][a-z_]*'. _post_rules reads the suffix sets through a local sets alias, which the grep cannot see, and the line names them. _state is not a stage.

Behavior-changing candidates

Not made. Each would move a reading somewhere:

  • _script_segment._only_post_nominals hand-copies a one- and two-word maiden-marker lookup, where _vocab.maiden_marker_run is the shared predicate. The two agree on the shipped vocabulary. On a caller's lexicon they differ for a marker of three or more words, for overlapping markers (geb and geb von both listed) and for a word that folds away.
  • _script_segment._all_titles vs _vocab.period_joined_title. They differ on a fullwidth stop inside the word ('ดร。.รศ').
  • _script_segment._ends_the_name's suffix test vs _listed_whole. They differ only if a cut leaves a word holding a stop, which glued_cuts should never do; left as is.
  • _post_rules._listed_suffix vs _listed_whole. They are identical on a capitals word, but _suggest calls it on words that may hold a stop, so the swap could move a suggestion.
  • _extract._opens_a_listed_particle cuts at ASCII - only, where _vocab._HYPHENS is the pipeline's hyphen class. Widening it changes rules/N2's reach ('s‐Gravesande with U+2010).
  • _script_segment: the three spellings of "a title chunk" (_all_titles, _vocab.is_title_chunk, _a_name_before's set test) are not equivalent: St reads differently.

Follow-ups

  • Frame savings outside the band. The efficiency reviewer measured scratch patches that cut the reference row from 285 to ~234 and Smith, John from 136 to ~112. The biggest pieces:

    • the per-character _ignorable call in _tokenize (scales with every character);
    • _is_emoji's generator over its ranges;
    • generator-to-list changes in _classify and _group.

    Taking them needs a deliberate move of _CALL_BASELINE and a decisions/parse-cost entry. The list is in the coordination notes (simplify-stages-frame-followup.md).

  • H10's lone-dotted-piece test is spelled in _pieces.leading_titles and _assign. A shared helper would cost frames in leading_titles, which runs every parse. That is for the _pieces owner.

🤖 Generated with Claude Code

The 3.1 release's /simplify pass over the pipeline stages changed this
cycle. No reading, report or message moves.

- script_segment: rules/W6's front peel looks a title up by slicing,
  longest first, as the tail peel and the surname match do, rather
  than walking every glued title (_longest_first goes); its gate reads
  the cached title_prefixes rather than rebuilding a tuple per parse;
  the glued word's post-nominal test asks _vocab._listed_whole; one
  helper, _not_glued_titles, holds the test _a_name_before and
  _a_word_to_spare each spelled; _ends_the_name drops a parameter
  that was always texts[k]; the segmenter-neighbour and confidence
  floor comments are cut to their citations, the floor's measurement
  moving to decisions/W1, which held none of it; the Reads: line names
  the sets the module reads directly.
- post_rules: _patronymic_under holds the patronymic test O9 and the
  O6 veto each spelled; _family_in_capitals calls its lowercase_joiner
  where it wrote the test out twice more; _take_trailing_initials
  drops its unused state; the P6 comment is cut to its citations, its
  history being in decisions/P6; the docstring names O8 and O9.
- assemble: _INITIAL_TAGS moves above its first user.
- test_layering: the recorded count of _sets reads is re-taken,
  203 -> 200.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@derek73 derek73 added the internals Refactors and parse cost with no behavior change label Nov 16, 2026
@derek73 derek73 self-assigned this Nov 16, 2026
Review measured frames rising with the word count on paths the first
commit's folds reached: the glued word's post-nominal and title tests
(T8), rules/O9's capitals walk and patronymic markers, and rules/O6's
patronymic veto. Each fold called a helper once per word, which the
frame budget refuses for a cost that multiplies with the input, so the
inline tests come back: `_only_post_nominals`' suffix test,
`_a_name_before`'s and `_a_word_to_spare`'s glued-titles test,
`_family_in_capitals`' lowercase-joiner test and the patronymic test
of O9's markers and O6's veto. `_sets` reads return to master's count,
so test_layering is master's again.

decisions/W1's floor entry now says its 112-name sample was not kept:
the figures are a dated snapshot under namedivider 0.4.1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@derek73
derek73 merged commit 4036849 into master Nov 16, 2026
14 checks passed
@derek73
derek73 deleted the simplify/pipeline-stages branch November 16, 2026 09:33
@derek73 derek73 added this to the 3.1 milestone Nov 16, 2026
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