Add clean_name utility and fallback_func support to lookup#97
Closed
jcarbaugh wants to merge 1 commit into
Closed
Conversation
Add a `clean_name` helper that normalizes free-form text down to a bare state name by stripping punctuation and the filler words "the", "state", "commonwealth", and "of", then collapsing whitespace. Add a `fallback_func` argument to `lookup`. When no built-in match is found, the fallback is called with the original lookup value so callers can supply custom match logic. Include a `startswith_fallback` helper that matches on a state name prefix. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Member
Author
|
Opened against the wrong repository by mistake; reopening on the correct fork. |
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
Adds two related improvements to
us.statesfor handling messy, free-form state input.clean_nameA new utility that normalizes free-form text down to a bare state name. It lowercases the input, strips punctuation, removes the filler words
the,state,commonwealth, andof, and collapses whitespace before recombining tokens into a single space-separated string.clean_nameis a standalone normalizer — it is not auto-wired intolookup, so existing callers are unaffected. Callers combine the two explicitly.fallback_funcargument onlookuplookupnow accepts an optionalfallback_func. When the built-in FIPS / abbreviation / metaphone matching finds nothing, the fallback is called with the original, untransformed lookup value and its return value is used as the result. This lets callers plug in their own match logic. Fallback results are not cached.A
startswith_fallbackhelper is included as a ready-madefallback_func: it returns the first state or territory whose name starts with the given value (case-insensitive). An empty string matches nothing.Testing
us/tests/test_us.pycoveringclean_name, thefallback_funcbehavior, andstartswith_fallback.ruff checkclean.Notes
Linear issue: https://linear.app/apricotdotcool/issue/APR-30/add-clean-name-utility-and-fallback-func-support-to-lookup