PHP 编辑百分比

发布于 2024-10-17 06:16:01 字数 300 浏览 14 评论 0原文

您能解释一下为什么我在确定编辑百分比时需要同时使用输入字符串和匹配字符串吗?

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

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;      

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

下壹個目標 2024-10-24 06:16:01

因为它是一个百分比。您需要将一个数字与另一个数字进行比较。

编辑距离是将第一个字符串更改为第二个字符串所需的两个字符串之间的单个字符更改的数量。百分比是原始字符被更改的数量。例如列弗。 10 个字符的单词上 2 的距离 (20%) 比 lev 的百分比要小。 2 个字符单词上的距离为 2 (100%),即使两者都是 lev。距离是相同的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文