Class DamerauOSADistance
- All Implemented Interfaces:
EditDistance
Counts insertions, deletions and substitutions, plus transpositions of two adjacent symbols, each with a unit cost. As an optimal-string-alignment metric, a given substring may not be edited more than once, which is the variant used by the SymSpell reference implementation.
This is the default edit distance for the engine. It 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. A bounded computation with early exit is
provided through distance(CharSequence, CharSequence, int).
-
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
-
DamerauOSADistance
public DamerauOSADistance()
-
-
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
-