/*** After several steps, the calculated source can be converted to the target value * @ Param source * @ Param target * @ return **/public static function editdistance (Source: string, target: string): int {var slen: Int = source. length; var tlen: Int = target. length; var D: array = []; for (var I: Int = 0; I <= slen; I ++) {d [I] = []; d [I] [0] = I; if (I = 0) {for (VAR J: Int = 1; j <= tlen; j ++) {d [0] [J] = J ;}} else {for (var j: Int = 1; j <= tlen; j ++) {d [I] [J] = 0 ;}} (Var I: Int = 1; I <= slen; I ++) {for (VAR J: Int = 1; j <= tlen; j ++) {If (source. charcodeat (I-1) = target. charcodeat (J-1) {d [I] [J] = d [I-1] [J-1];} else {var insert: Int = d [I] [J-1] + 1; vaR DEL: Int = d [I-1] [J] + 1; var update: Int = d [I-1] [J-1] + 1; d [I] [J] = math. min (insert, del)> math. min (Del, update )? Math. min (Del, update): math. min (insert, del) ;}}return d [slen] [tlen];} /*** similarity calculation ** @ Param source * @ Param target * @ return **/public static function getsimilarityrate (Source: String, target: string ): number {return 1-editdistance (source, target)/math. max (source. length, target. length );}
For more information about the code, see refer to examples.
String similarity algorithm, implemented by as3, used to determine chat ads