Skip to content

Text 0.3.1 dameraulevenshtein normalizedsimilarity

github-actions[bot] edited this page Aug 16, 2026 · 1 revision

Lodestar.Text 0.3.1. This page is frozen at that release. Read the current documentation for what main says now. A link to a decision or a migration page follows main, and leaves the archive.

DamerauLevenshtein.NormalizedSimilarity

1 - NormalizedDistance: 1 when the two are identical, 0 when nothing is shared.

public static double NormalizedSimilarity(ReadOnlySpan<char> a, ReadOnlySpan<char> b, TextElement element = TextElement.Utf16Unit)

Parametersa and b are the two strings to compare; element says what counts as one character, exactly as it does for NormalizedDistance, which this is computed from.

Returnsdouble in [0, 1], larger meaning more alike.

Example — the same pair as above, read the other way round.

using Lodestar.Text.Distances;

double s = DamerauLevenshtein.NormalizedSimilarity("MARTHA", "MARHTA");   // => 0.8333…

Remarks — use this rather than NormalizedDistance wherever a bigger number ought to mean a better match: ranking candidates, sorting descending, or handing a score to something that expects one. Nothing else about the two differs.

The trap is the empty case. NormalizedDistance("", "") is 0, so this returns 1 — two empty strings are reported as a perfect match. If an empty string means "this field was never filled in", that is exactly backwards, and the filtering has to happen before the call.

Applies to — net10.0, netstandard2.0.

See alsoDamerauLevenshtein.NormalizedDistance, Osa.NormalizedSimilarity, Levenshtein.NormalizedSimilarity, the Python equivalence table.

Lodestar

Project

Clone this wiki locally