Actual application, two string similarity determination, to remove punctuation, or even stop words, and then for the continuous number to reduce the weight, such as the same "2016" can only be used as a similarity degree.
specific code, to stop the word after the hair, you need a stop vocabulary + scanning data structure algorithm, to achieve near-index efficiency. There are some words, word segmentation will have the attributes of speech to help stop the word, but the idea and this is not the same. The following is the conversion of the string, converted to string "", and because the punctuation is removed, the successive numbers in one, reducing the computational amount, faster than the simple maximum common substring calculation is faster 1/3.
public static string[] ConvertDigit (String str) {//regular punctuation string str = s
Tr.replaceall ("[\\pP]", "");
Continuous Digital Unity arraylist<string> find = new arraylist<string> ();
StringBuffer sb = new StringBuffer ();
for (int i = 0; i < str.length (); i++) {if (Character.isdigit (Str.charat (i)))
{Sb.append (Str.charat (i)); } else {if (sb.length () > 0) {find.ad
D (sb.tostring ());
Sb.setlength (0);
} find.add (Str.charat (i) + "");
} if (I==str.length () -1&&sb.length () >0) Find.add (sb.tostring ());
} return Find.toarray (new string[0]); }
The
is then the two string "" that was converted with the above method to calculate the maximum common substring
Maximum common substring, statistical matrix row and column common elements, dynamic programming find 1 longest diagonal length, continuous digital weight 1 public static int Getsimilarlengthimprove (string[] s, string[] t)
{int same[][];//matrix int score[][];//matrix int n;//Length of S int m; Length of t int i; Iterates through S Int J; Iterates through T char s_i; ith character of S Char T_j; jth character of t int cost;
Cost n = s.length;
m = t.length;
if (n = = 0) {return m;
} if (M = = 0) {return n;
} same = new int[n][m];
Score = new Int[n][m];
for (i = 0, i < n; i++) {for (j = 0; J < m; J + +) {
if (S[i].equals (T[j])) {same[i][j] = 1;
} }} for (i = 0; i < n; i++) {for (j = 0; J < m; J + +) {if (i = = 0 | | j = 0) {Score[i][j] = s
AME[I][J]; } else {int max = Math.max (score[i-1][j-1] + same[i][j], Math.max (score[i
][j-1], score[i-1][j]);
SCORE[I][J] = max;
}}} return score[n-1][m-1]; }
Of course, when you calculate the editing distance, you can also pre-process the preceding.