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) {
|
||||
$definitions = $this->dico[strlen($mot)][$mot];
|
||||
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) {
|
||||
$definitions = $this->dico[strlen($mot)][$mot];
|
||||
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 DEFINITION = 0;
|
||||
const AUTEUR = 1;
|
||||
const NB_MOTS = 2;
|
||||
|
||||
|
||||
function dico($longueur_max) {
|
||||
@@ -13,7 +16,7 @@ function dico($longueur_max) {
|
||||
for ($longueur = 0; $longueur <= $longueur_max; $longueur++) {
|
||||
$dico[] = new Trie();
|
||||
}
|
||||
if (($lecteur = fopen("dico.csv", "r")) !== FALSE) {
|
||||
if (($lecteur = fopen("dico.tsv", "r")) !== FALSE) {
|
||||
$entete = fgetcsv($lecteur, 0, "\t");
|
||||
while (($ligne = fgetcsv($lecteur, 0, "\t")) !== FALSE) {
|
||||
if (
|
||||
@@ -23,7 +26,7 @@ function dico($longueur_max) {
|
||||
) continue;
|
||||
|
||||
$mot = $ligne[0];
|
||||
$definitions = array_slice($ligne, 1);
|
||||
$definition = array_slice($ligne, 1);
|
||||
|
||||
$mot = str_replace("-", CASE_NOIRE, $mot);
|
||||
$mot = $transliterator->transliterate($mot);
|
||||
@@ -31,12 +34,16 @@ function dico($longueur_max) {
|
||||
$mots = explode(CASE_NOIRE, $mot);
|
||||
$nb_mots = count($mots);
|
||||
$mot = implode("", $mots);
|
||||
foreach($definitions as $i => $definition) {
|
||||
$definitions[$i] = "$definition#$nb_mots";
|
||||
}
|
||||
} else {
|
||||
$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);
|
||||
}
|
||||
|
||||
14
index.php
14
index.php
@@ -1,5 +1,9 @@
|
||||
<?php
|
||||
|
||||
ini_set('display_errors', '1');
|
||||
ini_set('display_startup_errors', '1');
|
||||
error_reporting(E_ALL);
|
||||
|
||||
include_once "Grille.php";
|
||||
|
||||
|
||||
@@ -44,19 +48,19 @@ if (!isset($_GET["grille"]) || $_GET["grille"] == "") {
|
||||
}
|
||||
|
||||
function formatter_definition($definition) {
|
||||
if (strpos($definition, "#") !== false) {
|
||||
[$definition, $nb_mots] = explode("#", $definition);
|
||||
if (isset($definition["nb_mots"]) && $definition["nb_mots"] > 1){
|
||||
$nb_mots = $definition["nb_mots"];
|
||||
$nb_mots = " <small>($nb_mots mots)</small>";
|
||||
} else {
|
||||
$nb_mots = "";
|
||||
}
|
||||
if (strpos($definition, "@") !== false) {
|
||||
[$definition, $auteur] = explode("@", $definition);
|
||||
if (array_key_exists(AUTEUR, $definition)) {
|
||||
$auteur = $definition[AUTEUR];
|
||||
$auteur = " <small><em>$auteur</em></small>";
|
||||
} else {
|
||||
$auteur = "";
|
||||
}
|
||||
return $definition . $nb_mots . $auteur;
|
||||
return $definition[DEFINITION] . $nb_mots . $auteur;
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE HTML>
|
||||
|
||||
Reference in New Issue
Block a user