Move the word comparison function to common file
This commit is contained in:
parent
ea95c63e18
commit
98b3498de2
2 changed files with 18 additions and 15 deletions
16
common.php
Normal file
16
common.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
|
||||
function areWordsSimilar(string $word1, string $word2)
|
||||
{
|
||||
$word_sim = similar_text($word1, $word2, $word_perc);
|
||||
$meta_sim = similar_text(metaphone($word1), metaphone($word2), $meta_perc);
|
||||
$sndx_sim = similar_text(soundex_fr($word1), soundex_fr($word2), $sndx_perc);
|
||||
if ($word_perc >= 90 || $meta_perc >= 90 || $sndx_perc >= 90) {
|
||||
return true;
|
||||
}
|
||||
if ($word_perc >= 80 && $meta_perc >= 80 && $sndx_perc >= 80) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
17
db.php
17
db.php
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
require_once 'soundex_fr.php';
|
||||
require_once 'common.php';
|
||||
|
||||
class DataBase
|
||||
{
|
||||
|
@ -91,7 +92,7 @@ class DataBase
|
|||
$stmt->bindValue(':cid', $cloudId, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
while($data = $stmt->fetch()) {
|
||||
if ($this->areWordsSimilar($data['word'], $word)) {
|
||||
if (areWordsSimilar($data['word'], $word)) {
|
||||
$word = $data['word'];
|
||||
$wordId = $data['id_word'];
|
||||
break;
|
||||
|
@ -276,18 +277,4 @@ class DataBase
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function areWordsSimilar(string $word1, string $word2)
|
||||
{
|
||||
$word_sim = similar_text($word1, $word2, $word_perc);
|
||||
$meta_sim = similar_text(metaphone($word1), metaphone($word2), $meta_perc);
|
||||
$sndx_sim = similar_text(soundex_fr($word1), soundex_fr($word2), $sndx_perc);
|
||||
if ($word_perc >= 90 || $meta_perc >= 90 || $sndx_perc >= 90) {
|
||||
return true;
|
||||
}
|
||||
if ($word_perc >= 80 && $meta_perc >= 80 && $sndx_perc >= 80) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue