Add words similarity test
Should put the almost same words in the same counter
This commit is contained in:
parent
ce1f76a96c
commit
39d4be9eb3
1 changed files with 22 additions and 0 deletions
22
db.php
22
db.php
|
@ -85,6 +85,19 @@ class DataBase
|
|||
} else {
|
||||
return false;
|
||||
}
|
||||
$stmt = $this->db->prepare("
|
||||
SELECT *
|
||||
FROM words
|
||||
WHERE cloud_id = :cid;
|
||||
");
|
||||
$stmt->bindValue(':cid', $cloudId, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
while($data = $stmt->fetch()) {
|
||||
if ($this->areWordsSimilar($data['word'], $word)) {
|
||||
$word = $data['word'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
$stmt = $this->db->prepare("
|
||||
SELECT *
|
||||
FROM words
|
||||
|
@ -275,4 +288,13 @@ class DataBase
|
|||
return false;
|
||||
}
|
||||
|
||||
function areWordsSimilar(string $word1, string $word2)
|
||||
{
|
||||
$sim = similar_text($word1, $word2, $perc);
|
||||
$sim_meta = similar_text(metaphone($word1), metaphone($word2), $perc_meta);
|
||||
if ($perc >= 80 && $perc_meta >= 80) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue