petites modifs
This commit is contained in:
parent
ca39709fbd
commit
457d18436e
@ -2,6 +2,9 @@
|
|||||||
include_once "dico.php";
|
include_once "dico.php";
|
||||||
|
|
||||||
|
|
||||||
|
const ECART_TYPE_ALEA = 5;
|
||||||
|
|
||||||
|
|
||||||
$randmax = mt_getrandmax() + 1;
|
$randmax = mt_getrandmax() + 1;
|
||||||
function gaussienne($moyenne = 0, $ecartType = 1.0): float {
|
function gaussienne($moyenne = 0, $ecartType = 1.0): float {
|
||||||
global $randmax;
|
global $randmax;
|
||||||
@ -82,7 +85,7 @@ class Grille implements ArrayAccess
|
|||||||
$lettres_colonne->branches
|
$lettres_colonne->branches
|
||||||
);
|
);
|
||||||
foreach ($lettres_communes as $lettre => $_) {
|
foreach ($lettres_communes as $lettre => $_) {
|
||||||
$lettres_communes[$lettre] = count($lettres_ligne->branches[$lettre]) * count($lettres_colonne->branches[$lettre]) * gaussienne(1, 5);
|
$lettres_communes[$lettre] = count($lettres_ligne->branches[$lettre]) * count($lettres_colonne->branches[$lettre]) * gaussienne(1, ECART_TYPE_ALEA);
|
||||||
}
|
}
|
||||||
uksort($lettres_communes, function($a, $b) use ($lettres_communes) {
|
uksort($lettres_communes, function($a, $b) use ($lettres_communes) {
|
||||||
return $lettres_communes[$b] <=> $lettres_communes[$a];
|
return $lettres_communes[$b] <=> $lettres_communes[$a];
|
||||||
|
15
dico.php
15
dico.php
@ -6,14 +6,13 @@ const MIN_PREMIER_MOT = 1;
|
|||||||
const MIN_MOTS_SUIVANTS = 1;
|
const MIN_MOTS_SUIVANTS = 1;
|
||||||
|
|
||||||
|
|
||||||
$nb_mots = 0;
|
|
||||||
|
|
||||||
function dico($longueur_max) {
|
function dico($longueur_max) {
|
||||||
global $nb_mots;
|
|
||||||
|
|
||||||
$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) {
|
||||||
@ -40,16 +39,16 @@ function dico($longueur_max) {
|
|||||||
$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)";
|
$definition .= " ($nb_mots mots)";
|
||||||
}
|
}
|
||||||
|
|
||||||
$longueur = strlen($mot);
|
$longueur = strlen($mot);
|
||||||
if (!isset($dico[$longueur])) $dico[$longueur] = new Trie();
|
|
||||||
if (!isset($dico[$longueur][$mot])) $dico[$longueur][$mot] = [];
|
if (!isset($dico[$longueur][$mot])) $dico[$longueur][$mot] = [];
|
||||||
if (strlen($definition)) $dico[$longueur][$mot][] = $definition;
|
if (strlen($definition)) $dico[$longueur][$mot][] = $definition;
|
||||||
}
|
}
|
||||||
@ -60,8 +59,6 @@ function dico($longueur_max) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function mots_espaces($longueur_max) {
|
function mots_espaces($longueur_max) {
|
||||||
global $nb_mots;
|
|
||||||
|
|
||||||
$dico = dico($longueur_max);
|
$dico = dico($longueur_max);
|
||||||
for ($longueur = 1; $longueur <= $longueur_max; $longueur++) {
|
for ($longueur = 1; $longueur <= $longueur_max; $longueur++) {
|
||||||
for ($position_espace = MIN_PREMIER_MOT; $position_espace + MIN_MOTS_SUIVANTS < $longueur; $position_espace++) {
|
for ($position_espace = MIN_PREMIER_MOT; $position_espace + MIN_MOTS_SUIVANTS < $longueur; $position_espace++) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user