RapidFuzz
Loading...
Searching...
No Matches
distance.hpp
1/* SPDX-License-Identifier: MIT */
2/* Copyright © 2022 Max Bachmann */
3
4#pragma once
5
6#include <cmath>
7#include <rapidfuzz/details/Range.hpp>
8#include <rapidfuzz/details/common.hpp>
9#include <rapidfuzz/details/simd.hpp>
10#include <type_traits>
11
12namespace rapidfuzz {
13namespace detail {
14
15template <typename T, typename... Args>
16struct NormalizedMetricBase {
17 template <typename InputIt1, typename InputIt2,
18 typename = rapidfuzz::rf_enable_if_t<!std::is_same<InputIt2, double>::value>>
19 static double normalized_distance(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2,
20 Args... args, double score_cutoff, double score_hint)
21 {
22 return _normalized_distance(make_range(first1, last1), make_range(first2, last2),
23 std::forward<Args>(args)..., score_cutoff, score_hint);
24 }
25
26 template <typename Sentence1, typename Sentence2>
27 static double normalized_distance(const Sentence1& s1, const Sentence2& s2, Args... args,
28 double score_cutoff, double score_hint)
29 {
30 return _normalized_distance(make_range(s1), make_range(s2), std::forward<Args>(args)..., score_cutoff,
31 score_hint);
32 }
33
34 template <typename InputIt1, typename InputIt2,
35 typename = rapidfuzz::rf_enable_if_t<!std::is_same<InputIt2, double>::value>>
36 static double normalized_similarity(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2,
37 Args... args, double score_cutoff, double score_hint)
38 {
39 return _normalized_similarity(make_range(first1, last1), make_range(first2, last2),
40 std::forward<Args>(args)..., score_cutoff, score_hint);
41 }
42
43 template <typename Sentence1, typename Sentence2>
44 static double normalized_similarity(const Sentence1& s1, const Sentence2& s2, Args... args,
45 double score_cutoff, double score_hint)
46 {
47 return _normalized_similarity(make_range(s1), make_range(s2), std::forward<Args>(args)...,
48 score_cutoff, score_hint);
49 }
50
51protected:
52 template <typename InputIt1, typename InputIt2>
53 static double _normalized_distance(const Range<InputIt1>& s1, const Range<InputIt2>& s2, Args... args,
54 double score_cutoff, double score_hint)
55 {
56 auto maximum = T::maximum(s1, s2, args...);
57 auto cutoff_distance = NormDist_to_Dist(maximum, score_cutoff);
58 auto hint_distance = NormDist_to_Dist(maximum, score_hint);
59 auto dist = T::_distance(s1, s2, std::forward<Args>(args)..., cutoff_distance, hint_distance);
60 double norm_dist = (maximum != 0) ? static_cast<double>(dist) / static_cast<double>(maximum) : 0.0;
61 return (norm_dist <= score_cutoff) ? norm_dist : 1.0;
62 }
63
64 template <typename InputIt1, typename InputIt2>
65 static double _normalized_similarity(const Range<InputIt1>& s1, const Range<InputIt2>& s2, Args... args,
66 double score_cutoff, double score_hint)
67 {
68 double cutoff_score = NormSim_to_NormDist(score_cutoff);
69 double hint_score = NormSim_to_NormDist(score_hint);
70 double norm_dist =
71 _normalized_distance(s1, s2, std::forward<Args>(args)..., cutoff_score, hint_score);
72 double norm_sim = 1.0 - norm_dist;
73 return (norm_sim >= score_cutoff) ? norm_sim : 0.0;
74 }
75
76 NormalizedMetricBase()
77 {}
78 friend T;
79};
80
81template <typename T, typename ResType, int64_t WorstSimilarity, int64_t WorstDistance, typename... Args>
82struct DistanceBase : public NormalizedMetricBase<T, Args...> {
83 template <typename InputIt1, typename InputIt2,
84 typename = rapidfuzz::rf_enable_if_t<!std::is_same<InputIt2, double>::value>>
85 static ResType distance(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Args... args,
86 ResType score_cutoff, ResType score_hint)
87 {
88 return T::_distance(make_range(first1, last1), make_range(first2, last2), std::forward<Args>(args)...,
89 score_cutoff, score_hint);
90 }
91
92 template <typename Sentence1, typename Sentence2>
93 static ResType distance(const Sentence1& s1, const Sentence2& s2, Args... args, ResType score_cutoff,
94 ResType score_hint)
95 {
96 return T::_distance(make_range(s1), make_range(s2), std::forward<Args>(args)..., score_cutoff,
97 score_hint);
98 }
99
100 template <typename InputIt1, typename InputIt2,
101 typename = rapidfuzz::rf_enable_if_t<!std::is_same<InputIt2, double>::value>>
102 static ResType similarity(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Args... args,
103 ResType score_cutoff, ResType score_hint)
104 {
105 return _similarity(make_range(first1, last1), make_range(first2, last2), std::forward<Args>(args)...,
106 score_cutoff, score_hint);
107 }
108
109 template <typename Sentence1, typename Sentence2>
110 static ResType similarity(const Sentence1& s1, const Sentence2& s2, Args... args, ResType score_cutoff,
111 ResType score_hint)
112 {
113 return _similarity(make_range(s1), make_range(s2), std::forward<Args>(args)..., score_cutoff,
114 score_hint);
115 }
116
117protected:
118 template <typename InputIt1, typename InputIt2>
119 static ResType _similarity(Range<InputIt1> s1, Range<InputIt2> s2, Args... args, ResType score_cutoff,
120 ResType score_hint)
121 {
122 auto maximum = T::maximum(s1, s2, args...);
123 if (score_cutoff > maximum) return 0;
124
125 score_hint = std::min(score_cutoff, score_hint);
126 ResType cutoff_distance = maximum - score_cutoff;
127 ResType hint_distance = maximum - score_hint;
128 ResType dist = T::_distance(s1, s2, std::forward<Args>(args)..., cutoff_distance, hint_distance);
129 ResType sim = maximum - dist;
130 return (sim >= score_cutoff) ? sim : 0;
131 }
132
133 DistanceBase()
134 {}
135 friend T;
136};
137
138template <typename T, typename ResType, int64_t WorstSimilarity, int64_t WorstDistance, typename... Args>
139struct SimilarityBase : public NormalizedMetricBase<T, Args...> {
140 template <typename InputIt1, typename InputIt2,
141 typename = rapidfuzz::rf_enable_if_t<!std::is_same<InputIt2, double>::value>>
142 static ResType distance(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Args... args,
143 ResType score_cutoff, ResType score_hint)
144 {
145 return _distance(make_range(first1, last1), make_range(first2, last2), std::forward<Args>(args)...,
146 score_cutoff, score_hint);
147 }
148
149 template <typename Sentence1, typename Sentence2>
150 static ResType distance(const Sentence1& s1, const Sentence2& s2, Args... args, ResType score_cutoff,
151 ResType score_hint)
152 {
153 return _distance(make_range(s1), make_range(s2), std::forward<Args>(args)..., score_cutoff,
154 score_hint);
155 }
156
157 template <typename InputIt1, typename InputIt2,
158 typename = rapidfuzz::rf_enable_if_t<!std::is_same<InputIt2, double>::value>>
159 static ResType similarity(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Args... args,
160 ResType score_cutoff, ResType score_hint)
161 {
162 return T::_similarity(make_range(first1, last1), make_range(first2, last2),
163 std::forward<Args>(args)..., score_cutoff, score_hint);
164 }
165
166 template <typename Sentence1, typename Sentence2>
167 static ResType similarity(const Sentence1& s1, const Sentence2& s2, Args... args, ResType score_cutoff,
168 ResType score_hint)
169 {
170 return T::_similarity(make_range(s1), make_range(s2), std::forward<Args>(args)..., score_cutoff,
171 score_hint);
172 }
173
174protected:
175 template <typename InputIt1, typename InputIt2>
176 static ResType _distance(const Range<InputIt1>& s1, const Range<InputIt2>& s2, Args... args,
177 ResType score_cutoff, ResType score_hint)
178 {
179 auto maximum = T::maximum(s1, s2, args...);
180 ResType cutoff_similarity = (maximum >= score_cutoff)
181 ? DistCutoff_to_SimCutoff<ResType>(maximum, score_cutoff)
182 : static_cast<ResType>(WorstSimilarity);
183 ResType hint_similarity = (maximum >= score_hint)
184 ? DistCutoff_to_SimCutoff<ResType>(maximum, score_hint)
185 : static_cast<ResType>(WorstSimilarity);
186 ResType sim = T::_similarity(s1, s2, std::forward<Args>(args)..., cutoff_similarity, hint_similarity);
187 ResType dist = maximum - sim;
188 return _apply_distance_score_cutoff(dist, score_cutoff);
189 }
190
191 template <typename U>
192 static rapidfuzz::rf_enable_if_t<std::is_floating_point<U>::value, U>
193 _apply_distance_score_cutoff(U score, U score_cutoff)
194 {
195 return (score <= score_cutoff) ? score : 1.0;
196 }
197
198 template <typename U>
199 static rapidfuzz::rf_enable_if_t<!std::is_floating_point<U>::value, U>
200 _apply_distance_score_cutoff(U score, U score_cutoff)
201 {
202 return (score <= score_cutoff) ? score : score_cutoff + 1;
203 }
204
205 SimilarityBase()
206 {}
207 friend T;
208};
209
210template <typename T>
211struct CachedNormalizedMetricBase {
212 template <typename InputIt2>
213 double normalized_distance(InputIt2 first2, InputIt2 last2, double score_cutoff = 1.0,
214 double score_hint = 1.0) const
215 {
216 return _normalized_distance(make_range(first2, last2), score_cutoff, score_hint);
217 }
218
219 template <typename Sentence2>
220 double normalized_distance(const Sentence2& s2, double score_cutoff = 1.0, double score_hint = 1.0) const
221 {
222 return _normalized_distance(make_range(s2), score_cutoff, score_hint);
223 }
224
225 template <typename InputIt2>
226 double normalized_similarity(InputIt2 first2, InputIt2 last2, double score_cutoff = 0.0,
227 double score_hint = 0.0) const
228 {
229 return _normalized_similarity(make_range(first2, last2), score_cutoff, score_hint);
230 }
231
232 template <typename Sentence2>
233 double normalized_similarity(const Sentence2& s2, double score_cutoff = 0.0,
234 double score_hint = 0.0) const
235 {
236 return _normalized_similarity(make_range(s2), score_cutoff, score_hint);
237 }
238
239protected:
240 template <typename InputIt2>
241 double _normalized_distance(const Range<InputIt2>& s2, double score_cutoff, double score_hint) const
242 {
243 const T& derived = static_cast<const T&>(*this);
244 auto maximum = derived.maximum(s2);
245 auto cutoff_distance = NormDist_to_Dist(maximum, score_cutoff);
246 auto hint_distance = NormDist_to_Dist(maximum, score_hint);
247 double dist = static_cast<double>(derived._distance(s2, cutoff_distance, hint_distance));
248 double norm_dist = (maximum != 0) ? dist / static_cast<double>(maximum) : 0.0;
249 return (norm_dist <= score_cutoff) ? norm_dist : 1.0;
250 }
251
252 template <typename InputIt2>
253 double _normalized_similarity(const Range<InputIt2>& s2, double score_cutoff, double score_hint) const
254 {
255 double cutoff_score = NormSim_to_NormDist(score_cutoff);
256 double hint_score = NormSim_to_NormDist(score_hint);
257 double norm_dist = _normalized_distance(s2, cutoff_score, hint_score);
258 double norm_sim = 1.0 - norm_dist;
259 return (norm_sim >= score_cutoff) ? norm_sim : 0.0;
260 }
261
262 CachedNormalizedMetricBase()
263 {}
264 friend T;
265};
266
267template <typename T, typename ResType, int64_t WorstSimilarity, int64_t WorstDistance>
268struct CachedDistanceBase : public CachedNormalizedMetricBase<T> {
269 template <typename InputIt2>
270 ResType distance(InputIt2 first2, InputIt2 last2,
271 ResType score_cutoff = static_cast<ResType>(WorstDistance),
272 ResType score_hint = static_cast<ResType>(WorstDistance)) const
273 {
274 const T& derived = static_cast<const T&>(*this);
275 return derived._distance(make_range(first2, last2), score_cutoff, score_hint);
276 }
277
278 template <typename Sentence2>
279 ResType distance(const Sentence2& s2, ResType score_cutoff = static_cast<ResType>(WorstDistance),
280 ResType score_hint = static_cast<ResType>(WorstDistance)) const
281 {
282 const T& derived = static_cast<const T&>(*this);
283 return derived._distance(make_range(s2), score_cutoff, score_hint);
284 }
285
286 template <typename InputIt2>
287 ResType similarity(InputIt2 first2, InputIt2 last2,
288 ResType score_cutoff = static_cast<ResType>(WorstSimilarity),
289 ResType score_hint = static_cast<ResType>(WorstSimilarity)) const
290 {
291 return _similarity(make_range(first2, last2), score_cutoff, score_hint);
292 }
293
294 template <typename Sentence2>
295 ResType similarity(const Sentence2& s2, ResType score_cutoff = static_cast<ResType>(WorstSimilarity),
296 ResType score_hint = static_cast<ResType>(WorstSimilarity)) const
297 {
298 return _similarity(make_range(s2), score_cutoff, score_hint);
299 }
300
301protected:
302 template <typename InputIt2>
303 ResType _similarity(const Range<InputIt2>& s2, ResType score_cutoff, ResType score_hint) const
304 {
305 const T& derived = static_cast<const T&>(*this);
306 ResType maximum = derived.maximum(s2);
307 if (score_cutoff > maximum) return 0;
308
309 score_hint = std::min(score_cutoff, score_hint);
310 ResType cutoff_distance = maximum - score_cutoff;
311 ResType hint_distance = maximum - score_hint;
312 ResType dist = derived._distance(s2, cutoff_distance, hint_distance);
313 ResType sim = maximum - dist;
314 return (sim >= score_cutoff) ? sim : 0;
315 }
316
317 CachedDistanceBase()
318 {}
319 friend T;
320};
321
322template <typename T, typename ResType, int64_t WorstSimilarity, int64_t WorstDistance>
323struct CachedSimilarityBase : public CachedNormalizedMetricBase<T> {
324 template <typename InputIt2>
325 ResType distance(InputIt2 first2, InputIt2 last2,
326 ResType score_cutoff = static_cast<ResType>(WorstDistance),
327 ResType score_hint = static_cast<ResType>(WorstDistance)) const
328 {
329 return _distance(make_range(first2, last2), score_cutoff, score_hint);
330 }
331
332 template <typename Sentence2>
333 ResType distance(const Sentence2& s2, ResType score_cutoff = static_cast<ResType>(WorstDistance),
334 ResType score_hint = static_cast<ResType>(WorstDistance)) const
335 {
336 return _distance(make_range(s2), score_cutoff, score_hint);
337 }
338
339 template <typename InputIt2>
340 ResType similarity(InputIt2 first2, InputIt2 last2,
341 ResType score_cutoff = static_cast<ResType>(WorstSimilarity),
342 ResType score_hint = static_cast<ResType>(WorstSimilarity)) const
343 {
344 const T& derived = static_cast<const T&>(*this);
345 return derived._similarity(make_range(first2, last2), score_cutoff, score_hint);
346 }
347
348 template <typename Sentence2>
349 ResType similarity(const Sentence2& s2, ResType score_cutoff = static_cast<ResType>(WorstSimilarity),
350 ResType score_hint = static_cast<ResType>(WorstSimilarity)) const
351 {
352 const T& derived = static_cast<const T&>(*this);
353 return derived._similarity(make_range(s2), score_cutoff, score_hint);
354 }
355
356protected:
357 template <typename InputIt2>
358 ResType _distance(const Range<InputIt2>& s2, ResType score_cutoff, ResType score_hint) const
359 {
360 const T& derived = static_cast<const T&>(*this);
361 ResType maximum = derived.maximum(s2);
362 ResType cutoff_similarity =
363 (maximum > score_cutoff) ? DistCutoff_to_SimCutoff<ResType>(maximum, score_cutoff) : 0;
364 ResType hint_similarity =
365 (maximum > score_hint) ? DistCutoff_to_SimCutoff<ResType>(maximum, score_hint) : 0;
366 ResType sim = derived._similarity(s2, cutoff_similarity, hint_similarity);
367 ResType dist = maximum - sim;
368 return _apply_distance_score_cutoff(dist, score_cutoff);
369 }
370
371 template <typename U>
372 static rapidfuzz::rf_enable_if_t<std::is_floating_point<U>::value, U>
373 _apply_distance_score_cutoff(U score, U score_cutoff)
374 {
375 return (score <= score_cutoff) ? score : 1.0;
376 }
377
378 template <typename U>
379 static rapidfuzz::rf_enable_if_t<!std::is_floating_point<U>::value, U>
380 _apply_distance_score_cutoff(U score, U score_cutoff)
381 {
382 return (score <= score_cutoff) ? score : score_cutoff + 1;
383 }
384
385 CachedSimilarityBase()
386 {}
387 friend T;
388};
389
390template <typename T, typename ResType>
391struct MultiNormalizedMetricBase {
392 template <typename InputIt2>
393 void normalized_distance(double* scores, size_t score_count, InputIt2 first2, InputIt2 last2,
394 double score_cutoff = 1.0) const
395 {
396 _normalized_distance(scores, score_count, make_range(first2, last2), score_cutoff);
397 }
398
399 template <typename Sentence2>
400 void normalized_distance(double* scores, size_t score_count, const Sentence2& s2,
401 double score_cutoff = 1.0) const
402 {
403 _normalized_distance(scores, score_count, make_range(s2), score_cutoff);
404 }
405
406 template <typename InputIt2>
407 void normalized_similarity(double* scores, size_t score_count, InputIt2 first2, InputIt2 last2,
408 double score_cutoff = 0.0) const
409 {
410 _normalized_similarity(scores, score_count, make_range(first2, last2), score_cutoff);
411 }
412
413 template <typename Sentence2>
414 void normalized_similarity(double* scores, size_t score_count, const Sentence2& s2,
415 double score_cutoff = 0.0) const
416 {
417 _normalized_similarity(scores, score_count, make_range(s2), score_cutoff);
418 }
419
420protected:
421 template <typename InputIt2>
422 void _normalized_distance(double* scores, size_t score_count, const Range<InputIt2>& s2,
423 double score_cutoff = 1.0) const
424 {
425 const T& derived = static_cast<const T&>(*this);
426 if (score_count < derived.result_count())
427 throw std::invalid_argument("scores has to have >= result_count() elements");
428
429 // reinterpretation only works when the types have the same size
430 ResType* scores_orig = nullptr;
431
432 RAPIDFUZZ_IF_CONSTEXPR (sizeof(double) == sizeof(ResType))
433 scores_orig = reinterpret_cast<ResType*>(scores);
434 else
435 scores_orig = new ResType[derived.result_count()];
436
437 derived.distance(scores_orig, derived.result_count(), s2);
438
439 for (size_t i = 0; i < derived.get_input_count(); ++i) {
440 auto maximum = derived.maximum(i, s2);
441 double norm_dist =
442 (maximum != 0) ? static_cast<double>(scores_orig[i]) / static_cast<double>(maximum) : 0.0;
443 scores[i] = (norm_dist <= score_cutoff) ? norm_dist : 1.0;
444 }
445
446 RAPIDFUZZ_IF_CONSTEXPR (sizeof(double) != sizeof(ResType)) delete[] scores_orig;
447 }
448
449 template <typename InputIt2>
450 void _normalized_similarity(double* scores, size_t score_count, const Range<InputIt2>& s2,
451 double score_cutoff) const
452 {
453 const T& derived = static_cast<const T&>(*this);
454 _normalized_distance(scores, score_count, s2);
455
456 for (size_t i = 0; i < derived.get_input_count(); ++i) {
457 double norm_sim = 1.0 - scores[i];
458 scores[i] = (norm_sim >= score_cutoff) ? norm_sim : 0.0;
459 }
460 }
461
462 MultiNormalizedMetricBase()
463 {}
464 friend T;
465};
466
467template <typename T, typename ResType, int64_t WorstSimilarity, int64_t WorstDistance>
468struct MultiDistanceBase : public MultiNormalizedMetricBase<T, ResType> {
469 template <typename InputIt2>
470 void distance(ResType* scores, size_t score_count, InputIt2 first2, InputIt2 last2,
471 ResType score_cutoff = static_cast<ResType>(WorstDistance)) const
472 {
473 const T& derived = static_cast<const T&>(*this);
474 derived._distance(scores, score_count, make_range(first2, last2), score_cutoff);
475 }
476
477 template <typename Sentence2>
478 void distance(ResType* scores, size_t score_count, const Sentence2& s2,
479 ResType score_cutoff = static_cast<ResType>(WorstDistance)) const
480 {
481 const T& derived = static_cast<const T&>(*this);
482 derived._distance(scores, score_count, make_range(s2), score_cutoff);
483 }
484
485 template <typename InputIt2>
486 void similarity(ResType* scores, size_t score_count, InputIt2 first2, InputIt2 last2,
487 ResType score_cutoff = static_cast<ResType>(WorstSimilarity)) const
488 {
489 _similarity(scores, score_count, make_range(first2, last2), score_cutoff);
490 }
491
492 template <typename Sentence2>
493 void similarity(ResType* scores, size_t score_count, const Sentence2& s2,
494 ResType score_cutoff = static_cast<ResType>(WorstSimilarity)) const
495 {
496 _similarity(scores, score_count, make_range(s2), score_cutoff);
497 }
498
499protected:
500 template <typename InputIt2>
501 void _similarity(ResType* scores, size_t score_count, const Range<InputIt2>& s2,
502 ResType score_cutoff) const
503 {
504 const T& derived = static_cast<const T&>(*this);
505 derived._distance(scores, score_count, s2);
506
507 for (size_t i = 0; i < derived.get_input_count(); ++i) {
508 ResType maximum = derived.maximum(i, s2);
509 ResType sim = maximum - scores[i];
510 scores[i] = (sim >= score_cutoff) ? sim : 0;
511 }
512 }
513
514 MultiDistanceBase()
515 {}
516 friend T;
517};
518
519template <typename T, typename ResType, int64_t WorstSimilarity, int64_t WorstDistance>
520struct MultiSimilarityBase : public MultiNormalizedMetricBase<T, ResType> {
521 template <typename InputIt2>
522 void distance(ResType* scores, size_t score_count, InputIt2 first2, InputIt2 last2,
523 ResType score_cutoff = static_cast<ResType>(WorstDistance)) const
524 {
525 _distance(scores, score_count, make_range(first2, last2), score_cutoff);
526 }
527
528 template <typename Sentence2>
529 void distance(ResType* scores, size_t score_count, const Sentence2& s2,
530 ResType score_cutoff = static_cast<ResType>(WorstDistance)) const
531 {
532 _distance(scores, score_count, make_range(s2), score_cutoff);
533 }
534
535 template <typename InputIt2>
536 void similarity(ResType* scores, size_t score_count, InputIt2 first2, InputIt2 last2,
537 ResType score_cutoff = static_cast<ResType>(WorstSimilarity)) const
538 {
539 const T& derived = static_cast<const T&>(*this);
540 derived._similarity(scores, score_count, make_range(first2, last2), score_cutoff);
541 }
542
543 template <typename Sentence2>
544 void similarity(ResType* scores, size_t score_count, const Sentence2& s2,
545 ResType score_cutoff = static_cast<ResType>(WorstSimilarity)) const
546 {
547 const T& derived = static_cast<const T&>(*this);
548 derived._similarity(scores, score_count, make_range(s2), score_cutoff);
549 }
550
551protected:
552 template <typename InputIt2>
553 void _distance(ResType* scores, size_t score_count, const Range<InputIt2>& s2, ResType score_cutoff) const
554 {
555 const T& derived = static_cast<const T&>(*this);
556 derived._similarity(scores, score_count, s2);
557
558 for (size_t i = 0; i < derived.get_input_count(); ++i) {
559 ResType maximum = derived.maximum(i, s2);
560 ResType dist = maximum - scores[i];
561 scores[i] = _apply_distance_score_cutoff(dist, score_cutoff);
562 }
563 }
564
565 template <typename U>
566 static rapidfuzz::rf_enable_if_t<std::is_floating_point<U>::value, U>
567 _apply_distance_score_cutoff(U score, U score_cutoff)
568 {
569 return (score <= score_cutoff) ? score : 1.0;
570 }
571
572 template <typename U>
573 static rapidfuzz::rf_enable_if_t<!std::is_floating_point<U>::value, U>
574 _apply_distance_score_cutoff(U score, U score_cutoff)
575 {
576 return (score <= score_cutoff) ? score : score_cutoff + 1;
577 }
578
579 MultiSimilarityBase()
580 {}
581 friend T;
582};
583
584} // namespace detail
585} // namespace rapidfuzz