<summary>///Calculate Text Edit Distance Utility Class///</summary> public static CLA SS Texteditdistanceutility {///<summary>///get edit distance between two string///
</summary>///<param name= "str1" ></param>///<param name= "str2" ></param>
<returns></returns> public static int geteditdistance (string str1, String str2) {
if (str1 = = str2) return 0;
else if (String.IsNullOrEmpty (str1) && string.isnullorempty (str2)) return 0; else if (String.IsNullOrEmpty (STR1) &&! String.IsNullOrEmpty (STR2)) return str2.
Length; else if (! String.IsNullOrEmpty (str1) && string.isnullorempty (str2)) return str1.
Length; int[,] D = new int[str1. Length + 1, str2.
Length + 1];
D.initialize ();
int cost = 0; for (int i = 0; i < D.getLength (0);
i++) {d[i, 0] = i;
for (int j = 0; J < d.getlength (1); J + +) {d[0, j] = J; for (int i = 0; i < str1. Length; i++) {for (int j = 0; J < str2. Length;
J + +) {if (str1[i] = = Str2[j]) cost = 0;
else cost = 1;
D[i + 1, j + 1] = Math.min (Math.min (D[i, J + 1] + 1, D[i + 1, j] + 1), math.min (D[i + 1, j] + 1, d[i, J] + cost); } return D[STR1. Length, str2.
Length]; }
}
Edit distance is to compare the number of basic operations between two strings to become the other operation, add a character, delete a character, modify a character, are counted as an operation
For example ABB and BBB, edit distance is 1,abc into AA, edit distance is 2
The application of this algorithm is more than two times the difference between the results of how much