469 |
jpm |
1 |
<?php
|
|
|
2 |
class Index {
|
|
|
3 |
|
|
|
4 |
const DOSSIER_V0 = '../../../donnees/coste/0.00/';
|
|
|
5 |
const DOSSIER_V2 = '../../../donnees/coste/2.00/';
|
|
|
6 |
|
|
|
7 |
private $conteneur = null;
|
|
|
8 |
private $outils = null;
|
|
|
9 |
private $messages = null;
|
487 |
jpm |
10 |
private $generateur = null;
|
469 |
jpm |
11 |
private $dossierBase = '';
|
|
|
12 |
private $spIndex = array();
|
|
|
13 |
private $supraSpIndex = array();
|
487 |
jpm |
14 |
private $imgIndex = array();
|
469 |
jpm |
15 |
private $indexFinal = array();
|
|
|
16 |
private $tableauParDefaut = array();
|
471 |
jpm |
17 |
private $nbreTaxonInf = array();
|
469 |
jpm |
18 |
private $enteteFinal = array(
|
|
|
19 |
'num_nom',
|
|
|
20 |
'num_nom_retenu',
|
|
|
21 |
'num_tax_sup',
|
|
|
22 |
'rang',
|
|
|
23 |
'nom_sci',
|
487 |
jpm |
24 |
'nom_supra_generique',
|
|
|
25 |
'genre',
|
|
|
26 |
'epithete_infra_generique',
|
|
|
27 |
'epithete_sp',
|
|
|
28 |
'type_epithete',
|
|
|
29 |
'epithete_infra_sp',
|
|
|
30 |
'cultivar_groupe',
|
|
|
31 |
'cultivar',
|
|
|
32 |
'nom_commercial',
|
469 |
jpm |
33 |
'auteur',
|
|
|
34 |
'annee',
|
|
|
35 |
'biblio_origine',
|
487 |
jpm |
36 |
'notes',
|
|
|
37 |
'nom_addendum',
|
469 |
jpm |
38 |
'nom_francais',
|
|
|
39 |
'nom_coste',
|
|
|
40 |
'auteur_coste',
|
|
|
41 |
'biblio_coste',
|
|
|
42 |
'num_nom_coste',
|
|
|
43 |
'num_nom_retenu_coste',
|
|
|
44 |
'num_tax_sup_coste',
|
|
|
45 |
'synonymie_coste',
|
|
|
46 |
'tome',
|
|
|
47 |
'page',
|
471 |
jpm |
48 |
'nbre_taxons',
|
487 |
jpm |
49 |
'flore_bdtfx_nn',
|
|
|
50 |
'flore_bdtfx_nt',
|
471 |
jpm |
51 |
'image',
|
487 |
jpm |
52 |
'image_auteur',
|
471 |
jpm |
53 |
'page_wiki_dsc',
|
487 |
jpm |
54 |
'page_wiki_cle',
|
|
|
55 |
'nom_sci_html');
|
469 |
jpm |
56 |
|
|
|
57 |
public function __construct(Conteneur $conteneur) {
|
|
|
58 |
mb_internal_encoding('UTF-8');
|
|
|
59 |
setlocale(LC_ALL, 'fr_FR.UTF-8');
|
|
|
60 |
$this->conteneur = $conteneur;
|
|
|
61 |
$this->outils = $conteneur->getOutils();
|
|
|
62 |
$this->messages = $conteneur->getMessages();
|
487 |
jpm |
63 |
$this->generateur = $conteneur->getGenerateurNomSciHtml();
|
469 |
jpm |
64 |
$this->dossierBase = dirname(__FILE__).'/';
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
public function fusionnerIndex() {
|
|
|
68 |
$this->chargerIndexSp();
|
|
|
69 |
$this->chargerIndexSupraSp();
|
|
|
70 |
$this->initialiserTableauLigneIndexFinal();
|
|
|
71 |
$this->creerIndexFinal();
|
494 |
jpm |
72 |
$this->insererCorrections();
|
469 |
jpm |
73 |
$this->ajouterChampsDansIndexFinal();
|
487 |
jpm |
74 |
$this->ajouteurAuteurImage();
|
|
|
75 |
$this->decomposerNomSci();
|
|
|
76 |
$this->ajouteurNomSciHtml();
|
469 |
jpm |
77 |
$this->creerFichierCsvIndexFinal();
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
private function chargerIndexSp() {
|
|
|
81 |
$spIndexFichier = $this->dossierBase.self::DOSSIER_V0.'index_general_sp.tsv';
|
476 |
jpm |
82 |
$index = $this->outils->transformerTxtTsvEnTableau($spIndexFichier);
|
469 |
jpm |
83 |
$index = $this->reindexerParNumNomCoste($index);
|
|
|
84 |
foreach ($index as $numNomCoste => $infos) {
|
|
|
85 |
$numTaxSup = '';
|
|
|
86 |
if ($infos['num_nom_coste'] == $infos['num_nom_retenu_coste']) {
|
|
|
87 |
$numTaxSup = $infos['num_tax_sup_coste'];
|
|
|
88 |
} else {
|
|
|
89 |
$infosNomRetenu = $index[$infos['num_nom_retenu_coste']];
|
|
|
90 |
$numTaxSup = $infosNomRetenu['num_tax_sup_coste'];
|
|
|
91 |
}
|
|
|
92 |
$this->spIndex[$numTaxSup][] = $infos;
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
private function reindexerParNumNomCoste($index) {
|
|
|
97 |
$nouvelIndex = array();
|
|
|
98 |
foreach ($index as $infos) {
|
|
|
99 |
$nouvelIndex[$infos['num_nom_coste']] = $infos;
|
|
|
100 |
}
|
|
|
101 |
return $nouvelIndex;
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
private function chargerIndexSupraSp() {
|
|
|
105 |
$infraSpIndexFichier = $this->dossierBase.self::DOSSIER_V0.'index_general.tsv';
|
476 |
jpm |
106 |
$this->supraSpIndex = $this->outils->transformerTxtTsvEnTableau($infraSpIndexFichier);
|
469 |
jpm |
107 |
foreach ($this->supraSpIndex as $cle => $infos) {
|
|
|
108 |
$this->supraSpIndex[$cle]['num_nom_retenu_coste'] = $infos['num_nom_coste'];
|
|
|
109 |
}
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
private function initialiserTableauLigneIndexFinal() {
|
|
|
113 |
$this->tableauParDefaut = array();
|
|
|
114 |
foreach ($this->enteteFinal as $cle) {
|
|
|
115 |
$this->tableauParDefaut[$cle] = '';
|
|
|
116 |
}
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
private function creerIndexFinal() {
|
|
|
120 |
foreach ($this->supraSpIndex as $infos) {
|
|
|
121 |
$this->ajouterDansIndexFinal($infos);
|
|
|
122 |
if (preg_match('/^G[0-9]+$/', $infos['num_nom_coste'])) {
|
|
|
123 |
foreach ($this->spIndex[$infos['num_nom_coste']] as $infosSp) {
|
|
|
124 |
$this->ajouterDansIndexFinal($infosSp);
|
|
|
125 |
}
|
|
|
126 |
}
|
|
|
127 |
}
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
private function ajouterDansIndexFinal($infos) {
|
|
|
131 |
$infos = array_merge($this->tableauParDefaut, $infos);
|
471 |
jpm |
132 |
$infos['num_nom'] = (count($this->indexFinal) + 1);
|
469 |
jpm |
133 |
$this->indexFinal[$infos['num_nom_coste']] = $infos;
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
private function ajouterChampsDansIndexFinal() {
|
471 |
jpm |
137 |
$this->genererNbreTaxons();
|
469 |
jpm |
138 |
foreach ($this->indexFinal as $nnc => $infos) {
|
|
|
139 |
if ($infos['num_nom_coste'] == $infos['num_nom_retenu_coste']) {
|
|
|
140 |
$infos['num_nom_retenu'] = $infos['num_nom'];
|
|
|
141 |
if ($nnc != 'R') {
|
|
|
142 |
$nomSuperieur = $this->indexFinal[$infos['num_tax_sup_coste']];
|
|
|
143 |
$infos['num_tax_sup'] = $nomSuperieur['num_nom'];
|
|
|
144 |
}
|
471 |
jpm |
145 |
$nomRetenu = $infos;
|
469 |
jpm |
146 |
} else {
|
|
|
147 |
$nomRetenu = $this->indexFinal[$infos['num_nom_retenu_coste']];
|
494 |
jpm |
148 |
$infos['num_nom_retenu'] = $nomRetenu['num_nom'];
|
|
|
149 |
$infos['page'] = $nomRetenu['page'];
|
|
|
150 |
$infos['tome'] = $nomRetenu['tome'];
|
469 |
jpm |
151 |
}
|
471 |
jpm |
152 |
$infos['image'] = $this->obtenirNomFichierImg($nomRetenu);
|
|
|
153 |
$infos['nbre_taxons'] = $this->obtenirNbreTaxon($infos);
|
476 |
jpm |
154 |
$nomRetenu['nbre_taxons'] = $infos['nbre_taxons'];
|
471 |
jpm |
155 |
$infos['page_wiki_dsc'] = $this->genererPageWikiDsc($nomRetenu);
|
|
|
156 |
$infos['page_wiki_cle'] = $this->genererPageWikiCle($nomRetenu);
|
|
|
157 |
|
469 |
jpm |
158 |
$this->indexFinal[$nnc] = $infos;
|
|
|
159 |
}
|
|
|
160 |
}
|
|
|
161 |
|
471 |
jpm |
162 |
private function genererNbreTaxons() {
|
|
|
163 |
foreach ($this->indexFinal as $infos) {
|
|
|
164 |
if ($infos['num_tax_sup_coste'] != '') {
|
|
|
165 |
if (isset($this->nbreTaxonInf[$infos['num_tax_sup_coste']])) {
|
|
|
166 |
$this->nbreTaxonInf[$infos['num_tax_sup_coste']] += 1;
|
|
|
167 |
} else {
|
|
|
168 |
$this->nbreTaxonInf[$infos['num_tax_sup_coste']] = 1;
|
|
|
169 |
}
|
|
|
170 |
}
|
|
|
171 |
}
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
private function genererPageWikiDsc($infos) {
|
|
|
175 |
$prefixe = $this->genererPrefixePage($infos);
|
487 |
jpm |
176 |
if ($infos['rang'] == '180') {
|
|
|
177 |
$nomSci = str_replace(' ', '', ucwords(strtolower($infos['nom_coste'])));
|
|
|
178 |
} else {
|
|
|
179 |
$nomSci = str_replace(' ', '', ucwords(strtolower($infos['nom_sci'])));
|
|
|
180 |
}
|
471 |
jpm |
181 |
$pageWiki = $prefixe.$nomSci;
|
|
|
182 |
return $pageWiki;
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
private function genererPageWikiCle($infos) {
|
|
|
186 |
$pageWiki = '';
|
|
|
187 |
if ($infos['nbre_taxons'] > 1) {
|
|
|
188 |
$prefixe = $this->genererPrefixePage($infos);
|
487 |
jpm |
189 |
if ($infos['rang'] == '20') {
|
|
|
190 |
$pageWiki = $prefixe.'TabClaEtEmb';
|
|
|
191 |
} elseif ($infos['rang'] == '40' && ($infos['num_nom_coste'] == 'E2' || $infos['num_nom_coste'] == 'E3')) {
|
|
|
192 |
$pageWiki = $prefixe.'TabFam';
|
|
|
193 |
} else if ($infos['rang'] == '80') {
|
|
|
194 |
$pageWiki = $prefixe.'TabFam';
|
|
|
195 |
} else if ($infos['rang'] == '180') {
|
471 |
jpm |
196 |
$pageWiki = $prefixe.'TabGen';
|
|
|
197 |
} else if ($infos['rang'] == '220') {
|
|
|
198 |
$pageWiki = $prefixe.'TabSp';
|
|
|
199 |
}
|
|
|
200 |
}
|
|
|
201 |
return $pageWiki;
|
|
|
202 |
}
|
|
|
203 |
|
|
|
204 |
private function genererPrefixePage($infos) {
|
|
|
205 |
$prefixe = '';
|
494 |
jpm |
206 |
$num = preg_replace('/^[a-z]*([0-9]+)(?:[.][0-9a-z]|)$/i', '$1', $infos['num_nom_coste']);
|
|
|
207 |
if (preg_match('/^([0-9]+)[.][0-9a-z]$/i', $infos['num_nom_coste'], $match)) {
|
471 |
jpm |
208 |
$num = sprintf('%04s', $match[1]);
|
487 |
jpm |
209 |
} else if ($infos['rang'] == 20 ) {
|
|
|
210 |
$num = '';
|
471 |
jpm |
211 |
} else if ($infos['rang'] < 80 ) {
|
|
|
212 |
$num = sprintf('%02s', $num);
|
|
|
213 |
} else if ($infos['rang'] < 290 ) {
|
|
|
214 |
$num = sprintf('%03s', $num);
|
|
|
215 |
} else {
|
|
|
216 |
$num = sprintf('%04s', $num);
|
|
|
217 |
}
|
|
|
218 |
$rangsTxt = array('20' => 'Reg', '40' => 'Emb', '80' => 'Cla', '180' => 'Fam', '220' => 'Gen', '290' => 'Esp', '340' => 'Var');
|
|
|
219 |
$rang = $rangsTxt[$infos['rang']];
|
|
|
220 |
|
|
|
221 |
$prefixe = $rang.$num;
|
|
|
222 |
return $prefixe;
|
|
|
223 |
}
|
|
|
224 |
|
|
|
225 |
private function obtenirNbreTaxon($infos) {
|
|
|
226 |
$nbre = '';
|
487 |
jpm |
227 |
if (isset($this->nbreTaxonInf[$infos['num_nom_coste']])) {
|
|
|
228 |
$nbre = $this->nbreTaxonInf[$infos['num_nom_coste']];
|
471 |
jpm |
229 |
}
|
|
|
230 |
return $nbre;
|
|
|
231 |
}
|
|
|
232 |
|
|
|
233 |
private function obtenirNomFichierImg($infos) {
|
|
|
234 |
$img = '';
|
494 |
jpm |
235 |
if ($infos['rang'] == '290') {
|
|
|
236 |
$prefixe = preg_replace('/[.][a-z]$/', '', $infos['num_nom_retenu']);
|
|
|
237 |
$img = $prefixe.'.png';
|
471 |
jpm |
238 |
}
|
|
|
239 |
return $img;
|
|
|
240 |
}
|
|
|
241 |
|
487 |
jpm |
242 |
private function ajouteurAuteurImage() {
|
|
|
243 |
$this->chargerAuteurImg();
|
|
|
244 |
foreach ($this->indexFinal as $nnc => $infos) {
|
|
|
245 |
$infos['image_auteur'] = $this->imgIndex[$infos['image']];
|
|
|
246 |
$this->indexFinal[$nnc] = $infos;
|
|
|
247 |
}
|
|
|
248 |
}
|
|
|
249 |
|
|
|
250 |
private function chargerAuteurImg() {
|
|
|
251 |
$imgIndexFichier = $this->dossierBase.self::DOSSIER_V0.'coste_images_auteur_correspondance_bdnff.tsv';
|
|
|
252 |
$index = $this->outils->transformerTxtTsvEnTableau($imgIndexFichier);
|
|
|
253 |
foreach ($index as $infos) {
|
|
|
254 |
$id = $infos['id_image'];
|
|
|
255 |
$this->imgIndex[$id] = $infos['auteur'];
|
|
|
256 |
}
|
|
|
257 |
}
|
|
|
258 |
|
|
|
259 |
private function decomposerNomSci() {
|
|
|
260 |
$majuscule = "[ÆŒA-Z]";
|
|
|
261 |
$epithete = "[æœïa-z-]+";
|
|
|
262 |
foreach ($this->indexFinal as $nnc => $infos) {
|
|
|
263 |
$id = $infos['num_nom_coste'];
|
|
|
264 |
$nomSci = $infos['nom_sci'];
|
|
|
265 |
$rang = $infos['rang'];
|
|
|
266 |
if ($rang < 220) {
|
|
|
267 |
$infos['nom_supra_generique'] = $nomSci;
|
|
|
268 |
} else if ($rang == 220) {
|
|
|
269 |
$infos['genre'] = $nomSci;
|
|
|
270 |
} else if ($rang == 290) {
|
|
|
271 |
if (preg_match("/^($majuscule$epithete) ($epithete)$/", $nomSci, $match)) {
|
|
|
272 |
$infos['genre'] = $match[1];
|
|
|
273 |
$infos['epithete_sp'] = $match[2];
|
|
|
274 |
} else {
|
|
|
275 |
$this->messages->traiterErreur("Le nom $nomSci ($id) de rang $rang n'est pas standard.");
|
|
|
276 |
}
|
|
|
277 |
} else if ($rang == 340) {
|
|
|
278 |
if (preg_match("/^($majuscule$epithete) ($epithete) (var[.]) ($epithete)$/", $nomSci, $match)) {
|
|
|
279 |
$infos['genre'] = $match[1];
|
|
|
280 |
$infos['epithete_sp'] = $match[2];
|
|
|
281 |
$infos['type_epithete'] = $match[3];
|
|
|
282 |
$infos['epithete_infra_sp'] = $match[4];
|
|
|
283 |
} else {
|
|
|
284 |
$this->messages->traiterErreur("Le nom $nomSci ($id) de rang $rang n'est pas standard.");
|
|
|
285 |
}
|
|
|
286 |
}
|
|
|
287 |
|
|
|
288 |
$this->indexFinal[$nnc] = $infos;
|
|
|
289 |
$this->messages->afficherAvancement("Décomposition des noms scientifiques en cours");
|
|
|
290 |
}
|
|
|
291 |
echo "\n";
|
|
|
292 |
}
|
|
|
293 |
|
|
|
294 |
private function ajouteurNomSciHtml() {
|
|
|
295 |
foreach ($this->indexFinal as $nnc => $infos) {
|
|
|
296 |
$this->indexFinal[$nnc]['nom_sci_html'] = $this->generateur->genererNomSciHtml($infos);
|
|
|
297 |
$this->messages->afficherAvancement("Création des noms scientifiques HTML en cours");
|
|
|
298 |
}
|
|
|
299 |
echo "\n";
|
|
|
300 |
}
|
|
|
301 |
|
494 |
jpm |
302 |
private function insererCorrections() {
|
493 |
jpm |
303 |
$correctionsFichier = $this->dossierBase.self::DOSSIER_V2.'coste_v2_00_corrections.tsv';
|
|
|
304 |
$corrections = $this->outils->transformerTxtTsvEnTableau($correctionsFichier);
|
|
|
305 |
foreach ($corrections as $infos) {
|
|
|
306 |
$nnc = $infos['num_nom_coste'];
|
494 |
jpm |
307 |
$infosACorriger = isset($this->indexFinal[$nnc]) ? $this->indexFinal[$nnc] : array();
|
493 |
jpm |
308 |
foreach ($corrections as $champ => $valeur) {
|
|
|
309 |
$infosACorriger[$champ] = $valeur;
|
|
|
310 |
}
|
|
|
311 |
$this->indexFinal[$nnc] = $infosACorriger;
|
|
|
312 |
}
|
|
|
313 |
}
|
|
|
314 |
|
469 |
jpm |
315 |
private function creerFichierCsvIndexFinal() {
|
|
|
316 |
$lignes = array();
|
|
|
317 |
array_unshift($this->indexFinal, $this->enteteFinal);
|
|
|
318 |
foreach ($this->indexFinal as $infos) {
|
493 |
jpm |
319 |
$lignes[] = implode("\t", $infos);
|
469 |
jpm |
320 |
}
|
|
|
321 |
|
|
|
322 |
$txt = '';
|
|
|
323 |
$txt = implode("\n", $lignes);
|
|
|
324 |
|
478 |
jpm |
325 |
$fichierTsvIndexFinal = $this->dossierBase.self::DOSSIER_V2.'coste_v2_00.tsv';
|
469 |
jpm |
326 |
file_put_contents($fichierTsvIndexFinal, $txt);
|
|
|
327 |
}
|
|
|
328 |
}
|
|
|
329 |
?>
|