Top Description Fields Constructors Methods
org.apache.commons.text.similarity

public Class FuzzyScore

extends Object
Class Inheritance
Imports
java.util.Locale

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

Field Summary

Modifier and TypeField and Description
private final Locale
locale

Locale used to change the case of text.

Constructor Summary

AccessConstructor and Description
public
FuzzyScore(final Locale
The string matching logic is case insensitive. A Locale is necessary to normalize both Strings to lower case.
locale
)

Constructs a new instance for a Locale-specific FuzzyScore.

Method Summary

Modifier and TypeMethod and Description
public Integer

Returns:

result score.
fuzzyScore
(final CharSequence
a full term that should be matched against, must not be null.
term
,
final CharSequence
the query that will be matched against a term, must not be null.
query
)

Computes the Fuzzy Score which indicates the similarity score between two Strings.

public Locale

Returns:

The locale
getLocale
()

Gets the locale.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

localeback to summary
private final Locale locale

Locale used to change the case of text.

Constructor Detail

FuzzyScoreback to summary
public FuzzyScore(final Locale locale)

Constructs a new instance for a Locale-specific FuzzyScore.

Parameters
locale:Locale

The string matching logic is case insensitive. A Locale is necessary to normalize both Strings to lower case.

Exceptions
IllegalArgumentException:
This is thrown if the Locale parameter is null.

Method Detail

fuzzyScoreback to summary
public Integer fuzzyScore(final CharSequence term, final CharSequence query)

Computes the Fuzzy Score which indicates the similarity score between two Strings.

score.fuzzyScore(null, null)                          = Throws IllegalArgumentException
score.fuzzyScore("not null", null)                    = Throws IllegalArgumentException
score.fuzzyScore(null, "not null")                    = Throws 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:CharSequence

a full term that should be matched against, must not be null.

query:CharSequence

the query that will be matched against a term, must not be null.

Returns:Integer

result score.

Exceptions
IllegalArgumentException:
if the term or query is null.
getLocaleback to summary
public Locale getLocale()

Gets the locale.

Returns:Locale

The locale