Top Description Fields Constructors Methods
info.debatty.java.stringsimilarity

public Class JaroWinkler

extends Object
implements NormalizedStringSimilarity, NormalizedStringDistance
Class Inheritance
All Implemented Interfaces
info.debatty.java.stringsimilarity.interfaces.NormalizedStringDistance, info.debatty.java.stringsimilarity.interfaces.StringDistance, java.io.Serializable, info.debatty.java.stringsimilarity.interfaces.NormalizedStringSimilarity, info.debatty.java.stringsimilarity.interfaces.StringSimilarity
Annotations
@Immutable
Imports
info.debatty.java.stringsimilarity.interfaces.NormalizedStringSimilarity, .NormalizedStringDistance, java.util.Arrays, net.jcip.annotations.Immutable

The Jaro–Winkler distance metric is designed and best suited for short strings such as person names, and to detect typos; it is (roughly) a variation of Damerau-Levenshtein, where the substitution of 2 close characters is considered less important then the substitution of 2 characters that a far from each other. Jaro-Winkler was developed in the area of record linkage (duplicate detection) (Winkler, 1990). It returns a value in the interval [0.0, 1.0]. The distance is computed as 1 - Jaro-Winkler similarity.
Author
Thibault Debatty

Field Summary

Modifier and TypeField and Description
private static final double
private static final double
private static final int
private final double

Constructor Summary

AccessConstructor and Description
public
JaroWinkler()

Instantiate with default threshold (0.7).

public
JaroWinkler(final double threshold)

Instantiate with given threshold to determine when Winkler bonus should be used.

Method Summary

Modifier and TypeMethod and Description
public final double

Returns:

1 - similarity.
distance
(final String
The first string to compare.
s1
,
final String
The second string to compare.
s2
)

Implements info.debatty.java.stringsimilarity.interfaces.StringDistance.distance.

Return 1 - similarity.

public final double

Returns:

the current value of the threshold
getThreshold
()

Returns the current value of the threshold used for adding the Winkler bonus.

private int[]
matches(final String s1, final String s2)

public final double

Returns:

The Jaro-Winkler similarity in the range [0, 1]
similarity
(final String
The first string to compare.
s1
,
final String
The second string to compare.
s2
)

Implements info.debatty.java.stringsimilarity.interfaces.StringSimilarity.similarity.

Compute Jaro-Winkler similarity.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_THRESHOLDback to summary
private static final double DEFAULT_THRESHOLD
JW_COEFback to summary
private static final double JW_COEF
THREEback to summary
private static final int THREE
thresholdback to summary
private final double threshold

Constructor Detail

JaroWinklerback to summary
public JaroWinkler()

Instantiate with default threshold (0.7).

JaroWinklerback to summary
public JaroWinkler(final double threshold)

Instantiate with given threshold to determine when Winkler bonus should be used. Set threshold to a negative value to get the Jaro distance.

Method Detail

distanceback to summary
public final double distance(final String s1, final String s2)

Implements info.debatty.java.stringsimilarity.interfaces.StringDistance.distance.

Return 1 - similarity.

Parameters
s1:String

The first string to compare.

s2:String

The second string to compare.

Returns:double

1 - similarity.

Exceptions
NullPointerException:
if s1 or s2 is null.
getThresholdback to summary
public final double getThreshold()

Returns the current value of the threshold used for adding the Winkler bonus. The default value is 0.7.

Returns:double

the current value of the threshold

matchesback to summary
private int[] matches(final String s1, final String s2)
similarityback to summary
public final double similarity(final String s1, final String s2)

Implements info.debatty.java.stringsimilarity.interfaces.StringSimilarity.similarity.

Compute Jaro-Winkler similarity.

Parameters
s1:String

The first string to compare.

s2:String

The second string to compare.

Returns:double

The Jaro-Winkler similarity in the range [0, 1]

Exceptions
NullPointerException:
if s1 or s2 is null.