# -*- coding:utf-8 -*-
#2018/04/23
#标签相似度计算
import numpy as np
value1="娃娃鞋"
value2="宝贝儿童鞋"
def xsd(value1,value2):
i=len(value1)
j=len(value2)
sz=np.zeros((i+1,j+1))
for a in range(i+1):
sz[a][0]=a
for a in range(j+1):
sz[0][a]=a
for b in range(1,i+1):
for c in range(1,j+1):
if value1[b-1]==value2[c-1]:
temp=0
else:
temp=1
sz[b][c]=min(sz[b-1][c-1]+temp,sz[b][c-1]+1,sz[b-1][c]+1)
print(1-(sz[i][j]/max(i,j)))
xsd(value1,value2)
计算结果:0.19999999999999996