Move the word comparison function to common file

This commit is contained in:
Gregory Trolliet 2020-11-25 19:52:13 +01:00
parent ea95c63e18
commit 98b3498de2
2 changed files with 18 additions and 15 deletions

16
common.php Normal file
View 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
View File

@ -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;
}
}