就比较名称而言,您可能想看看Levenshtein 距离算法。给定两个字符串,它将计算一个距离测量值,该测量值可用作捕获重复项的基础。
我个人在我为一个应用程序开发的工具中使用了它,该应用程序具有相当大的数据库,其中包含大量重复项。将它与与我的领域相关的一些其他数据比较结合使用,我能够将我的工具指向应用程序数据库并快速找到许多重复的记录。不会撒谎,我认为看到实际操作非常酷。
它甚至可以快速实现,这是一个C# 版本:
public int CalculateDistance(string s, string t) {
int n = s.Length; //length of s
int m = t.Length; //length of t
int[,] d = new int[n + 1, m + 1]; // matrix
int cost; // cost
// Step 1
if (n == 0) return m;
if (m == 0) return n;
// Step 2
for (int i = 0; i <= n; d[i, 0] = i++) ;
for (int j = 0; j <= m; d[0, j] = j++) ;
// Step 3
for (int i = 1; i <= n; i++) {
//Step 4
for (int j = 1; j <= m; j++) {
// Step 5
cost = (t.Substring(j - 1, 1) == s.Substring(i - 1, 1) ? 0 : 1);
// Step 6
d[i, j] = System.Math.Min(System.Math.Min(d[i - 1, j] + 1, d[i, j - 1] + 1), d[i - 1, j - 1] + cost);
}
}
// Step 7
return d[n, m];
}