Text 0.5.0 jarowinkler distance - CyrilB1531/lodestar GitHub Wiki
Lodestar.Text 0.5.0. This page is frozen at that release. Read the current documentation for what
mainsays now. A link to a decision or a migration page followsmain, and leaves the archive.
1 - Similarity, for code that wants a distance rather than a score.
public static double Distance(ReadOnlySpan<char> a, ReadOnlySpan<char> b, double prefixWeight = 0.1, TextElement element = TextElement.Utf16Unit)Parameters — a and b are the two strings to compare, prefixWeight is what each shared
leading character is worth (0.1 by default) and element says what counts as one character —
all
three exactly as for Similarity, which this subtracts from 1.
Returns — double, normally in [0, 1] and larger meaning less alike.
Example — a swapped pair of letters, forgiven almost entirely because the prefix agrees.
using Lodestar.Text.Distances;
double d = JaroWinkler.Distance("MARTHA", "MARHTA"); // => 0.0388…Remarks — the same measure as Similarity, turned round for code that sorts ascending or
thresholds with "at most". Nothing else differs.
It inherits Similarity's unvalidated prefixWeight, and inverts its consequence: a weight above
0.25 can push the similarity past 1 and therefore this below zero. A negative distance
breaks the assumption that most clustering and nearest-neighbour code makes without stating it, so
leave prefixWeight alone unless you have a reason and a test.
Applies to — net10.0, netstandard2.0.
See also — JaroWinkler.Similarity, Jaro.Distance,
the Python equivalence table.