feat: add last_base / last_prefixes derived properties (#130, #132)#182
Merged
Conversation
Adds _split_last(), last_base, last_prefixes, last_base_list, last_prefixes_list, family, and family_prefixes to HumanName. The guard prevents stripping when every last-name token is a prefix. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add list-form assertions to test_von_bergen_wessels (multi-word base) - Add test_case_insensitive_prefix_detection to pin is_prefix lowercasing - Clarify _split_last docstring: document the all-particles guard invariant, add Anh Do doctest, soften inline comment to heuristic framing - Add guard-behavior notes to last_base_list, last_prefixes_list, last_base, and last_prefixes docstrings so the non-obvious empty-prefix case is surfaced Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds 'af', 'av', 'bar', 'bat', 'bint', 'den', 'ter', 'zu', and "'t" sourced from https://en.wikipedia.org/wiki/List_of_family_name_affixes (also referenced in PR #132). Excludes 'ben' due to ambiguity with the common English given name; excludes single-letter particles and fused prefixes (mc, fitz) as too ambiguous for general use. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace 'ter' (now in PREFIXES) with 'op' as the custom-particle example; also demonstrates chaining with the newly added 'den' prefix. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Summary
last_base/last_base_list— the last name with leading prefix particles stripped (e.g."van Gogh"→"Gogh")last_prefixes/last_prefixes_list— the leading prefix particle(s) (e.g."van","de la")familyandfamily_prefixesstring aliases for the abovelast_listat access time;lastandlast_listare unchangedDesign
Uses a single
_split_last()helper that consumes leadingPREFIXESwords. Includes an all-particles guard so surnames that collide with the prefix set (e.g."Do") are never stripped. Purely additive — no changes to_members, parse flow, or existing attributes.Test Plan
uv run pytest— 864 passed, 22 xfaileduv run pytest --doctest-modules nameparser/parser.py— 9 passeduv run mypy nameparser/— cleanuv run ruff check nameparser/ tests/— cleanvan Gogh,de la Vega,von bergen wessels,John Smith(no prefix),Anh Do(surname == prefix word guard), all-particles guard, empty name, alias parity, title+prefix (Dra. da Silva)Closes #130, #132