def similarity_ratio(x, y, threshold=FuzzyMatchGenerator.SIMILARITY_THRESHOLD):
"""Compute the similarity ratio between two strings.
If the ratio exceeds the threshold, return it; otherwise, return 0.
The similarity ratio is given by
1 - (levenshtein distance with substitution cost = 2) / (total length)
"""
ratio = Levenshtein.ratio(x, y)
return ratio if ratio > threshold else 0.
################################
# NERValueGenerator
评论列表
文章目录