Avoid division by zero when computing the scalar product of two quotes

This commit is contained in:
Tissevert 2024-03-16 15:49:23 +01:00
parent b9066f0933
commit a0bba7173f

View file

@ -55,7 +55,8 @@ We define a similarity measure on sets which counts the number of elements
they have in common they have in common
""" """
def scalar(a, b): def scalar(a, b):
return len(a.intersection(b))/sqrt(len(a)*len(b)) sizeProduct = len(a)*len(b)
return len(a.intersection(b))/sqrt(sizeProduct) if sizeProduct > 0 else 0
def find_best_quote(db, user_input): def find_best_quote(db, user_input):
indexed_input = index(user_input) indexed_input = index(user_input)