c语言sscanf函数的用法是什么
292
2022-11-30
C# 计算两个字符的相似度
//计算相似度 public static double LevenshteinDistanceSimilarty(string str1, string str2) { if (string.IsNullOrEmpty(str1) || string.IsNullOrEmpty(str2)) return 0; int str1Length = str1.Length; int str2Length = str2.Length; int[,] index = new int[str1Length, str2Length]; if (str1Length == 0 || str2Length == 0) return 0; for (int i = 0; i < str1Length; i++) { for (int j = 0; j < str2Length; j++) { int k = str1[i] == str2[j] ? 0 : 1; if (i == 0 && j == 0) continue; else if (i == 0) { index[i, j] = k + index[i, j - 1]; continue; } else if (j == 0) { index[i, j] = k + index[i - 1, j]; continue; } int temp = Min(index[i, j - 1], index[i - 1, j], index[i - 1, j - 1]); index[i, j] = temp + k; } } double distance = index[str1Length - 1, str2Length - 1]; double maxLength = str1Length > str2Length ? str1Length : str2Length; double similarty = 1 - (double)distance / maxLength; return similarty; } //交换比 private static int Min(int a, int b, int c) { int temp = a < b ? a : b; temp = temp < c ? temp : c; return temp; }
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~