Expand description
Vendored string-similarity primitives — GoldenMatch’s OWN implementations of
the four metrics the scorer surface needs, replacing the rapidfuzz crate on
the shipped path so the “one authoritative semantic owner per capability”
invariant holds for the scoring math itself (not a black box).
Slice 1 of the rapidfuzz-ownership epic. These are faithful, byte-identical
ports of rapidfuzz-rs 0.5.0’s scalar normalized_similarity / distance:
jaro_winkler==jaro_winkler::normalized_similarity(prefix_weight 0.1)levenshtein_normalized_similarity==levenshtein::normalized_similarityindel_ratio==fuzz::ratio(Indel normalized_similarity, [0,1])damerau_levenshtein_distance==damerau_levenshtein::distance(true DL)
rapidfuzz’s bit-parallel machinery (Myers/Hyyrö, SIMD batch) is an optimization: the integer distances / LCS / Jaro match+transposition counts it produces are exact and identical to a correct naive computation, so byte-identical output only requires (a) the same final float arithmetic and (b) rapidfuzz’s Jaro match order (iterate the text string, greedily bind the lowest unflagged pattern position in the window). Both are replicated below.
Byte-identical output is PROVEN, not assumed: the parity test module (built
only with the rapidfuzz dev-dependency) asserts f64::to_bits equality
against the crate over a large randomized + adversarial corpus.
Structs§
- Batch
Comparator - A query prepared for one-vs-many scoring (rapidfuzz’s
BatchComparator/cdist). Byte-identical to the per-pair scorers.
Enums§
- Scorer
- Which normalized-similarity scorer the batch API uses (all on
[0, 1]).
Functions§
- cdist
- Full one-vs-many score matrix:
out[i][j]=scorer(queries[i], choices[j]). Each query’s peq is built once and reused across all choices. - damerau_
levenshtein_ distance - True Damerau-Levenshtein edit distance (adjacent transposition = 1 edit,
unrestricted), matching
rapidfuzz::distance::damerau_levenshtein::distance. Integer result; used by the date comparator over 8 packed digits. - extract
- One-vs-many top-k. Scores
queryagainst each choice withscorer(the query peq is built once), keeps scores>= score_cutoff, and returns up tolimit(choice_index, score)pairs, highest score first (ties broken by lower index).limit == 0means no limit. - indel_
ratio rapidfuzz::fuzz::ratio== Indelnormalized_similarityon[0, 1]: indel distance= len1 + len2 - 2*lcs, maximum= len1 + len2,sim = 1.0 - dist / maximum(maximum == 0 -> 1.0).- jaro_
winkler - Jaro-Winkler normalized similarity on
[0, 1], matchingrapidfuzz::distance::jaro_winkler::normalized_similaritywith the defaultprefix_weight = 0.1. Operates on Unicode codepoints. - jaro_
winkler_ chars - Slice form (lets
score_one/callers avoid re-collecting when they already holdVec<char>).prefix_weightfixed at rapidfuzz’s default 0.1. - levenshtein_
distance - Uniform-weight Levenshtein edit distance, bit-parallel (Myers 1999). The
PATTERN
ais packed one bit per position; each text char advances the vertical-delta vectorspv/mvwith a fixed set of word ops. Integer result identical to the naive Wagner-Fischer DP and to rapidfuzz (proven in tests). - levenshtein_
normalized_ similarity rapidfuzz::distance::levenshtein::normalized_similarity:1.0 - dist / max(len1, len2)(maximum == 0 -> 0distance -> 1.0 sim).- partial_
ratio fuzz.partial_ratioin[0, 100].- partial_
token_ ratio fuzz.partial_token_ratioin[0, 100].- partial_
token_ set_ ratio fuzz.partial_token_set_ratioin[0, 100].- partial_
token_ sort_ ratio fuzz.partial_token_sort_ratioin[0, 100].- q_ratio
fuzz.QRatio=ratio, except two empty (or one-empty) strings return 0.- ratio
fuzz.ratioin[0, 100](Indel normalized similarity * 100).- token_
ratio fuzz.token_ratio=max(token_set_ratio, token_sort_ratio).- token_
set_ ratio fuzz.token_set_ratioin[0, 100].- token_
sort_ ratio fuzz.token_sort_ratioin[0, 100].- w_ratio
fuzz.WRatio— the composite weighted ratio in[0, 100]. Empty input -> 0.