public class DamerauLevenshteinAlgorithm extends Object
This implementation allows the client to specify the costs of the various edit operations with the restriction that the cost of two swap operations must not be less than the cost of a delete operation followed by an insert operation. This restriction is required to preclude two swaps involving the same character being required for optimality which, in turn, enables a fast dynamic programming solution.
The running time of the Damerau-Levenshtein algorithm is O(n*m) where n is the length of the source string and m is the length of the target string. This implementation consumes O(n*m) space.
| Constructor and Description |
|---|
DamerauLevenshteinAlgorithm(int deleteCost,
int insertCost,
int replaceCost,
int swapCost)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
int |
execute(String source,
String target)
Compute the Damerau-Levenshtein distance between the specified source
string and the specified target string.
|
public DamerauLevenshteinAlgorithm(int deleteCost,
int insertCost,
int replaceCost,
int swapCost)
deleteCost - the cost of deleting a character.insertCost - the cost of inserting a character.replaceCost - the cost of replacing a character.swapCost - the cost of swapping two adjacent characters.Copyright © 1994–2024 Peter Murray-Rust. All rights reserved.