これが私の機能で、非常に興味深いものです。
文字列のおおよその類似性をチェックしています。
そのために私が使っている基準があります。
- 言葉の順番が大事
- 単語の類似度は 85% です。
例:
$string1 = "How much will it cost to me" (string in vocabulary)
$string2 = "How much does costs it " //("costs" instead "cost" -is a mistake) (user input);
アルゴリズム: 1) 単語の類似性をチェックし、「適切な」単語できれいな文字列を作成します (語彙に現れる順序で)。OUTPUT: "how how much it cost" 2) ユーザー入力に表示されるように、"適切な単語" でクリーンな文字列を作成します。OUTPUT: "how how much it it" 3) 2 つの出力を比較し、同じでない場合は no を返し、同じ場合は yes を返します。
error_reporting(E_ALL);
ini_set('display_errors', true);
$string1="сколько это стоит ваще" ;
$string2= "сколько будет стоить это будет мне";
if(compareStrings($string1, $string2)) {
echo "yes";
} else {
echo 'no';
}
//echo compareStrings($string1, $string2);
function compareStrings($s1, $s2) {
if (strlen($s1)==0 || strlen($s2)==0) {
return 0;
}
while (strpos($s1, " ")!==false) {
$s1 = str_replace(" ", " ", $s1);
}
while (strpos($s2, " ")!==false) {
$s2 = str_replace(" ", " ", $s2);
}
$ar1 = explode(" ",$s1);
$ar2 = explode(" ",$s2);
// $array1 = array_flip($ar1);
// $array2 = array_flip($ar2);
$l1 = count($ar1);
$l2 = count($ar2);
$meaning="";
$rightorder="";
$compare=0;
for ($i=0;$i<$l1;$i++) {
for ($j=0;$j<$l2;$j++) {
$compare = (similar_text($ar1[$i],$ar2[$j],$percent)) ;
// echo $compare;
if ($percent>=85) {
$meaning=$meaning." ".$ar1[$i];
$rightorder=$rightorder." ".$ar1[$j];
$compare=0;
}
}
}
//print_r($rightorder);
if ($rightorder==$meaning) {
return true;
} else {
return false;
}
}
あなたの意見と改善方法の提案を聞きたいです