String similarity algorithm, implemented by as3, used to determine chat ads

Source: Internet
Author: User
  1. /*** 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.