Question about the behaviour of partial_ratio with spaces #471
Replies: 1 comment 2 replies
-
|
The reason is that partial ratio uses a sliding window of the shorter text on top of the longer text. So unless the substring is at start/end of the longer string it has the same length as the shorter string. It then returns the score for the alignment with the best fuzz.ratio. This leads to surprising results in your case because for
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I noticed a weird behaviour with partial_ratio and comparing two pieces of text where one has spaces. For some reason, it will sometimes generate a score that is lower than it should be, given that it is doing sub-string comparison. I was able to notice this with exact text I have used here:
fuzz.partial_ratio("FG Kissimmee", " YM Kissimmee ") # output: 83.33333333333334This returns a score of 83.333, instead of the best possible answer which to my understanding should be 90.909, which can be produced when I strip out the leading and trailing spaces for the text on the right:
fuzz.partial_ratio("FG Kissimmee", "YM Kissimmee") # output: 90.9090909090909Additionally, it does not happen in all cases when spacing is applied, for example:
fuzz.partial_ratio("Hello World", " Hella World ") # output: 90.9090909090909fuzz.partial_ratio("Hello World", "Hella World") # output: 90.9090909090909Is this a bug, or is this an intentional behaviour?
Beta Was this translation helpful? Give feedback.
All reactions