grand dico
This commit is contained in:
parent
ca39709fbd
commit
13fcdf05fb
28
dico.php
28
dico.php
@ -14,6 +14,9 @@ function dico($longueur_max) {
|
|||||||
$transliterator = Transliterator::createFromRules(':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: Upper(); :: NFC;', Transliterator::FORWARD);
|
$transliterator = Transliterator::createFromRules(':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: Upper(); :: NFC;', Transliterator::FORWARD);
|
||||||
|
|
||||||
$dico = [[""]];
|
$dico = [[""]];
|
||||||
|
for ($longueur = 0; $longueur <= $longueur_max; $longueur++) {
|
||||||
|
$dico[] = new Trie();
|
||||||
|
}
|
||||||
if (($lecteur = fopen("dico.csv", "r")) !== FALSE) {
|
if (($lecteur = fopen("dico.csv", "r")) !== FALSE) {
|
||||||
$entete = fgetcsv($lecteur, 0, "\t");
|
$entete = fgetcsv($lecteur, 0, "\t");
|
||||||
while (($ligne = fgetcsv($lecteur, 0, "\t")) !== FALSE) {
|
while (($ligne = fgetcsv($lecteur, 0, "\t")) !== FALSE) {
|
||||||
@ -23,35 +26,22 @@ function dico($longueur_max) {
|
|||||||
|| strlen($ligne[0]) > $longueur_max
|
|| strlen($ligne[0]) > $longueur_max
|
||||||
) continue;
|
) continue;
|
||||||
|
|
||||||
switch(count($ligne)) {
|
|
||||||
case 1:
|
|
||||||
[$mot] = $ligne;
|
|
||||||
$definition = "";
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
[$mot, $definition] = $ligne;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
[$mot, $definition, $auteur] = $ligne;
|
|
||||||
$definition .= " <small><em>$auteur</em></small>";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$mot = $ligne[0];
|
$mot = $ligne[0];
|
||||||
$definitions = array_slice($ligne, 1);
|
$definitions = array_slice($ligne, 1);
|
||||||
|
$mot = str_replace("-", " ", $mot);
|
||||||
|
|
||||||
$mot = $transliterator->transliterate($mot);
|
$mot = $transliterator->transliterate($mot);
|
||||||
if (strpos($mot, " ") !== false) {
|
if (strpos($mot, " ") !== false) {
|
||||||
$mots = explode(" ", $mot);
|
$mots = explode(" ", $mot);
|
||||||
$nb_mot = count($mots);
|
$nb_mots = count($mots);
|
||||||
$mot = implode("", $mots);
|
$mot = implode("", $mots);
|
||||||
$definition .= " ($nb_mot mots)";
|
foreach($definitions as $i => $definition) {
|
||||||
|
$definitions[$i] .= " ($nb_mots mots)";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$longueur = strlen($mot);
|
$longueur = strlen($mot);
|
||||||
if (!isset($dico[$longueur])) $dico[$longueur] = new Trie();
|
$dico[$longueur][$mot] = $definitions;
|
||||||
if (!isset($dico[$longueur][$mot])) $dico[$longueur][$mot] = [];
|
|
||||||
if (strlen($definition)) $dico[$longueur][$mot][] = $definition;
|
|
||||||
}
|
}
|
||||||
fclose($lecteur);
|
fclose($lecteur);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user