Repository navigation
Simplify _classify.py with no reading moved - #1528
Merged
Merged
Conversation
The two rules/P12 walks now collect each pair's marks in one dict and rebuild the tokens once, in a loop rather than a generator; the walk from a second word kept its pairs in a list, tested by `in` once per token, quadratic on a long run of pairs. `_name_words` returns at four, all `long_names_only` asks, so it no longer walks the whole name once per candidate pair. The C10 rebuild loses its generator too, the comma test is skipped where the name has no comma, and the lexicon's sets are bound once in classify. No tag or reading moves. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each citation now carries its quote, the clause it implements and a decisions pointer; the corpus measurement and issue history that had grown in the H5 and T4 comments are left to the entries that hold them. The `one_case` paragraph's example had stopped reaching its case, `NEE` being a listed marker the caps test declines whichever fact it reads, so its history moves to a dated decisions/S9 bullet with a witness that still shows it, held by a new test. The Reads: line names `bound_seconds_listed`, which the stage reads. Two _SHAPES rows hold the P12 pair walks the previous commit made linear. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The caps half reads the own words' one-case fact for every token, a clause's word included, not the whole name's case: the decisions/S9 bullet, the `_tags_for` docstring and the new test said otherwise, and the test gains the row that tells the two apart (`JOHN SMITH nee Jones XYZ`). The S9 bullet is dated by the decision (#516) and points at the wordlist test's live roster; three citation pointers name the entry that holds their issue (S8 for #1394, S9 for #516, S10 for #721). Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test review found three refactored sites no test pinned at the tag level: a pair read across a comma, a bound given name counted after the pair by `long_names_only`, and a second delimiter-glued word keeping its joining tags. A word heading both P12 pairs takes the second walk's marks by assignment: they hold the phrase mark, so the union was a no-op. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Step 0 of the 3.2 release checklist: a /simplify pass over
nameparser/_pipeline/_classify.py, limited to the code the cycle changed (git diff v3.1.0 origin/master -- nameparser/_pipeline/_classify.py, 202 lines), plus its citation comments. It is quality only: no reading and no tag moves, and no other library file changes. It touches no test expectation; it adds classify tests and two scaling rows.Changes
_SHAPESrows now hold them._name_words,abdul'slong_names_onlycount (ShouldAbduljoin the word after it when it is not the first word? (Ahmad Abdul Rahmangives middleAbdul, familyRahman) #1464), walked the whole name once per candidate pair. It now returns at four, which is all its caller asks."abdul aziz " × nread 18.4x at base 200 and 14.3x at 800 for 4x the input; it now reads 4.03x and 4.61x.inonce per token."عز الدين " × nread 4.96x at base 200 and 7.51x at 800, over_MAX_RATIO; it now reads 3.93x and 4.88x.TITLE_AMBIGUOUS_TAG. Every head the first walk marks is a bound given name, so it already carriesvocab:bound-given, and adding the phrase tag cannot change either answer.classifybindslexandsetsonce, where it had three spellings of the lexicon's sets.not tags - Xbecomestags <= X._name_wordsdrops astem andthat its letter test already implies.Reads:now namesbound_seconds_listed, the one settools/stage_reads.py --stage classifylists that the line did not. The trace was checked against every field the line names and every field it leaves out:given_namesis not read, andsurnamesandhonorific_tailsare read only through helpers.decisions/X (#N). Pointers were added for S2, S3, S4, H10, H5 (×3), H8, S11, P7, N4, T4, H2, P10 (×2), H9 and S12. Each pointer was checked to name an entry holding that issue.д-рending a name), which decisions/H5's ShouldHans Meier Priv.-Doz.read the listed title at the end, asHans Meier Prof.does? #1116 entry holds._name_words' docstring said a numeral "VI to X"; the code excludes any I to X not in Title case, a lone capital being Title case. It now says so._tags_for'sone_caseparagraph told the history of a ShouldJohn Smith XYZreadXYZas a credential when no wordlist has those letters? #516 review finding through an example that no longer shows it.JOHN SMITH NEE'sNEEis a listed marker, so the caps test declines it on its wordlist test whichever fact it is handed.JOHN SMITH NEE JONES XYZunderCapsSuffixes.EVERYWHERE. Handed the own-words fact, it reads suffix 'XYZ', maiden 'JONES', and reports both words.test_the_caps_half_asks_the_own_words_case_of_a_clauses_wordholds it. Its control was run: it fails withone_case_ownpassed in, and itsJOHN SMITH nee Jones XYZrow fails with the whole name's case passed in.test_the_p12_walks_mark_the_first_word_of_each_pair(a pair across a comma, a bound given name counted after the pair, a word both walks mark) andtest_every_word_a_delimiter_is_glued_to_loses_its_joining_tags. Each kills the mutant it was written for: the comma gate inverted,<=made<, the C10 loop over the first word only,setdefaultfor the second walk's marks.Proof that nothing moved
BOUND_SECOND_TAGmoves 176 rows)tools/differential/corpus*.jsonl× 8 parsers (default, both family-first orders,CapsSuffixes.EVERYWHEREwith dotted off, two extra delimiters,locales.ES,locales.AR,locales.MS) = 60,896 parses. Each row records every token's text, role and sorted tags straight out of classify, its pending ambiguities andone_case, and then the final repr, ambiguities and each token's tags andreading. sha256406b1d7b…in both trees, base asserted bynameparser.__file__tools/differential/snapshot.jsonltest_snapshot.pypasses-n0 -m serial)measure.py --base(master af58ca0)mypy,ruff checkFrames per parse
sys.setprofile"call" events, mean of 20 after a warm-up, py3.11. Master is af58ca0 in a worktree of its own, path asserted. Each cell shows the default order / FAMILY_FIRST.Dr. Juan0001 de la Vega III(reference)Smith, JohnJohn SmithDr. John Quincy Xavier Adams de la Vega y Lopez III, PhD, MBA(long)Tariq Abdul Aziz HassanAli Abdel Mahdi Hassan Omarسامر عز الدين حدادTariq Abdul Aziz,Abu Bakr Mohammed Ali Hassan Omar Khalid,John (Jack) Smith née Jones,Jane Doe Ph. D.,Associate Dean John Smith,JOHN E SMITH,Smith; Jr, JohnNo row rises. The names that reach a P12 rebuild drop 5 or 6 frames. The reference row and the comma name are unchanged, since no code they run changed, so
_CALL_BASELINE's band is untouched.Behavior-changing candidates (not applied)
long_names_only's count out of classify (altitude review)._name_wordsis a 50-line hand copy of readings later stages make: H2, H9 and H10's leading title run, the trailing run's suffix and numeral take, and ShouldRam Bahadur B.K.keepB.K.as its family name? #864's paired initials. nameparser/AGENTS.md says such a guard "belongs where the parse has read them (post_rules here)", and Should جميل عز الدين read family عز الدين, the الدين joining the word before it? #1072 already moved its own two-word guard that way (_post_rules._split_a_lone_backward_pair).completes_anypair in classify, and let post_rules split along_names_onlypair where the name words it actually read number fewer than four. That would delete_name_words,_LEADING_TITLE_TAGSand_BOUND_TAGS.Policy(two_family_names=True),Tariq Abdul Aziz PopeandTariq Abdul Aziz Bishopleave the pair unjoined (family 'Pope'), though the parse ends with four name words.Tariq Abdul Aziz Jr Haddadjoins, countingJras no word, and the parse then readsJras a family word (family 'Jr Haddad')._post_rules.py. decisions/P12 leaves this to "a change that measures it".Tariq Abdel, Azizalready reads family 'Tariq Abdel', given 'Aziz' through another stage, but a shared comma guard would need a tag comparison before it could be called quality-only. Not tried._name_words' numeral test asking_vocab.reads_as_generation(reuse review; mechanisms.md#ONE-PREDICATE-PER-QUESTION). The two answer differently:V,IorXafter the pair is a name word to the count and the generation to the predicate;… J. VI) is excluded by the count and not read as the generation by the predicate.abdulnames of exactly four words, and adds a frame per word after the pair.Considered and left alone
_vocab.tag_marker_runsmapped alias markers as it maps maiden markers. That needs_vocab.py, outside this pass, and could move tags, since a maiden marker's tag runs across the words it takes.caps_shape_candidate(..., mixed_case=False)(altitude review): one boolean switching the predicate between two shapes, only_comma.decidepassing True. A predicate of its own for the comma slot needs_vocab.pyand_comma.py.bisect(efficiency and reuse reviews): frameless with commas present, but a hand copy of_state.comma_bucket. Callingcomma_bucketinstead costs two frames. The gate on an emptycomma_offsetstakes the frame off every comma-less name; a name with commas still pays it on this rare path._HAS_LETTERbuilt from_vocab._LETTER(reuse review): the same answer in a search. It is left as is; its comment says why it is a search.lex._sets.→sets.inside_tags_for: a binding there moves the recorded count intest_layering.py::test_the_check_refuses_every_read_4i_a_moved(214 → 215) and buys nothing, so_tags_forkeeps its spelling.Reviews
The simplify pass ran four reviewers (reuse, simplification, efficiency, altitude). The findings applied are listed under Changes; the ones refused as behavior changes are listed above.
PR review toolkit, on 684c1b0:
aziza bound given name,deana bound second,الدينcompletes_any) was byte-identical to master in repr and classify's tags: 50,628 rows, 4,363 bound-phrase and 1,548 bound-second tags each.John Smith XYZreadXYZas a credential when no wordlist has those letters? #516) and its roster pointer, which named a superseded list; three citation pointers (MDinside a name in capitals reads as the degree and takes the father's name (MARIAM HAFIZAH MD MOKHTARgives suffix 'MD MOKHTAR') #1394 lives in decisions/S8, ShouldJohn Smith XYZreadXYZas a credential when no wordlist has those letters? #516 in S9, Shouldjohn vread V as the family name, asJOHN Vandjohn xdo? #721 in S10); a benchmark comment's wording.<=, the C10 loop), and the "word heading both pairs" union was a no-op. Fixed in dd40883 with tag-level tests and a plain assignment.Second round on 4e125bb and dd40883: no defects. One test row's comment claimed more than the row pins; reworded in af66925. The second round also confirmed that segment's recorded
one_caseand classify's fallback are the same own-words fact.🤖 Generated with Claude Code