Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 428 | Rev 435 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 428 Rev 430
Line 21... Line 21...
21
	private $correspondance = array();
21
	private $correspondance = array();
22
	private $infosCorrespondanceBase = array(
22
	private $infosCorrespondanceBase = array(
23
		'nom_sci' => '',
23
		'nom_sci' => '',
24
		'rang' => 290,
24
		'rang' => 290,
25
		'auteur' => '',
25
		'auteur' => '',
-
 
26
		'annee' => '',
-
 
27
		'biblio_coste' => '',
26
		'nom_francais' => '',
28
		'nom_francais' => '',
27
		'nom_coste' => '',
29
		'nom_coste' => '',
-
 
30
		'auteur_coste' => '',
28
		'num_nom_coste' => '',
31
		'num_nom_coste' => '',
-
 
32
		'num_nom_retenu_coste' => '',
29
		'num_tax_sup_coste' => '',
33
		'num_tax_sup_coste' => '',
30
		'tome' => '',
34
		'tome' => '',
31
		'page' => '',
35
		'page' => '',
-
 
36
		'synonymie_coste' => '',
32
		'bdnff_nn' => '',
37
		'bdnff_nn' => '',
33
		'bdnff_nt' => '');
38
		'bdnff_nt' => '');
Line 34... Line 39...
34
 
39
 
35
	public function __construct(Conteneur $conteneur) {
40
	public function __construct(Conteneur $conteneur) {
Line 71... Line 76...
71
		}
76
		}
72
		echo "\n";
77
		echo "\n";
Line 73... Line 78...
73
 
78
 
74
		$fichierTxt = $this->dossierBase.self::DOSSIER_V0.'index_general_sp.tsv';
79
		$fichierTxt = $this->dossierBase.self::DOSSIER_V0.'index_general_sp.tsv';
75
		$txtCorrespondance = $this->creerFichierCsvCorrespondance();
80
		$txtCorrespondance = $this->creerFichierCsvCorrespondance();
-
 
81
		file_put_contents($fichierTxt, $txtCorrespondance);
-
 
82
 
-
 
83
		$fichierLog = $this->dossierBase.self::DOSSIER_LOG.'synonymes.log';
76
		file_put_contents($fichierTxt, $txtCorrespondance);
84
		file_put_contents($fichierLog, $this->log);
Line 77... Line 85...
77
	}
85
	}
78
 
86
 
79
	private function chargerFichiers() {
87
	private function chargerFichiers() {
Line 95... Line 103...
95
			}
103
			}
96
		} else {
104
		} else {
97
			$this->messages->traiterErreur("Le dossier {$this->nomDossier} est introuvable.");
105
			$this->messages->traiterErreur("Le dossier {$this->nomDossier} est introuvable.");
98
		}
106
		}
Line 99... Line 107...
99
 
107
 
100
		asort($this->listeFichiers);
108
		arsort($this->listeFichiers);
Line 101... Line 109...
101
	}
109
	}
102
 
110
 
103
	private function verifierFichier() {
111
	private function verifierFichier() {
104
		$donnees = $this->analyserFichier();
112
		$donnees = $this->analyserFichier();
105
		$txt = $donnees['texte'];
113
		$txt = $donnees['texte'];
106
		$this->verifierOuvertureFermetureBalise($txt);
114
		$this->verifierOuvertureFermetureBalise($txt);
-
 
115
		$this->verifierAbscenceEgale($txt);
107
		$this->verifierAbscenceEgale($txt);
116
		$this->verifierNumero($txt);
Line 108... Line 117...
108
		$this->verifierNumero($txt);
117
		// TODO : vérifier les noms vernauclaire qui sont abrégés
109
	}
118
	}
110
 
119
 
