如何获得一个字符串与Python中另一个字符串相似的概率? 我想得到一个十进制值,例如0.9(表示90%)等。最好使用标准Python和库。 例如 similar("Apple","Appel") #would have a high prob. similar("Apple","Mango") #would have a lower prob.
从Python:tf-idf-cosine:查找文档相似度,可以使用tf-idf余弦计算文档相似度。如果不导入外部库,是否有任何方法可以计算2个字符串之间的余弦相似度? s1 = "This is a foo bar sentence ." s2 = "This sentence is similar to a foo bar sentence ." s3 = "What is this string ? Totally not related to the other two lines ." cosine_sim(s1, s2) # Should give high cosine similarity cosine_sim(s1, s3) # Shouldn't …