Compare characters by value in DamerauLevenshteinDistance - #770
Merged
garydgregory merged 1 commit intoSep 3, 2026
Merged
Conversation
calculateCost compared the boxed Character values returned by SimilarityInput.at with ==, so it only recognized equal characters that Character.valueOf caches. That cache covers values up to 127, so every non-ASCII character compared unequal to itself: applying the distance to "caf\u00e9" and "caf\u00e9" reported 1 instead of 0, and a two-character CJK input compared against itself reported 2. The adjacent-transposition branch never fired for non-ASCII input either, so transposing two accented characters cost 2 instead of 1. The limited variant was affected the same way and could return -1 for inputs whose real distance is within the threshold. Compare with Objects.equals instead, matching every other class in this package: LevenshteinDistance, LevenshteinDetailedDistance, JaroWinklerSimilarity and HammingDistance all use equals on the values from at.
Member
|
@Weiki886 LGTM, merged 🚀 |
garydgregory
added a commit
that referenced
this pull request
Sep 3, 2026
|
Hi, any ETA when new release can be expected? Without this fix the Damerau-Levenshtein algorithm in unusable. |
Member
|
@Weiki886 |
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.
calculateCost compared the boxed Character values returned by
SimilarityInput.atwith==, so it only recognized equal charactersthat
Character.valueOfcaches. That cache covers values up to 127,so every non-ASCII character compared unequal to itself: applying the
distance to
"caf\u00e9"and"caf\u00e9"reported 1 instead of 0,and a two-character CJK input compared against itself reported 2. The
adjacent-transposition branch never fired for non-ASCII input either,
so transposing two accented characters cost 2 instead of 1. The
limited variant was affected the same way and could return -1 for
inputs whose real distance is within the threshold.
Compare with
Objects.equalsinstead, matching every other class inthis package:
LevenshteinDistance,LevenshteinDetailedDistance,JaroWinklerSimilarityandHammingDistanceall useequalson thevalues from
at.mvn; that ismvnon the command line by itself.