This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-text.git
commit edf191d2466b72dc96335f23cf58c34d2e0de721 Author: Gary Gregory <[email protected]> AuthorDate: Sun Nov 30 08:02:23 2025 -0500 Javadoc Reduce vertical whitespace --- .../org/apache/commons/text/similarity/FuzzyScore.java | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/apache/commons/text/similarity/FuzzyScore.java b/src/main/java/org/apache/commons/text/similarity/FuzzyScore.java index fd5c447d..b35455dc 100644 --- a/src/main/java/org/apache/commons/text/similarity/FuzzyScore.java +++ b/src/main/java/org/apache/commons/text/similarity/FuzzyScore.java @@ -54,7 +54,7 @@ public class FuzzyScore { } /** - * Find the Fuzzy Score which indicates the similarity score between two Strings. + * Computes the Fuzzy Score which indicates the similarity score between two Strings. * * <pre> * score.fuzzyScore(null, null) = Throws {@link IllegalArgumentException} @@ -78,51 +78,39 @@ public class FuzzyScore { if (term == null || query == null) { throw new IllegalArgumentException("CharSequences must not be null"); } - // fuzzy logic is case insensitive. We normalize the Strings to lower // case right from the start. Turning characters to lower case // via Character.toLowerCase(char) is unfortunately insufficient // as it does not accept a locale. final String termLowerCase = term.toString().toLowerCase(locale); final String queryLowerCase = query.toString().toLowerCase(locale); - // the resulting score int score = 0; - // the position in the term which will be scanned next for potential // query character matches int termIndex = 0; - // index of the previously matched character in the term int previousMatchingCharacterIndex = Integer.MIN_VALUE; - for (int queryIndex = 0; queryIndex < queryLowerCase.length(); queryIndex++) { final char queryChar = queryLowerCase.charAt(queryIndex); - boolean termCharacterMatchFound = false; - for (; termIndex < termLowerCase.length() - && !termCharacterMatchFound; termIndex++) { + for (; termIndex < termLowerCase.length() && !termCharacterMatchFound; termIndex++) { final char termChar = termLowerCase.charAt(termIndex); - if (queryChar == termChar) { // simple character matches result in one point score++; - // subsequent character matches further improve // the score. if (previousMatchingCharacterIndex + 1 == termIndex) { score += 2; } - previousMatchingCharacterIndex = termIndex; - // we can leave the nested loop. Every character in the // query can match at most one character in the term. termCharacterMatchFound = true; } } } - return score; }
