开发者

PHP Levenshtein Percentages

Can you explain why I need to use both the input string and 开发者_开发知识库the matching string when determining the levenshtein percentage?

$str1len = strlen($str1);        
$str2len = strlen($str2);    
if($str1len < $str2len){    
    $pct = ($str1len - $lev) / $str1len;    
} else {    
    $pct = ($str2len - $lev) / $str2len;    
}   
$pct = $pct * 100;      


Because it's a percentage. You need to compare one number against another.

A levenshtein distance is the number of single character changes between two strings needed to change the first string into the second string. The percentage is how many of the original characters got changed. e.g. a lev. distance of 2 on a 10 character word (20%) is a smaller percentage than a lev. distance of 2 on a 2 character word (100%), even though both lev. distances are the same.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