seatgeek / fuzzywuzzy

Fuzzy String Matching in Python
http://chairnerd.seatgeek.com/fuzzywuzzy-fuzzy-string-matching-in-python/
GNU General Public License v2.0
9.21k stars 874 forks source link

partial_ratio not using best aligned substring with python-Levenshtein #274

Closed maxbachmann closed 4 years ago

maxbachmann commented 4 years ago

When using partial_ratio with python-Levenshtein it is not guaranteed to use the best aligned string, even though thats the purpose of partial_ratio. As an example:

>>> fuzz.partial_ratio("aaaa", "babaaaab")
75.0

Here the best aligned string is a exact match. However the get_matching_blocks method from python-Levenshtein only finds the alignment aaaa <-> abaa and therefore calculates a ratio of 75% in partial_ratio.

In my opinion it should be either explicitly mentioned (probably in the docstring), that when using python-Levenshtein this function is not guaranteed to use the best aligned string, or it should keep using difflib to calculate the matching_blocks and python-Levenshtein only for the final ratio calculation when looping over the matching_blocks even when python-Levenshtein is available.

maxbachmann commented 4 years ago

duplicate of https://github.com/seatgeek/fuzzywuzzy/issues/79