Package opennlp.spellcheck.distance
Class LevenshteinDistance
java.lang.Object
opennlp.spellcheck.distance.LevenshteinDistance
- All Implemented Interfaces:
EditDistance
Plain Levenshtein edit distance (insertions, deletions, substitutions; no
transpositions). Offered as a selectable alternative to the default
DamerauOSADistance, with which it shares the bounded EditDistance
contract; the only behavioural difference is that an adjacent transposition costs two
edits here (one deletion plus one insertion) rather than one.
The computation is bounded with early exit and is Unicode-aware: comparison happens on Unicode code points, so characters outside the Basic Multilingual Plane (e.g. many emoji) are treated as single symbols.
Instances are immutable and thread-safe.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintdistance(CharSequence a, CharSequence b, int max) Computes the edit distance betweenaandb, giving up early once it is certain the distance exceedsmax.
-
Field Details
-
INSTANCE
Shared, stateless instance.
-
-
Constructor Details
-
LevenshteinDistance
public LevenshteinDistance()
-
-
Method Details
-
distance
Description copied from interface:EditDistanceComputes the edit distance betweenaandb, giving up early once it is certain the distance exceedsmax.A
maxof0is permitted and meaningful: it asks only whether the two sequences are equal, returning0when they are and-1as soon as any difference is found. It is the natural lower bound of the contract, not a degenerate case.- Specified by:
distancein interfaceEditDistance- Parameters:
a- the first sequence; must not benullb- the second sequence; must not benullmax- the maximum acceptable distance; must not be negative (>= 0)- Returns:
- the edit distance, or
-1if it is strictly greater thanmax
-