Make RapidFuzzMatcher the default fuzzy matcher - #62
Merged
Merged
Conversation
Add RapidFuzzMatcher, which scores names with rapidfuzz, and make it the default for get_code_from_name. Phonetics remains available via the matcher parameter. RapidFuzzMatcher.place_name_scorer additionally rejects names that share a word but differ in another (eg. "central kalimantan" vs "kalimantan utara"). Add resolve_name_parts: a two-part name resolves when one part qualifies the other (a parent name, or a sub-code such as "Protection - GBV"), and a list of names is not fuzzy matched. rapidfuzz is now a required dependency. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Test Results137 tests +10 136 ✅ +9 11s ⏱️ +3s For more details on these failures, see this check. Results for commit 1b87283. ± Comparison against base commit 12b8d11. |
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
RapidFuzzMatcher(new,matching.py): fuzzy matches names with rapidfuzz, using the samematch()interface asPhonetics.default_scorer:token_set_ratio, orratioon the names with spaces and punctuation removed when that is at least 90 (for "Dawlatabad" vs "Dawlat Abad").place_name_scorer: asdefault_scorer, but scores 0 when names share a word and differ in another that isn't a spelling variant (eg. "central kalimantan" vs "kalimantan utara").ratio, so "north west" picks "North West" over "West".get_code_from_namedefaults toRapidFuzzMatcher. Passmatcher=Phonetics()for the previous behaviour.resolve_name_parts(new): a name split by,;/:&newline "and" "et", or a hyphen, is resolved from its parts:A list of names (3+ parts, or 2 parts with different codes) is not fuzzy matched.
rapidfuzzis now a required dependency.pyphoneticsstays, sincePhoneticsis still available.Docs: breaking change note and matching examples in
documentation/index.md. The note says "From 4.2.0", which needs confirming.Why
pyphonetics has had no release or activity in 12+ months. A comparison over admin and lookup names collected from the repos that use this code (2,762 admin names with an answer independent of either matcher, from test asserts and provider p-codes; pipeline mode):
Impact
Matching results change for downstream users of
get_code_from_nameand of hdx-python-country'sAdminLevel, which will get the same default in a follow-up PR once this is released. Known RapidFuzzMatcher limits:Testing
tests/hdx/utilities/test_matching.py: 19 passed.main(test_downloader::test_downloadsize assert,test_emailandtest_htmlwithout the optional extras).