From 04969928a7578aec48dfe8b4b82fc1030e77c74b Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 2 Jan 2022 15:44:28 +0100 Subject: [PATCH] Fix incorrect normalization for legacy scorers --- src/cpp_string_metric.hpp | 58 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/src/cpp_string_metric.hpp b/src/cpp_string_metric.hpp index acee291..6084639 100644 --- a/src/cpp_string_metric.hpp +++ b/src/cpp_string_metric.hpp @@ -1,6 +1,56 @@ #pragma once #include "cpp_common.hpp" + +template +static inline bool legacy_scorer_func_wrapper_f64(const RF_ScorerFunc* self, const RF_String* str, double score_cutoff, double* result) +{ + CachedScorer& scorer = *(CachedScorer*)self->context; + try { + *result = visit(*str, [&](auto s){ + return scorer.ratio(s, score_cutoff); + }) * 100; + } catch(...) { + PyGILState_STATE gilstate_save = PyGILState_Ensure(); + CppExn2PyErr(); + PyGILState_Release(gilstate_save); + return false; + } + return true; +} + +template