Fuzzy fuzz tokensortratio - 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.
Home › Fuzzy › Fuzzy matching
Fuzz.TokenSortRatio
The words sorted before comparing, so their order stops counting.
public static double TokenSortRatio(string a, string b)
public static double TokenSortRatio(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.
Parameters — a and b are the strings to compare. element is the unit compared, in the second overload only.
Returns — double in [0, 100], the Ratio of the two strings after each
is split into words, sorted and rejoined.
Exceptions — ArgumentOutOfRangeException 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 — the same words in a different order.
using Lodestar.Fuzzy;
double reordered = Fuzz.TokenSortRatio("new york mets", "mets new york"); // => 100
Remarks — 100, where Ratio on the same pair is much lower. Word order is
the difference, and for names, addresses and titles it usually carries no meaning — "Smith, John"
and "John Smith" are one person.
It still counts extra words against you: a side with a word the other lacks scores lower, which
is the difference from TokenSetRatio.
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 also — Fuzz.TokenSetRatio, Fuzz.Ratio.