Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wired behavior of partial_ratio #313

Open
sillybun opened this issue May 2, 2021 · 1 comment
Open

Wired behavior of partial_ratio #313

sillybun opened this issue May 2, 2021 · 1 comment

Comments

@sillybun
Copy link

sillybun commented May 2, 2021

In [47]: fuzzywuzzy.fuzz.partial_ratio("red", "random")                        
Out[47]: 33

In [48]: fuzzywuzzy.fuzz.partial_ratio("rod", "random")                        
Out[48]: 33

In [49]: fuzzywuzzy.fuzz.partial_ratio("prod", "random")                       
Out[49]: 25

In [50]: fuzzywuzzy.fuzz.partial_ratio("pred", "random")                       
Out[50]: 50

why "pred" is more similar to "random" than "prod"?

@maxbachmann
Copy link

This is a known issue in python-Levenshtein: #79
In your case for the comparision of

"prod" <-> "random"

the following alignment is used:

"prod" <-> "ndom"

which has a similarity of 25.
However the optimal alignment would be:

"prod" <-> "rand"

which has a similarity of 50.
In FuzzyWuzzy you will get the correct result when the slower difflib based implementation is used:

>>> from fuzzywuzzy import fuzz
>>> from difflib import SequenceMatcher
>>> fuzz.SequenceMatcher = SequenceMatcher
>>> fuzzywuzzy.fuzz.partial_ratio("prod", "random") 
50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants