From cdb1d90140beddfa0206d264bcb124e002e801ca Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Sat, 21 Jul 2018 14:15:21 +0200 Subject: [PATCH] Fixed crashes in certain error situations. --- string_distance.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/string_distance.lua b/string_distance.lua index f0bd122..fb36603 100644 --- a/string_distance.lua +++ b/string_distance.lua @@ -186,12 +186,10 @@ local function strings_with_highest_similarity (str, list_of_other_str) -- Calculate similarity metrics for _, other_str in ipairs(list_of_other_str) do local total_sim = 0 - --print(other_str) for _, similarity_func in ipairs(SIMILARITY_METRICS) do - local sim, max_sim, min_sim = similarity_func(str, other_str) - assert(max_sim ~= min_sim) + local sim, max_sim, min_sim = similarity_func(str, other_str) + assert(min_sim <= max_sim) total_sim = total_sim + (sim-min_sim)/(max_sim-min_sim) - --print('', sim, (sim-min_sim)/(max_sim-min_sim)) end possible[#possible+1] = {other_str, total_sim} --print('\tTotal: '.. total_sim) @@ -213,3 +211,4 @@ return { jaccard_similarity_of_words = jaccard_similarity_of_words, strings_with_highest_similarity = strings_with_highest_similarity, } +