From 98b3498de2173639a60b904ef2d5ef81b7fb4276 Mon Sep 17 00:00:00 2001 From: Gregory Trolliet Date: Wed, 25 Nov 2020 19:52:13 +0100 Subject: [PATCH] Move the word comparison function to common file --- common.php | 16 ++++++++++++++++ db.php | 17 ++--------------- 2 files changed, 18 insertions(+), 15 deletions(-) create mode 100644 common.php diff --git a/common.php b/common.php new file mode 100644 index 0000000..177e45f --- /dev/null +++ b/common.php @@ -0,0 +1,16 @@ += 90 || $meta_perc >= 90 || $sndx_perc >= 90) { + return true; + } + if ($word_perc >= 80 && $meta_perc >= 80 && $sndx_perc >= 80) { + return true; + } + return false; +} diff --git a/db.php b/db.php index d09a175..fdfe2f9 100644 --- a/db.php +++ b/db.php @@ -1,5 +1,6 @@ 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; - } }