Skip to main content

Crate goldenfuzz_core

Crate goldenfuzz_core 

Source
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:

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§

BatchComparator
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 query against each choice with scorer (the query peq is built once), keeps scores >= score_cutoff, and returns up to limit (choice_index, score) pairs, highest score first (ties broken by lower index). limit == 0 means no limit.
indel_ratio
rapidfuzz::fuzz::ratio == Indel normalized_similarity on [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], matching rapidfuzz::distance::jaro_winkler::normalized_similarity with the default prefix_weight = 0.1. Operates on Unicode codepoints.
jaro_winkler_chars
Slice form (lets score_one/callers avoid re-collecting when they already hold Vec<char>). prefix_weight fixed at rapidfuzz’s default 0.1.
levenshtein_distance
Uniform-weight Levenshtein edit distance, bit-parallel (Myers 1999). The PATTERN a is packed one bit per position; each text char advances the vertical-delta vectors pv/mv with 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 -> 0 distance -> 1.0 sim).
partial_ratio
fuzz.partial_ratio in [0, 100].
partial_token_ratio
fuzz.partial_token_ratio in [0, 100].
partial_token_set_ratio
fuzz.partial_token_set_ratio in [0, 100].
partial_token_sort_ratio
fuzz.partial_token_sort_ratio in [0, 100].
q_ratio
fuzz.QRatio = ratio, except two empty (or one-empty) strings return 0.
ratio
fuzz.ratio in [0, 100] (Indel normalized similarity * 100).
token_ratio
fuzz.token_ratio = max(token_set_ratio, token_sort_ratio).
token_set_ratio
fuzz.token_set_ratio in [0, 100].
token_sort_ratio
fuzz.token_sort_ratio in [0, 100].
w_ratio
fuzz.WRatio — the composite weighted ratio in [0, 100]. Empty input -> 0.