rechangement de format du dictionnaire
This commit is contained in:
12
Grille.php
12
Grille.php
@@ -83,7 +83,11 @@ class Grille implements ArrayAccess
|
|||||||
foreach($mots as $mot) {
|
foreach($mots as $mot) {
|
||||||
$definitions = $this->dico[strlen($mot)][$mot];
|
$definitions = $this->dico[strlen($mot)][$mot];
|
||||||
if (count($definitions)) {
|
if (count($definitions)) {
|
||||||
$this->definitions["horizontales"][$y][] = $definitions[mt_rand(0, count($definitions) - 1)];
|
$definition = $definitions[mt_rand(0, count($definitions) - 1)];
|
||||||
|
if (isset($definitions["nb_mots"])) {
|
||||||
|
$definition["nb_mots"] = $definitions["nb_mots"];
|
||||||
|
}
|
||||||
|
$this->definitions["horizontales"][$y][] = $definition;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,7 +96,11 @@ class Grille implements ArrayAccess
|
|||||||
foreach($mots as $mot) {
|
foreach($mots as $mot) {
|
||||||
$definitions = $this->dico[strlen($mot)][$mot];
|
$definitions = $this->dico[strlen($mot)][$mot];
|
||||||
if (count($definitions)) {
|
if (count($definitions)) {
|
||||||
$this->definitions["verticales"][$x][] = $definitions[mt_rand(0, count($definitions) - 1)];
|
$definition = $definitions[mt_rand(0, count($definitions) - 1)];
|
||||||
|
if (isset($definitions["nb_mots"])) {
|
||||||
|
$definition["nb_mots"] = $definitions["nb_mots"];
|
||||||
|
}
|
||||||
|
$this->definitions["verticales"][$x][] = $definition;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
19
dico.php
19
dico.php
@@ -4,6 +4,9 @@ include_once "Trie.php";
|
|||||||
|
|
||||||
|
|
||||||
const CASE_NOIRE = " ";
|
const CASE_NOIRE = " ";
|
||||||
|
const DEFINITION = 0;
|
||||||
|
const AUTEUR = 1;
|
||||||
|
const NB_MOTS = 2;
|
||||||
|
|
||||||
|
|
||||||
function dico($longueur_max) {
|
function dico($longueur_max) {
|
||||||
@@ -13,7 +16,7 @@ function dico($longueur_max) {
|
|||||||
for ($longueur = 0; $longueur <= $longueur_max; $longueur++) {
|
for ($longueur = 0; $longueur <= $longueur_max; $longueur++) {
|
||||||
$dico[] = new Trie();
|
$dico[] = new Trie();
|
||||||
}
|
}
|
||||||
if (($lecteur = fopen("dico.csv", "r")) !== FALSE) {
|
if (($lecteur = fopen("dico.tsv", "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) {
|
||||||
if (
|
if (
|
||||||
@@ -23,7 +26,7 @@ function dico($longueur_max) {
|
|||||||
) continue;
|
) continue;
|
||||||
|
|
||||||
$mot = $ligne[0];
|
$mot = $ligne[0];
|
||||||
$definitions = array_slice($ligne, 1);
|
$definition = array_slice($ligne, 1);
|
||||||
|
|
||||||
$mot = str_replace("-", CASE_NOIRE, $mot);
|
$mot = str_replace("-", CASE_NOIRE, $mot);
|
||||||
$mot = $transliterator->transliterate($mot);
|
$mot = $transliterator->transliterate($mot);
|
||||||
@@ -31,12 +34,16 @@ function dico($longueur_max) {
|
|||||||
$mots = explode(CASE_NOIRE, $mot);
|
$mots = explode(CASE_NOIRE, $mot);
|
||||||
$nb_mots = count($mots);
|
$nb_mots = count($mots);
|
||||||
$mot = implode("", $mots);
|
$mot = implode("", $mots);
|
||||||
foreach($definitions as $i => $definition) {
|
} else {
|
||||||
$definitions[$i] = "$definition#$nb_mots";
|
$nb_mots = 1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$dico[strlen($mot)][$mot] = $definitions;
|
if (array_key_exists($mot, $dico)) {
|
||||||
|
$dico[strlen($mot)][$mot][] = $definition;
|
||||||
|
} else {
|
||||||
|
$dico[strlen($mot)][$mot] = [$definition];
|
||||||
|
if ($nb_mots > 1) $dico[strlen($mot)][$mot]["nb_mots"] = $nb_mots;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fclose($lecteur);
|
fclose($lecteur);
|
||||||
}
|
}
|
||||||
|
|||||||
14
index.php
14
index.php
@@ -1,5 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
ini_set('display_errors', '1');
|
||||||
|
ini_set('display_startup_errors', '1');
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
include_once "Grille.php";
|
include_once "Grille.php";
|
||||||
|
|
||||||
|
|
||||||
@@ -44,19 +48,19 @@ if (!isset($_GET["grille"]) || $_GET["grille"] == "") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function formatter_definition($definition) {
|
function formatter_definition($definition) {
|
||||||
if (strpos($definition, "#") !== false) {
|
if (isset($definition["nb_mots"]) && $definition["nb_mots"] > 1){
|
||||||
[$definition, $nb_mots] = explode("#", $definition);
|
$nb_mots = $definition["nb_mots"];
|
||||||
$nb_mots = " <small>($nb_mots mots)</small>";
|
$nb_mots = " <small>($nb_mots mots)</small>";
|
||||||
} else {
|
} else {
|
||||||
$nb_mots = "";
|
$nb_mots = "";
|
||||||
}
|
}
|
||||||
if (strpos($definition, "@") !== false) {
|
if (array_key_exists(AUTEUR, $definition)) {
|
||||||
[$definition, $auteur] = explode("@", $definition);
|
$auteur = $definition[AUTEUR];
|
||||||
$auteur = " <small><em>$auteur</em></small>";
|
$auteur = " <small><em>$auteur</em></small>";
|
||||||
} else {
|
} else {
|
||||||
$auteur = "";
|
$auteur = "";
|
||||||
}
|
}
|
||||||
return $definition . $nb_mots . $auteur;
|
return $definition[DEFINITION] . $nb_mots . $auteur;
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE HTML>
|
<!DOCTYPE HTML>
|
||||||
|
|||||||
Reference in New Issue
Block a user