rechangement de format du dictionnaire

This commit is contained in:
2025-12-03 17:26:36 +01:00
parent 974e2c203c
commit 563ba7ed0a
5 changed files with 4041 additions and 2852 deletions

View File

@@ -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;
}
}
}

2839
dico.csv

File diff suppressed because it is too large Load Diff

View File

@@ -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);
}

4009
dico.tsv Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -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>