def score_match(query_rep, text, length_penalty, dictionary=None, debug=False):
if text == "":
return 0
if not dictionary:
words = text.lower().split(' ')
else:
words = [w for w in dictionary.tokenize(text.lower())]
score = 0
rw = query_rep['words']
used = {}
for w in words:
if w in rw and w not in used:
score += rw[w]
if debug:
print("match: " + w)
used[w] = True
norm = math.sqrt(len(used))
score = score / math.pow(norm * query_rep['norm'], length_penalty)
return score
评论列表
文章目录