レーベンシュタイン距離は、2 つのシーケンス間の差を測定するための文字列メトリックです。非公式には、2 つの単語間のレーベンシュタイン距離は、1 つの単語を別の単語に変更するために必要な 1 文字の編集 (挿入、削除、置換) の最小数です。
ここに簡単な分析があります
$input = 'htc corporation';
// array of words to check against
$words = array(
'htc',
'Sprint Nextel',
'Sprint',
'banana',
'orange',
'radish',
'carrot',
'pea',
'bean'
);
foreach ( $words as $word ) {
// Check for Intercept
$ic = array_intersect(str_split($input), str_split($word));
printf("%s \t l= %s , s = %s , c = %d \n",$word ,
levenshtein($input, $word),
similar_text($input, $word),
count($ic));
}
出力
htc l= 12 , s = 3 , c = 5
Sprint Nextel l= 14 , s = 3 , c = 8
Sprint l= 12 , s = 1 , c = 7
banana l= 14 , s = 2 , c = 2
orange l= 12 , s = 4 , c = 7
radish l= 12 , s = 3 , c = 5
carrot l= 11 , s = 1 , c = 10
pea l= 13 , s = 2 , c = 2
bean l= 13 , s = 2 , c = 2
htc には の距離があることは明らかですが、htc が12
必要な場合は11
、Levenshtein
だけでは十分ではありません..正確な単語を比較して、優先順位を設定する必要があります