Class FuzzyScore
- java.lang.Object
-
- org.apache.commons.text.similarity.FuzzyScore
-
public class FuzzyScore extends java.lang.Object
A matching algorithm that is similar to the searching algorithms implemented in editors such as Sublime Text, TextMate, Atom and others.One point is given for every matched character. Subsequent matches yield two bonus points. A higher score indicates a higher similarity.
This code has been adapted from Apache Commons Lang 3.3.
- Since:
- 1.0
-
-
Constructor Summary
Constructors Constructor Description FuzzyScore(java.util.Locale locale)
This returns aLocale
-specificFuzzyScore
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Integer
fuzzyScore(java.lang.CharSequence term, java.lang.CharSequence query)
Find the Fuzzy Score which indicates the similarity score between two Strings.java.util.Locale
getLocale()
Gets the locale.
-
-
-
Constructor Detail
-
FuzzyScore
public FuzzyScore(java.util.Locale locale)
This returns a
Locale
-specificFuzzyScore
.- Parameters:
locale
- The string matching logic is case insensitive. ALocale
is necessary to normalize both Strings to lower case.- Throws:
java.lang.IllegalArgumentException
- This is thrown if theLocale
parameter isnull
.
-
-
Method Detail
-
fuzzyScore
public java.lang.Integer fuzzyScore(java.lang.CharSequence term, java.lang.CharSequence query)
Find the Fuzzy Score which indicates the similarity score between two Strings.
score.fuzzyScore(null, null) = IllegalArgumentException score.fuzzyScore("not null", null) = IllegalArgumentException score.fuzzyScore(null, "not null") = IllegalArgumentException score.fuzzyScore("", "") = 0 score.fuzzyScore("Workshop", "b") = 0 score.fuzzyScore("Room", "o") = 1 score.fuzzyScore("Workshop", "w") = 1 score.fuzzyScore("Workshop", "ws") = 2 score.fuzzyScore("Workshop", "wo") = 4 score.fuzzyScore("Apache Software Foundation", "asf") = 3
- Parameters:
term
- a full term that should be matched against, must not be nullquery
- the query that will be matched against a term, must not be null- Returns:
- result score
- Throws:
java.lang.IllegalArgumentException
- if the term or query isnull
-
getLocale
public java.util.Locale getLocale()
Gets the locale.- Returns:
- The locale
-
-