Fuzzy process extract - CyrilB1531/lodestar GitHub Wiki
Development build. This page describes
main, not a released package. The latest published Lodestar.Fuzzy is 0.5.0 — read its documentation.
Home › Fuzzy › Fuzzy matching
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)Parameters — query is what to match; a null one matches nothing. choices are the candidates,
a null one skipped with its index kept. Both follow rapidfuzz's None
(#1233). 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.
Returns — IReadOnlyList<ExtractResult>, best first, at most limit long.
Exceptions — ArgumentNullException when choices is null, and ArgumentOutOfRangeException
when limit is negative — neither when query is null, which answers an empty list first, as
rapidfuzz does. A limit of 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; // => 0Remarks — 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 also — Process.ExtractOne,
ExtractResult.