Fuzzy process extract - CyrilB1531/lodestar GitHub Wiki

Development build. This page describes main, not a released package. The latest published Lodestar.Fuzzy is 0.4.0 — read its documentation.

HomeFuzzyFuzzy matching

Process.Extract

The best candidates, ranked.

public static IReadOnlyList<ExtractResult> Extract(string query, IEnumerable<string> choices, Func<string, string, double> scorer = null, int? limit = 5, double scoreCutoff = 0)

Parametersquery is what to match. choices are the candidates. scorer is the scoring function, Fuzz.WRatio when omitted. limit caps how many come back, 5 by default and null for all of them. scoreCutoff drops anything scoring below it.

ReturnsIReadOnlyList<ExtractResult>, best first, at most limit long.

ExceptionsArgumentNullException when query or choices is null. ArgumentOutOfRangeException when limit is negative; 0 returns an empty list.

Example — the two best of four candidates.

using Lodestar.Fuzzy;

string[] choices = ["apple pie", "apple tart", "banana bread", "cherry pie"];

IReadOnlyList<ExtractResult> best = Process.Extract("apple pie", choices, limit: 2);

int returned = best.Count;  // => 2
string first = best[0].Choice;  // => apple pie
int where = best[0].Index;  // => 0

Remarks — the default limit of 5 is rapidfuzz's, and it is a cap rather than a guarantee: fewer come back when fewer clear the cutoff, and passing null returns every candidate ranked, which on a large list is the expensive call.

scoreCutoff filters after scoring: every candidate is scored in full and the ones below the cutoff are dropped, so it makes the result shorter and the heap smaller, not the scoring faster. For rapidfuzz's scores on text outside the BMP, pass a code-point scorer, such as (q, c) => Fuzz.WRatio(q, c, TextElement.CodePoint).

Each result carries its Index, which is how a match is traced back to the record it came from rather than to the string.

Applies to — net10.0, netstandard2.0.

See alsoProcess.ExtractOne, ExtractResult.

⚠️ **GitHub.com Fallback** ⚠️