假设我有两句话:
“快速的棕色狐狸跳过懒狗”
“快速的棕色兔子跳过懒猫”
是否有算法来检测这两个句子的相似比?例如:
function similarity_ratio($text1, $text2) {
code code code
return $similarity_ratio;
}
$text1 = "The quick brown fox jumps over the lazy dog";
$text2 = "The quick brown cat jumps over the lazy chicken";
echo similarity_ratio($text1, $text2);
// output 88%
答案 0 :(得分:5)
function similarity_ratio($text1, $text2) {
similar_text($text1, $text2, $similarity_ratio);
return $similarity_ratio;
}
$text1 = "The quick brown fox jumps over the lazy dog";
$text2 = "The quick brown fox jumps over the lazy cat";
echo similarity_ratio($text1, $text2);
Output: 93.023255813953
答案 1 :(得分:4)
答案 2 :(得分:2)