Line 136... Line 145...
136
	private function extraireInfosCorrespondance() {
145
	private function extraireInfosCorrespondance() {
137
		$donnees = $this->analyserFichier();
146
		$donnees = $this->analyserFichier();
138
		$infos = $this->infosCorrespondanceBase;
147
		$infos = $this->infosCorrespondanceBase;
Line 139... Line 148...
139
 
148
 
140
		$titre = $donnees['titre'];
149
		$titre = $donnees['titre'];
141
		if (preg_match('/^Coste ([0-9]+) - ([^ ]+ [^ ]+) - F[0-9]+, [^ ]+ - (G[0-9]+), T([123])[.]p([0-9]+)$/', $titre, $match)) {
150
		if (preg_match('/^Coste ([0-9]+) - ((?:(?! - ).)+) - F[0-9]+, (?:(?! - ).)+ - (G[0-9]+), T([123])[.]p([0-9]+)$/', $titre, $match)) {
142
			$infos['num_nom_coste'] = $match[1];
151
			$infos['num_nom_coste'] = $match[1];
143
			$infos['nom_sci'] = $match[2];
152
			$infos['nom_sci'] = $match[2];
144
			$infos['num_tax_sup_coste'] = $match[3];
153
			$infos['num_tax_sup_coste'] = $match[3];
145
			$infos['tome'] = $match[4];
154
			$infos['tome'] = $match[4];
146
			$infos['page'] = $match[5];
155
			$infos['page'] = $match[5];
147
		} else {
156
		} else {
148
			$this->messages->traiterErreur("Le titre du fichier {$this->fichierNum} est mal formaté.");
157
			$this->messages->traiterErreur("Le titre du fichier {$this->fichierNum} est mal formaté.");
Line 149... Line 158...
149
		}
158
		}
150
 
159
 
151
		$corres = $donnees['correspondance'];
160
		$corres = $donnees['correspondance'];
152
		if (preg_match('/^Bdnff ([0-9]+) -[^-]+-[^-]+- Tax=([0-9]+)$/', $corres, $match)) {
161
		if (preg_match('/^Bdnff ([0-9]+) - (?:(?! - ).)+ - (?:(?! - ).)+ - Tax=([0-9]+)$/', $corres, $match)) {
153
			$infos['bdnff_nn'] = $match[1];
-
 
154
			$infos['bdnff_nt'] = $match[2];
162
			$infos['bdnff_nn'] = $match[1];
155
 
163
			$infos['bdnff_nt'] = $match[2];
156
		} else {
164
		} else {
Line 157... Line 165...
157
			$this->messages->traiterErreur("La correspondance du fichier {$this->fichierNum} est mal formatée.");
165
			$this->messages->traiterErreur("La correspondance du fichier {$this->fichierNum} est mal formatée.");
158
		}
166
		}
159
 
167
 
160
		$txt = $donnees['texte'];
168
		$txt = $donnees['texte'];
161
		$txt = $this->corrigerDescription($txt);
169
		$txt = $this->corrigerDescription($txt);
162
		if (preg_match('/^<B>[0-9]{1,4}[.] – ([^<]+)<\/B> ([^–]+)– (?:<I>([^<]+)<\/I>|[A-Z])/u', $txt, $match)) {
170
		if (preg_match('/^<B>[0-9]{1,4}[.] – ([^<]+)<\/B> ([^–]*)– (?:<I>([^<]+)<\/I>[.] – |<I>([^<]+)<\/I>( \([^)]+\))[.] – |[A-Z]|<I>(?:Sous-|Espèce|Turion|Souche|Plante|Feuille|Racine))/u', $txt, $match)) {
-
 
171
			$infos['nom_coste'] = trim($match[1]);
-
 
172
			$infos['auteur_coste'] = trim($match[2]);
-
 
173
			$infos['nom_francais'] = isset($match[3]) ? $match[3] : '';
-
 
174
			$infos['nom_francais'] = isset($match[4]) && isset($match[5]) ? $match[4].$match[5] : $infos['nom_francais'];
-
 
175
			if (strpos($infos['auteur_coste'], '(' ) !== false) {
-
 
176
				if (preg_match('/^([^(]*)\(([^)]+)\)(?:[.]?| ; ((?:(?! – ).)+))$/', $infos['auteur_coste'], $match)) {
-
 
177
					$infos['auteur_coste'] = trim($match[1]);
-
 
178
					$infos['auteur'] = $this->traiterAuteur($infos['auteur_coste']);
-
 
179
					$parentheseContenu = trim($match[2]);
-
 
180
					if (preg_match('/^[0-9]+$/', $parentheseContenu)) {
-
 
181
						$infos['annee'] = $parentheseContenu;
-
 
182
					} else {
-
 
183
						$infos['synonymie_coste'] = $parentheseContenu;
-
 
184
						$infos['biblio_coste'] = isset($match[3]) ? trim($match[3]) : '';
-
 
185
					}
-
 
186
				} else {
163
			$infos['nom_coste'] = $match[1];
187
					$this->messages->traiterErreur("L'auteur du nom sciencitifique du fichier {$this->fichierNum} est mal formaté.");
164
			$infos['auteur'] = $match[2];
188
				}
165
			$infos['nom_francais'] = isset($match[3]) ? $match[3] : '';
189
			}
Line 166... Line 190...
166
		} else {
190
		} else {
-
 
191
			$this->messages->traiterErreur("La texte du fichier {$this->fichierNum} est mal formaté.");
-
 
192
		}
-
 
193
 
-
 
194
		$this->correspondance[] = $infos;
-
 
195
 
-
 
196
		if ($infos['synonymie_coste'] != '') {
-
 
197
			$this->traiterSynonymie($infos);
-
 
198
		}
-
 
199
	}
-
 
200
 
-
 
201
	private function traiterAuteur($auteurCoste) {
-
 
202
		$auteur = '';
-
 
203
		if ($auteurCoste != '') {
-
 
204
			$auteur = str_replace('et', '&', $auteurCoste);
-
 
205
		}
-
 
206
		return $auteur;
-
 
207
	}
-
 
208
 
-
 
209
	private function traiterSynonymie($infos) {
-
 
210
		$synoCoste = $infos['synonymie_coste'];
-
 
211
		$synoCoste = preg_replace('/^et /', '', $synoCoste);
-
 
212
		$synoCoste = preg_replace('/ et ([A-Z]{2,}|[A-Z][.] [A-Z]{2,})/', ' ; $1', $synoCoste);
-
 
213
		$synoCoste = preg_replace('/, ((?:(?!non |part[.]|an |G[.] G[.])[^,]+))/', ' ;$1', $synoCoste);
-
 
214
 
-
 
215
		$synonymes = explode(';', $synoCoste);
-
 
216
 
-
 
217
		foreach ($synonymes as $syno) {
-
 
218
			$syno = trim($syno);
-
 
219
			$syno = trim($syno, ' ');
167
			$this->messages->traiterErreur("La texte du fichier {$this->fichierNum} est mal formaté.");
220
			$infosSyno = $this->infosCorrespondanceBase;
Line 168... Line 221...
168
		}
221
			$this->log .= $infos['num_nom_coste']."\t$syno\n";
169
 
222
			$this->correspondance[] = $infosSyno;
170
		$this->correspondance[] = $infos;
223
		}
Line 201... Line 254...
201
		if ($fichierOuvert = fopen($this->fichier, 'r')) {
254
		if ($fichierOuvert = fopen($this->fichier, 'r')) {
202
			$i = 1;
255
			$i = 1;
203
			while ($ligne = fgets($fichierOuvert)) {
256
			while ($ligne = fgets($fichierOuvert)) {
204
				if ($i == 24) {
257
				if ($i == 24) {
205
					$donnees['titre'] = $this->supprimerHtml($ligne);
258
					$donnees['titre'] = $this->supprimerHtml($ligne);
206
				} elseif ($i >= 45 && $i <= 62) {
259
				} elseif ($i >= 45 && $i <= 60) {
207
					$donnees['texte'] .= $this->traiterLigneDescription($ligne);
260
					$donnees['texte'] .= $this->traiterLigneDescription($ligne);
208
				} elseif (($i == 63 || $i == 67) && preg_match('/Bdnff /ui', $ligne)) {
261
				} elseif ($i >= 61 && preg_match('/Bdnff /ui', $ligne)) {
209
					$donnees['correspondance'] = $this->supprimerHtml($ligne);
262
					$donnees['correspondance'] = $this->supprimerHtml($ligne);
210
				}
263
				}
211
				$i++;
264
				$i++;
212
			}
265
			}
213
			if ($i > 94) {
-
 
214
				$this->messages->traiterErreur("Le fichier {$this->fichier} contient plus de 94 lignes ($i).");
-
 
215
			}
-
 
216
			fclose($fichierOuvert);
266
			fclose($fichierOuvert);
217
		} else {
267
		} else {
218
			$this->messages->traiterErreur("Le fichier {$this->fichier} n'a pas pu être ouvert.");
268
			$this->messages->traiterErreur("Le fichier {$this->fichier} n'a pas pu être ouvert.");
219
		}
269
		}
220
		return $donnees;
270
		return $donnees;