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

public Class WeightedLevenshtein

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

Implementation of Levenshtein that allows to define different weights for different character substitutions.
Author
Thibault Debatty

Field Summary

Modifier and TypeField and Description
private final CharacterInsDelInterface
private final CharacterSubstitutionInterface

Constructor Summary

AccessConstructor and Description
public
WeightedLevenshtein(final CharacterSubstitutionInterface
The strategy to determine character substitution weights.
charsub
)

Instantiate with provided character substitution.

public
WeightedLevenshtein(final CharacterSubstitutionInterface
The strategy to determine character substitution weights.
charsub
,
final CharacterInsDelInterface
The strategy to determine character insertion / deletion weights.
charchange
)

Instantiate with provided character substitution, insertion, and deletion weights.

Method Summary

Modifier and TypeMethod and Description
private double
deletionCost(final char c)

public final double
distance(final String s1, final String s2)

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

Equivalent to distance(s1, s2, Double.MAX_VALUE).

public final double

Returns:

The computed weighted Levenshtein distance.
distance
(final String
The first string to compare.
s1
,
final String
The second string to compare.
s2
,
final double
The maximum result to compute before stopping. This means that the calculation can terminate early if you only care about strings with a certain similarity. Set this to Double.MAX_VALUE if you want to run the calculation to completion in every case.
limit
)

Compute Levenshtein distance using provided weights for substitution.

private double
insertionCost(final char c)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

charchangeback to summary
private final CharacterInsDelInterface charchange
charsubback to summary
private final CharacterSubstitutionInterface charsub

Constructor Detail

WeightedLevenshteinback to summary
public WeightedLevenshtein(final CharacterSubstitutionInterface charsub)

Instantiate with provided character substitution.

Parameters
charsub:CharacterSubstitutionInterface

The strategy to determine character substitution weights.

WeightedLevenshteinback to summary
public WeightedLevenshtein(final CharacterSubstitutionInterface charsub, final CharacterInsDelInterface charchange)

Instantiate with provided character substitution, insertion, and deletion weights.

Parameters
charsub:CharacterSubstitutionInterface

The strategy to determine character substitution weights.

charchange:CharacterInsDelInterface

The strategy to determine character insertion / deletion weights.

Method Detail

deletionCostback to summary
private double deletionCost(final char c)
distanceback to summary
public final double distance(final String s1, final String s2)

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

Equivalent to distance(s1, s2, Double.MAX_VALUE).

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

Compute Levenshtein distance using provided weights for substitution.

Parameters
s1:String

The first string to compare.

s2:String

The second string to compare.

limit:double

The maximum result to compute before stopping. This means that the calculation can terminate early if you only care about strings with a certain similarity. Set this to Double.MAX_VALUE if you want to run the calculation to completion in every case.

Returns:double

The computed weighted Levenshtein distance.

Exceptions
NullPointerException:
if s1 or s2 is null.
insertionCostback to summary
private double insertionCost(final char c)