Fuzzy fuzz partialratio - 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

Fuzz.PartialRatio

The best-matching window of the longer string.

public static double PartialRatio(string a, string b)
public static double PartialRatio(string a, string b, TextElement element)

The second overload compares over element. At TextElement.CodePoint a character outside the Basic Multilingual Plane counts once, tokens split on rapidfuzz's own whitespace and sort by code point, which is rapidfuzz's score on any string; TextElement.Utf16Unit is the first overload.

Parametersa and b are the strings to compare; which is longer does not matter. element is the unit compared, in the second overload only.

Returnsdouble in [0, 100], the best Ratio over any window of the longer string as long as the shorter.

ExceptionsArgumentOutOfRangeException when element is not a declared value. ArgumentException when the two strings hold more than 63,455 distinct code points above U+0020, which is what a char can rank one unit per code point; Fuzz.Ratio answers such a pair, these scorers do not yet.

Example — a short string contained in a longer one.

using Lodestar.Fuzzy;

double contained = Fuzz.PartialRatio("apple", "an apple a day");  // => 100

Remarks100, because apple appears verbatim inside the longer string. Ratio on the same pair is far lower, and both are correct: one asks "are these the same string", the other "does the short one occur in the long one".

Reach for it when one side is a fragment — a search box against titles, a product name against a description. Do not reach for it when the two are the same kind of thing, because it will happily score 100 for a short string that matches a small part of a long one and means something else.

An emoji is two UTF-16 units, so the first overload scores two different emoji that share a high surrogate as half alike, where rapidfuzz scores them 0; pass TextElement.CodePoint when the text can leave the BMP, as decision 0001 offers on every algorithm it affects.

Applies to — net10.0, netstandard2.0.

See alsoFuzz.Ratio, Fuzz.PartialTokenSortRatio.