Avoid division by zero when computing the scalar product of two quotes
This commit is contained in:
parent
b9066f0933
commit
a0bba7173f
1 changed files with 2 additions and 1 deletions
|
@ -55,7 +55,8 @@ We define a similarity measure on sets which counts the number of elements
|
|||
they have in common
|
||||
"""
|
||||
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):
|
||||
indexed_input = index(user_input)
|
||||
|
|
Loading…
Reference in a new issue