Ensure that maximum normalised distance is <= 1 and ... #78
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.
textdistance is currently failing its test-suite on arm64 machines with Python 3.10, which is causing me problems on Debian. I have managed to track down the first of these bugs (and there are at least two more to come): there are some algorithms that use
upper()
before comparing the strings. As noted in the code already, though these algorithms were designed for English (ASCII only), this can causeupper()
to change the length of the string if using non-English characters. Andhypothesis
does this when testing. This can result in the normalised distance being greater than 1. This patch addresses this by ensuring that the distance returned from the relevant algorithms is no greater thanself.maximum()
.A second issue which arose when doing this was calculating the maximum distance for
Editex()
; the current function for calculating the maximum does not give the correct answer ifmatch_cost > mismatch_cost
, for example. But this would be a silly situation: why would we penalise matching characters more than mismatching ones? There are two ways of resolving this: the first is to calculate the maximum distance usingmax(match_cost, group_cost, mismatch_cost)
, the second is to force the inequalitiesmatch_cost <= group_cost <= mismatch_cost
. I have gone for the latter option in this patch.All being well, there will be more patches to come in the next few weeks as I get to the bottom of them!