PHP 编辑百分比
您能解释一下为什么我在确定编辑百分比时需要同时使用输入字符串和匹配字符串吗?
$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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为它是一个百分比。您需要将一个数字与另一个数字进行比较。
编辑距离是将第一个字符串更改为第二个字符串所需的两个字符串之间的单个字符更改的数量。百分比是原始字符被更改的数量。例如列弗。 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.