-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgetRimes.php
More file actions
57 lines (45 loc) · 1.81 KB
/
getRimes.php
File metadata and controls
57 lines (45 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
include('dbinfo.php');
if (isset($_POST['word'])) {
$word = $_POST['word'];
}else{
exit;
}
try {
$bdd = new PDO('mysql:host=' . $dbhost . ';dbname=' . $dbname, $dblogin, $dbpassword, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));
$bdd->exec("SET CHARACTER SET utf8");
} catch (PDOException $e) {
echo 'Echec de la connexion : ' . $e->getMessage();
exit;
}
$response = $bdd->query("SELECT * FROM words WHERE word = '".$word."' ORDER BY freq DESC");
$words = $response->fetchAll();
$response->closeCursor();
if(count($words) == 0){
echo json_encode(array("rimes" => array()));
exit;
}
$wordProp = $words[0];
function getWord($rime)
{
return($rime['word']);
}
$lastChar = substr($word, -1);
$checkWordEnding = '';
$origines = explode(',', $wordProp['orig']);
$origineQuery = '';
foreach ($origines as $key => $origine) {
$parts = explode('|', $origine);
if($key != 0)
$origineQuery .= ' OR ';
$origineQuery .= "(orig LIKE BINARY '%". $parts[0] ."%')";
if($parts[0] == "VER" || ($parts[0] == "NOM" && ($lastChar == "s" || $lastChar == "x")))
$checkWordEnding = " AND (word_end = '" . $wordProp['word_end'] . "')";
}
// Uncomment end of query with RAND() and LIMIT to improve Panoryma example with more diverse rimes and better performance
$response = $bdd->query("SELECT * FROM words WHERE (phon_end = '" . $wordProp['phon_end'] . "') ". $checkWordEnding ." AND (".$origineQuery.") AND ((max_nsyl >= '" . $wordProp['min_nsyl'] . "') AND (min_nsyl <= '" . $wordProp['max_nsyl'] . "' OR (elidable AND min_nsyl - 1 <= '" . $wordProp['max_nsyl'] . "' AND '" . $wordProp['elidable'] . "'))) /*ORDER BY RAND() LIMIT 1000*/");
$result = $response->fetchAll();
$response->closeCursor();
$result = array_map("getWord", $result);
echo json_encode(array("rimes" => $result, "isFem" => $wordProp['feminine']));
?>