import jieba
from collections import Counter
import difflib
def edit_similar(str1,str2):
len_str1=len(str1)
len_str2=len(str2)
taglist=np.zeros((len_str1+1,len_str2+1))
for a in range(len_str1):
taglist[a][0]=a
for a in range(len_str2):
taglist[0][a] = a
for i in range(1,len_str1+1):
for j in range(1,len_str2+1):
if(str1[i - 1] == str2[j - 1]):
temp = 0
else:
temp = 1
taglist[i][j] = min(taglist[i - 1][j - 1] + temp, taglist[i][j - 1] + 1, taglist[i - 1][j] + 1)
return 1-taglist[len_str1][len_str2] / max(len_str1, len_str2)
def cos_sim(str1, str2):
co_str1 = (Counter(str1))
co_str2 = (Counter(str2)
几种短文本相似计算方法
最新推荐文章于 2023-04-24 17:22:36 发布