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();
|
|
|
72 |
$this->ajouterChampsDansIndexFinal();
|
487 |
jpm |
73 |
$this->ajouteurAuteurImage();
|
|
|
74 |
$this->decomposerNomSci();
|
|
|
75 |
$this->ajouteurNomSciHtml();
|
469 |
jpm |
76 |
$this->creerFichierCsvIndexFinal();
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
private function chargerIndexSp() {
|
|
|
80 |
$spIndexFichier = $this->dossierBase.self::DOSSIER_V0.'index_general_sp.tsv';
|
476 |
jpm |
81 |
$index = $this->outils->transformerTxtTsvEnTableau($spIndexFichier);
|
469 |
jpm |
82 |
$index = $this->reindexerParNumNomCoste($index);
|
|
|
83 |
foreach ($index as $numNomCoste => $infos) {
|
|
|
84 |
$numTaxSup = '';
|
|
|
85 |
if ($infos['num_nom_coste'] == $infos['num_nom_retenu_coste']) {
|
|
|
86 |
$numTaxSup = $infos['num_tax_sup_coste'];
|
|
|
87 |
} else {
|
|
|
88 |
$infosNomRetenu = $index[$infos['num_nom_retenu_coste']];
|
|
|
89 |
$numTaxSup = $infosNomRetenu['num_tax_sup_coste'];
|
|
|
90 |
}
|
|
|
91 |
$this->spIndex[$numTaxSup][] = $infos;
|
|
|
92 |
}
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
private function reindexerParNumNomCoste($index) {
|
|
|
96 |
$nouvelIndex = array();
|
|
|
97 |
foreach ($index as $infos) {
|
|
|
98 |
$nouvelIndex[$infos['num_nom_coste']] = $infos;
|
|
|
99 |
}
|
|
|
100 |
return $nouvelIndex;
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
private function chargerIndexSupraSp() {
|
|
|
104 |
$infraSpIndexFichier = $this->dossierBase.self::DOSSIER_V0.'index_general.tsv';
|
476 |
jpm |
105 |
$this->supraSpIndex = $this->outils->transformerTxtTsvEnTableau($infraSpIndexFichier);
|
469 |
jpm |
106 |
foreach ($this->supraSpIndex as $cle => $infos) {
|
|
|
107 |
$this->supraSpIndex[$cle]['num_nom_retenu_coste'] = $infos['num_nom_coste'];
|
|
|
108 |
}
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
private function initialiserTableauLigneIndexFinal() {
|
|
|
112 |
$this->tableauParDefaut = array();
|
|
|
113 |
foreach ($this->enteteFinal as $cle) {
|
|
|
114 |
$this->tableauParDefaut[$cle] = '';
|
|
|
115 |
}
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
private function creerIndexFinal() {
|
|
|
119 |
foreach ($this->supraSpIndex as $infos) {
|
|
|
120 |
$this->ajouterDansIndexFinal($infos);
|
|
|
121 |
if (preg_match('/^G[0-9]+$/', $infos['num_nom_coste'])) {
|
|
|
122 |
foreach ($this->spIndex[$infos['num_nom_coste']] as $infosSp) {
|
|
|
123 |
$this->ajouterDansIndexFinal($infosSp);
|
|
|
124 |
}
|
|
|
125 |
}
|
|
|
126 |
}
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
private function ajouterDansIndexFinal($infos) {
|
|
|
130 |
$infos = array_merge($this->tableauParDefaut, $infos);
|
471 |
jpm |
131 |
$infos['num_nom'] = (count($this->indexFinal) + 1);
|
469 |
jpm |
132 |
$this->indexFinal[$infos['num_nom_coste']] = $infos;
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
private function ajouterChampsDansIndexFinal() {
|
471 |
jpm |
136 |
$this->genererNbreTaxons();
|
469 |
jpm |
137 |
foreach ($this->indexFinal as $nnc => $infos) {
|
|
|
138 |
if ($infos['num_nom_coste'] == $infos['num_nom_retenu_coste']) {
|
|
|
139 |
$infos['num_nom_retenu'] = $infos['num_nom'];
|
|
|
140 |
if ($nnc != 'R') {
|
|
|
141 |
$nomSuperieur = $this->indexFinal[$infos['num_tax_sup_coste']];
|
|
|
142 |
$infos['num_tax_sup'] = $nomSuperieur['num_nom'];
|
|
|
143 |
}
|
471 |
jpm |
144 |
$nomRetenu = $infos;
|
469 |
jpm |
145 |
} else {
|
|
|
146 |
$nomRetenu = $this->indexFinal[$infos['num_nom_retenu_coste']];
|
|
|
147 |
$infos['num_nom_retenu'] = $nomRetenu['num_nom'];
|
|
|
148 |
}
|
471 |
jpm |
149 |
$infos['image'] = $this->obtenirNomFichierImg($nomRetenu);
|
|
|
150 |
$infos['nbre_taxons'] = $this->obtenirNbreTaxon($infos);
|
476 |
jpm |
151 |
$nomRetenu['nbre_taxons'] = $infos['nbre_taxons'];
|
471 |
jpm |
152 |
$infos['page_wiki_dsc'] = $this->genererPageWikiDsc($nomRetenu);
|
|
|
153 |
$infos['page_wiki_cle'] = $this->genererPageWikiCle($nomRetenu);
|
|
|
154 |
|
469 |
jpm |
155 |
$this->indexFinal[$nnc] = $infos;
|
|
|
156 |
}
|
|
|
157 |
}
|
|
|
158 |
|
471 |
jpm |
159 |
private function genererNbreTaxons() {
|
|
|
160 |
foreach ($this->indexFinal as $infos) {
|
|
|
161 |
if ($infos['num_tax_sup_coste'] != '') {
|
|
|
162 |
if (isset($this->nbreTaxonInf[$infos['num_tax_sup_coste']])) {
|
|
|
163 |
$this->nbreTaxonInf[$infos['num_tax_sup_coste']] += 1;
|
|
|
164 |
} else {
|
|
|
165 |
$this->nbreTaxonInf[$infos['num_tax_sup_coste']] = 1;
|
|
|
166 |
}
|
|
|
167 |
}
|
|
|
168 |
}
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
private function genererPageWikiDsc($infos) {
|
|
|
172 |
$prefixe = $this->genererPrefixePage($infos);
|
487 |
jpm |
173 |
if ($infos['rang'] == '180') {
|
|
|
174 |
$nomSci = str_replace(' ', '', ucwords(strtolower($infos['nom_coste'])));
|
|
|
175 |
} else {
|
|
|
176 |
$nomSci = str_replace(' ', '', ucwords(strtolower($infos['nom_sci'])));
|
|
|
177 |
}
|
471 |
jpm |
178 |
$pageWiki = $prefixe.$nomSci;
|
|
|
179 |
return $pageWiki;
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
private function genererPageWikiCle($infos) {
|
|
|
183 |
$pageWiki = '';
|
|
|
184 |
if ($infos['nbre_taxons'] > 1) {
|
|
|
185 |
$prefixe = $this->genererPrefixePage($infos);
|
487 |
jpm |
186 |
if ($infos['rang'] == '20') {
|
|
|
187 |
$pageWiki = $prefixe.'TabClaEtEmb';
|
|
|
188 |
} elseif ($infos['rang'] == '40' && ($infos['num_nom_coste'] == 'E2' || $infos['num_nom_coste'] == 'E3')) {
|
|
|
189 |
$pageWiki = $prefixe.'TabFam';
|
|
|
190 |
} else if ($infos['rang'] == '80') {
|
|
|
191 |
$pageWiki = $prefixe.'TabFam';
|
|
|
192 |
} else if ($infos['rang'] == '180') {
|
471 |
jpm |
193 |
$pageWiki = $prefixe.'TabGen';
|
|
|
194 |
} else if ($infos['rang'] == '220') {
|
|
|
195 |
$pageWiki = $prefixe.'TabSp';
|
|
|
196 |
}
|
|
|
197 |
}
|
|
|
198 |
return $pageWiki;
|
|
|
199 |
}
|
|
|
200 |
|
|
|
201 |
private function genererPrefixePage($infos) {
|
|
|
202 |
$prefixe = '';
|
|
|
203 |
$num = preg_replace('/^[a-z]*([0-9.]+)$/i', '$1', $infos['num_nom_coste']);
|
|
|
204 |
if (preg_match('/^([0-9]+)[.][0-9]+$/i', $infos['num_nom_coste'], $match)) {
|
|
|
205 |
$num = sprintf('%04s', $match[1]);
|
487 |
jpm |
206 |
} else if ($infos['rang'] == 20 ) {
|
|
|
207 |
$num = '';
|
471 |
jpm |
208 |
} else if ($infos['rang'] < 80 ) {
|
|
|
209 |
$num = sprintf('%02s', $num);
|
|
|
210 |
} else if ($infos['rang'] < 290 ) {
|
|
|
211 |
$num = sprintf('%03s', $num);
|
|
|
212 |
} else {
|
|
|
213 |
$num = sprintf('%04s', $num);
|
|
|
214 |
}
|
|
|
215 |
$rangsTxt = array('20' => 'Reg', '40' => 'Emb', '80' => 'Cla', '180' => 'Fam', '220' => 'Gen', '290' => 'Esp', '340' => 'Var');
|
|
|
216 |
$rang = $rangsTxt[$infos['rang']];
|
|
|
217 |
|
|
|
218 |
$prefixe = $rang.$num;
|
|
|
219 |
return $prefixe;
|
|
|
220 |
}
|
|
|
221 |
|
|
|
222 |
private function obtenirNbreTaxon($infos) {
|
|
|
223 |
$nbre = '';
|
487 |
jpm |
224 |
if (isset($this->nbreTaxonInf[$infos['num_nom_coste']])) {
|
|
|
225 |
$nbre = $this->nbreTaxonInf[$infos['num_nom_coste']];
|
471 |
jpm |
226 |
}
|
|
|
227 |
return $nbre;
|
|
|
228 |
}
|
|
|
229 |
|
|
|
230 |
private function obtenirNomFichierImg($infos) {
|
|
|
231 |
$img = '';
|
|
|
232 |
if ($infos['rang'] == '290' && ($infos['num_nom'] == $infos['num_nom_retenu'])) {
|
|
|
233 |
$img = $infos['num_nom_coste'].'.png';
|
|
|
234 |
}
|
|
|
235 |
return $img;
|
|
|
236 |
}
|
|
|
237 |
|
487 |
jpm |
238 |
private function ajouteurAuteurImage() {
|
|
|
239 |
$this->chargerAuteurImg();
|
|
|
240 |
foreach ($this->indexFinal as $nnc => $infos) {
|
|
|
241 |
$infos['image_auteur'] = $this->imgIndex[$infos['image']];
|
|
|
242 |
$this->indexFinal[$nnc] = $infos;
|
|
|
243 |
}
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
private function chargerAuteurImg() {
|
|
|
247 |
$imgIndexFichier = $this->dossierBase.self::DOSSIER_V0.'coste_images_auteur_correspondance_bdnff.tsv';
|
|
|
248 |
$index = $this->outils->transformerTxtTsvEnTableau($imgIndexFichier);
|
|
|
249 |
foreach ($index as $infos) {
|
|
|
250 |
$id = $infos['id_image'];
|
|
|
251 |
$this->imgIndex[$id] = $infos['auteur'];
|
|
|
252 |
}
|
|
|
253 |
}
|
|
|
254 |
|
|
|
255 |
private function decomposerNomSci() {
|
|
|
256 |
$majuscule = "[ÆŒA-Z]";
|
|
|
257 |
$epithete = "[æœïa-z-]+";
|
|
|
258 |
foreach ($this->indexFinal as $nnc => $infos) {
|
|
|
259 |
$id = $infos['num_nom_coste'];
|
|
|
260 |
$nomSci = $infos['nom_sci'];
|
|
|
261 |
$rang = $infos['rang'];
|
|
|
262 |
if ($rang < 220) {
|
|
|
263 |
$infos['nom_supra_generique'] = $nomSci;
|
|
|
264 |
} else if ($rang == 220) {
|
|
|
265 |
$infos['genre'] = $nomSci;
|
|
|
266 |
} else if ($rang == 290) {
|
|
|
267 |
if (preg_match("/^($majuscule$epithete) ($epithete)$/", $nomSci, $match)) {
|
|
|
268 |
$infos['genre'] = $match[1];
|
|
|
269 |
$infos['epithete_sp'] = $match[2];
|
|
|
270 |
} else {
|
|
|
271 |
$this->messages->traiterErreur("Le nom $nomSci ($id) de rang $rang n'est pas standard.");
|
|
|
272 |
}
|
|
|
273 |
} else if ($rang == 340) {
|
|
|
274 |
if (preg_match("/^($majuscule$epithete) ($epithete) (var[.]) ($epithete)$/", $nomSci, $match)) {
|
|
|
275 |
$infos['genre'] = $match[1];
|
|
|
276 |
$infos['epithete_sp'] = $match[2];
|
|
|
277 |
$infos['type_epithete'] = $match[3];
|
|
|
278 |
$infos['epithete_infra_sp'] = $match[4];
|
|
|
279 |
} else {
|
|
|
280 |
$this->messages->traiterErreur("Le nom $nomSci ($id) de rang $rang n'est pas standard.");
|
|
|
281 |
}
|
|
|
282 |
}
|
|
|
283 |
|
|
|
284 |
$this->indexFinal[$nnc] = $infos;
|
|
|
285 |
$this->messages->afficherAvancement("Décomposition des noms scientifiques en cours");
|
|
|
286 |
}
|
|
|
287 |
echo "\n";
|
|
|
288 |
}
|
|
|
289 |
|
|
|
290 |
private function ajouteurNomSciHtml() {
|
|
|
291 |
foreach ($this->indexFinal as $nnc => $infos) {
|
|
|
292 |
$this->indexFinal[$nnc]['nom_sci_html'] = $this->generateur->genererNomSciHtml($infos);
|
|
|
293 |
$this->messages->afficherAvancement("Création des noms scientifiques HTML en cours");
|
|
|
294 |
}
|
|
|
295 |
echo "\n";
|
|
|
296 |
}
|
|
|
297 |
|
469 |
jpm |
298 |
private function creerFichierCsvIndexFinal() {
|
|
|
299 |
$lignes = array();
|
|
|
300 |
array_unshift($this->indexFinal, $this->enteteFinal);
|
|
|
301 |
foreach ($this->indexFinal as $infos) {
|
|
|
302 |
$lignes[] = implode("\t", $infos);
|
|
|
303 |
}
|
|
|
304 |
|
|
|
305 |
$txt = '';
|
|
|
306 |
$txt = implode("\n", $lignes);
|
|
|
307 |
|
478 |
jpm |
308 |
$fichierTsvIndexFinal = $this->dossierBase.self::DOSSIER_V2.'coste_v2_00.tsv';
|
469 |
jpm |
309 |
file_put_contents($fichierTsvIndexFinal, $txt);
|
|
|
310 |
}
|
|
|
311 |
}
|
|
|
312 |
?>
|