【问题标题】:Deciding which string to go to first / second parameter in similar_text决定在similar_text中将哪个字符串转到第一个/第二个参数
【发布时间】:2018-06-25 05:34:34
【问题描述】:

我有一个字符串列表。对于每个字符串,我需要从另一个字符串列表中找到最相似的字符串。目前,我总是将第一个列表中的字符串作为第一个参数传递,并将第二个列表中的字符串作为similar_text 中的第二个参数传递,如下所示:

foreach($list_a as $str_a){

    $most_similar_str = null;
    $most_similar_str_pct = 0;

    foreach($list_b as $str_b){

        //swapping parameter order may yield a different result
        similar_text($str_a, $str_b, $pct);

        if($pct > $most_similar_str_pct){
            $most_similar_str = $str_b;
            $most_similar_str_pct = pct;
        }
    }

    echo "The most similar text for {$str_a} is {$most_similar_str}\n";

}

交换similar_text 中的第一个和第二个参数可能会产生不同的结果。为了产生更准确的结果,我不确定哪个字符串实际上应该转到第一个/第二个参数。

我也在考虑是否应该先从$str_a$str_b中找到较长的字符串,并始终将其作为第一个/第二个参数。

【问题讨论】:

    标签: php similarity


    【解决方案1】:

    我已经对相似文本进行了很多关于交换的实验,并且我已经看到当第一个参数比第二个参数更长时获得最正确的结果。在这种情况下,strlen 将是你的朋友来决定第一个参数

    【讨论】:

      猜你喜欢
      • 2015-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-29
      • 2020-02-14
      • 2013-05-21
      相关资源
      最近更新 更多