From ca39709fbd7a35f9629e668c75781c87c78a9cbd Mon Sep 17 00:00:00 2001 From: adrien Date: Wed, 7 May 2025 23:54:00 +0200 Subject: [PATCH] nombre de mots --- dico.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/dico.php b/dico.php index 113f14e..a5bf012 100644 --- a/dico.php +++ b/dico.php @@ -6,10 +6,16 @@ const MIN_PREMIER_MOT = 1; const MIN_MOTS_SUIVANTS = 1; +$nb_mots = 0; + function dico($longueur_max) { + global $nb_mots; + + $transliterator = Transliterator::createFromRules(':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: Upper(); :: NFC;', Transliterator::FORWARD); + $dico = [[""]]; if (($lecteur = fopen("dico.csv", "r")) !== FALSE) { - $header = fgetcsv($lecteur, 0, "\t"); + $entete = fgetcsv($lecteur, 0, "\t"); while (($ligne = fgetcsv($lecteur, 0, "\t")) !== FALSE) { if ( $ligne[0] == NULL @@ -31,7 +37,17 @@ function dico($longueur_max) { break; } - $mot = strtoupper($mot); + $mot = $ligne[0]; + $definitions = array_slice($ligne, 1); + + $mot = $transliterator->transliterate($mot); + if (strpos($mot, " ") !== false) { + $mots = explode(" ", $mot); + $nb_mot = count($mots); + $mot = implode("", $mots); + $definition .= " ($nb_mot mots)"; + } + $longueur = strlen($mot); if (!isset($dico[$longueur])) $dico[$longueur] = new Trie(); if (!isset($dico[$longueur][$mot])) $dico[$longueur][$mot] = []; @@ -44,9 +60,9 @@ function dico($longueur_max) { } function mots_espaces($longueur_max) { - $dico = dico($longueur_max); + global $nb_mots; - $_tries = [[]]; + $dico = dico($longueur_max); for ($longueur = 1; $longueur <= $longueur_max; $longueur++) { for ($position_espace = MIN_PREMIER_MOT; $position_espace + MIN_MOTS_SUIVANTS < $longueur; $position_espace++) { $mots_suivants = $dico[$longueur - $position_espace - 1];