1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""Levenshtein edit distance between `a` and `b`.
Input is normalised (trimmed, lowercased, diacritics stripped)
before comparison. Returns the minimum number of single-character
edits (insert, delete, substitute) to turn `a` into `b`.
"""
...
"""Jaro-Winkler similarity between `a` and `b`, in `[0.0, 1.0]`.
Gives a bonus for shared prefixes — works well for names and short
strings. Input is normalised before comparison.
"""
...
"""Trigram (Dice coefficient) similarity in `[0.0, 1.0]`.
Splits both strings into overlapping 3-character chunks and scores
overlap. Good for longer strings and typo detection.
"""
...
"""Weighted blend of Levenshtein, Jaro-Winkler, and trigram in `[0.0, 1.0]`.
Used internally by `best_match`, `rank_matches`, and
`batch_best_match`. Higher is more similar.
"""
...
"""Order-invariant similarity via `combined_score` over sorted tokens.
Useful when word order varies, e.g. `"Oat Drink Oatly 1L"` vs
`"Oatly Oat Drink 1L"`. Returns a score in `[0.0, 1.0]`.
"""
...
"""Like `token_sort_ratio` but also deduplicates tokens before comparing.
Useful when one string repeats words the other doesn't.
Returns a score in `[0.0, 1.0]`.
"""
...
"""Return the best `(candidate, score)` for `query`, or `None`.
If `threshold` is set and the best score is below it, returns `None`.
"""
...
"""Return all candidates ranked by similarity, highest first.
Candidates with a score below `threshold` are filtered out.
"""
...
"""Return the best match per query — parallelised via rayon.
The candidate list is normalised once and shared across all queries.
Each result is `None` if no candidate scored above `threshold`.
"""
...