给定一个字符串,

string name = "Michael";

我希望能够计算数组中哪个字符串最相似:
string[] names = new[] { "John", "Adam", "Paul", "Mike", "John-Michael" };

我想为用户创建一条消息:“我们找不到‘michael’,但‘john michael’很接近。这就是你的意思吗?”我要怎么做这个决定?

最佳答案

下面是使用Levenshtein距离的示例结果:

EditDistance["Michael",#]&/@{"John","Adam","Paul","Mike","John-Michael"}
{6,6,5,4,5}

这里有史密斯-沃特曼相似性检验的结果
SmithWatermanSimilarity["Michael",#]&/@{"John","Adam","Paul","Mike","John-Michael"}
{0.,0.,0.,2.,7.}

啊!

10-08 16:17