Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev 435 Rev 436
Line 5... Line 5...
5
	const DOSSIER_V0 = '../../../donnees/coste/0.00/';
5
	const DOSSIER_V0 = '../../../donnees/coste/0.00/';
6
	const DOSSIER_DSC_HTML = '../../../donnees/coste/descriptions/html/';
6
	const DOSSIER_DSC_HTML = '../../../donnees/coste/descriptions/html/';
7
	const DOSSIER_DSC_TXT = '../../../donnees/coste/descriptions/txt/';
7
	const DOSSIER_DSC_TXT = '../../../donnees/coste/descriptions/txt/';
8
	const DOSSIER_LOG = 'log/';
8
	const DOSSIER_LOG = 'log/';
Line -... Line 9...
-
 
9
 
9
 
10
	private $atueurs = array();
10
	private $dossierBase = '';
11
	private $dossierBase = '';
11
	private $conteneur = null;
12
	private $conteneur = null;
12
	private $outils = null;
13
	private $outils = null;
13
	private $messages = null;
14
	private $messages = null;
Line 19... Line 20...
19
	private $fichier = '';
20
	private $fichier = '';
20
	private $log = '';
21
	private $log = '';
21
	private $correspondance = array();
22
	private $correspondance = array();
22
	private $infosCorrespondanceBase = array(
23
	private $infosCorrespondanceBase = array(
23
		'nom_sci' => '',
24
		'nom_sci' => '',
24
		'rang' => 290,
-
 
25
		'auteur' => '',
25
		'auteur' => '',
-
 
26
		'nom_addendum' => '',
26
		'annee' => '',
27
		'annee' => '',
27
		'biblio_coste' => '',
28
		'biblio_coste' => '',
-
 
29
		'rang' => 290,
28
		'nom_francais' => '',
30
		'nom_francais' => '',
29
		'nom_coste' => '',
31
		'nom_coste' => '',
30
		'auteur_coste' => '',
32
		'auteur_coste' => '',
31
		'num_nom_coste' => '',
33
		'num_nom_coste' => '',
32
		'num_nom_retenu_coste' => '',
34
		'num_nom_retenu_coste' => '',
Line 60... Line 62...
60
		foreach ($this->listeFichiers as $this->fichierNum => $this->fichier) {
62
		foreach ($this->listeFichiers as $this->fichierNum => $this->fichier) {
61
			$this->messages->afficherAvancement("Analyse des descriptions");
63
			$this->messages->afficherAvancement("Analyse des descriptions");
62
			$this->verifierFichier();
64
			$this->verifierFichier();
63
		}
65
		}
64
		echo "\n";
66
		echo "\n";
65
 
-
 
66
		$fichierTxt = $this->dossierBase.self::DOSSIER_LOG.'analyse.log';
-
 
67
		file_put_contents($fichierTxt, $this->log);
67
		$this->ecrireLogs();
68
	}
68
	}
Line 69... Line 69...
69
 
69
 
70
	public function genererCorrespondance() {
70
	public function genererCorrespondance() {
71
		$this->chargerFichiers();
71
		$this->chargerFichiers();
-
 
72
 
72
 
73
		$this->ajouterLogSyno(implode("\t", array_keys($this->infosCorrespondanceBase)));
73
		foreach ($this->listeFichiers as $this->fichierNum => $this->fichier) {
74
		foreach ($this->listeFichiers as $this->fichierNum => $this->fichier) {
74
			$this->messages->afficherAvancement("Création du fichier de correspondance");
75
			$this->messages->afficherAvancement("Création du fichier de correspondance");
75
			$this->extraireInfosCorrespondance();
76
			$this->extraireInfosCorrespondance();
76
		}
77
		}
Line 77... Line 78...
77
		echo "\n";
78
		echo "\n";
78
 
79
 
79
		$fichierTxt = $this->dossierBase.self::DOSSIER_V0.'index_general_sp.tsv';
80
		$fichierTxt = $this->dossierBase.self::DOSSIER_V0.'index_general_sp.tsv';
Line 80... Line -...
80
		$txtCorrespondance = $this->creerFichierCsvCorrespondance();
-
 
81
		file_put_contents($fichierTxt, $txtCorrespondance);
81
		$txtCorrespondance = $this->creerFichierCsvCorrespondance();
82
 
82
		file_put_contents($fichierTxt, $txtCorrespondance);
Line 83... Line 83...
83
		$fichierLog = $this->dossierBase.self::DOSSIER_LOG.'synonymes.log';
83
 
84
		file_put_contents($fichierLog, $this->log);
84
		$this->ecrireLogs();
85
	}
85
	}
Line 119... Line 119...
119
 
119
 
120
	private function verifierOuvertureFermetureBalise($txt) {
120
	private function verifierOuvertureFermetureBalise($txt) {
121
		$b_ouvert = substr_count($txt, '<B>');
121
		$b_ouvert = substr_count($txt, '<B>');
122
		$b_ferme = substr_count($txt, '</B>');
122
		$b_ferme = substr_count($txt, '</B>');
123
		if ($b_ouvert != $b_ferme) {
123
		if ($b_ouvert != $b_ferme) {
-
 
124
			$message = "{$this->fichierNum} contient $b_ouvert balises B ouvertes et $b_ferme fermées";
124
			$this->log .= "{$this->fichierNum} contient $b_ouvert balises B ouvertes et $b_ferme fermées\n";
125
			$this->ajouterLogAnalyse($message);
125
		}
126
		}
126
		$i_ouvert = substr_count($txt, '<I>');
127
		$i_ouvert = substr_count($txt, '<I>');
127
		$i_ferme = substr_count($txt, '</I>');
128
		$i_ferme = substr_count($txt, '</I>');
128
		if ($i_ouvert != $i_ferme) {
129
		if ($i_ouvert != $i_ferme) {
-
 
130
			$message = "{$this->fichierNum} contient $i_ouvert balises I ouvertes et $i_ferme fermées";
129
			$this->log .= "{$this->fichierNum} contient $i_ouvert balises I ouvertes et $i_ferme fermées\n";
131
			$this->ajouterLogAnalyse($message);
130
		}
132
		}
Line 131... Line 133...
131
	}
133
	}
132
 
134
 
133
	private function verifierAbscenceEgale($txt) {
135
	private function verifierAbscenceEgale($txt) {
-
 
136
		if (strripos($txt, '=') === false) {
134
		if (strripos($txt, '=') === false) {
137
			$message = "{$this->fichierNum} ne contient pas le séparateur de phénologie (=)";
135
			$this->log .= "{$this->fichierNum} ne contient pas le séparateur de phénologie (=)\n";
138
			$this->ajouterLogAnalyse($message);
Line 136... Line 139...
136
		}
139
		}
137
	}
140
	}
138
 
141
 
-
 
142
	private function verifierNumero($txt) {
139
	private function verifierNumero($txt) {
143
		if (preg_match('/^<B>[0-9]{1,4}. – /', $txt) == 0) {
140
		if (preg_match('/^<B>[0-9]{1,4}. – /', $txt) == 0) {
144
			$message = "{$this->fichierNum} ne contient pas un numéro bien formaté";
Line 141... Line 145...
141
			$this->log .= "{$this->fichierNum} ne contient pas un numéro bien formaté\n";
145
			$this->ajouterLogAnalyse($message);
142
		}
146
		}
Line 212... Line 216...
212
		$synoCoste = preg_replace('/ et ([A-Z]{2,}|[A-Z][.] [A-Z]{2,})/', ' ; $1', $synoCoste);
216
		$synoCoste = preg_replace('/ et ([A-Z]{2,}|[A-Z][.] [A-Z]{2,})/', ' ; $1', $synoCoste);
213
		$synoCoste = preg_replace('/, ((?:(?!non |part[.]|an |G[.] G[.]|part[.]|centr[.])[^,]+))/', ' ;$1', $synoCoste);
217
		$synoCoste = preg_replace('/, ((?:(?!non |part[.]|an |G[.] G[.]|part[.]|centr[.])[^,]+))/', ' ;$1', $synoCoste);
Line 214... Line 218...
214
 
218
 
Line 215... Line 219...
215
		$synonymes = explode(';', $synoCoste);
219
		$synonymes = explode(';', $synoCoste);
216
 
220
 
217
		foreach ($synonymes as $syno) {
-
 
218
			$syno = trim($syno);
221
		foreach ($synonymes as $num => $syno) {
-
 
222
			$synoTraite = $this->traiterNomSyno($syno);
-
 
223
			$infosSyno = $this->infosCorrespondanceBase;
-
 
224
			$infosSyno['rang'] = $this->obtenirRangSyno($syno);
-
 
225
			$infosSyno['nom_sci'] = $this->obtenirNomSci($synoTraite, $infos, $synonymes, $num);
-
 
226
			$infosSyno['nom_coste'] = $synoTraite;
219
			$syno = trim($syno, ' ');
227
			$infosSyno['auteur'] =  $this->obtenirAuteur($synoTraite);
-
 
228
			$infosSyno['nom_addendum'] =  $this->obtenirNomAddendum($syno);
-
 
229
			$infosSyno['num_nom_coste'] = $infos['num_nom_coste'].'.'.($num + 1);
220
			$infosSyno = $this->infosCorrespondanceBase;
230
			$infosSyno['num_nom_retenu_coste'] = $infos['num_nom_coste'];
221
			$this->log .= $infos['num_nom_coste']."\t$syno\n";
231
			$this->ajouterLogSyno(implode("\t", $infosSyno));
222
			$this->correspondance[] = $infosSyno;
232
			$this->correspondance[] = $infosSyno;
Line -... Line 233...
-
 
233
		}
-
 
234
	}
-
 
235
 
-
 
236
	private function obtenirAuteur($syno) {
-
 
237
		$auteur = '';
-
 
238
		$nomSciRE = '(?:[^ ]+ [^ ]+ var. [^ ]+|[^ ]+ [^ ]+)';
-
 
239
		if (preg_match("/^$nomSciRE ((?!(?:auct.+|, non.+|p[.] p[.])$).+)$/", $syno, $match)) {
-
 
240
			$auteur = $match[1];
-
 
241
			$auteur = preg_replace('/(?: p[.] p[.]|, non .+|(?: Sp[.])? ed[.] [1-2])$/', '', $auteur);
-
 
242
			$this->ajouterAuteur($auteur);
-
 
243
		} else {
-
 
244
			$message = "Impossible de récupérer l'auteur pour le synonyme ($syno).";
-
 
245
			$this->ajouterLogProbleme($message);
-
 
246
		}
-
 
247
		return $auteur;
-
 
248
	}
-
 
249
 
-
 
250
	private function ajouterAuteur($auteur) {
-
 
251
		if (!isset($this->auteurs[$auteur])) {
-
 
252
			$this->auteurs[$auteur] = 1;
-
 
253
			$this->ajouterLogAuteur($auteur);
-
 
254
		} else {
-
 
255
			$this->auteurs[$auteur]++;
-
 
256
		}
-
 
257
	}
-
 
258
 
-
 
259
	private function obtenirNomAddendum($syno) {
-
 
260
		$nomAddendum = array();
-
 
261
		if (preg_match('/^((?:compr|incl)[.]) /', $syno, $match)) {
-
 
262
			$nomAddendum[] = '['.$match[1].']';
-
 
263
		}
-
 
264
		if (preg_match('/ (auct[.] .+)$/', $syno, $match)) {
-
 
265
			$nomAddendum[] = '['.$match[1].']';
-
 
266
		} else if (preg_match('/, (non .+)$/', $syno, $match)) {
-
 
267
			$nomAddendum[] = '['.$match[1].']';
-
 
268
		} else if (preg_match('/ (p[.] p[.])$/', $syno, $match)) {
-
 
269
			$nomAddendum[] = '['.$match[1].']';
-
 
270
		} else if (preg_match('/ (saltem part[.])$/', $syno, $match)) {
-
 
271
			$nomAddendum[] = '['.$match[1].']';
-
 
272
		}
-
 
273
 
-
 
274
		$nomAddendum = implode(' ; ', $nomAddendum);
-
 
275
		return $nomAddendum;
-
 
276
	}
-
 
277
 
-
 
278
	private function obtenirSynoPrecedent($synonymes, $num) {
-
 
279
		$synoPrecedent = '';
-
 
280
		if (isset($synonymes[($num - 1 )])) {
-
 
281
			$synoPrecedent = $this->traiterNomSyno($synonymes[($num - 1 )]);
-
 
282
		}
-
 
283
		return $synoPrecedent;
-
 
284
	}
-
 
285
 
-
 
286
	private function remplacerAbreviationGenre($syno, $infos, $synonymes, $num) {
-
 
287
		$nomSci = $syno;
-
 
288
 
-
 
289
		if (preg_match('/^(([A-Zƌ])[.]) /', $syno, $matchSyno)) {
-
 
290
			if ($matchSyno[2] == substr($infos['nom_coste'], 0, 1)) {
-
 
291
				if (preg_match('/^([^ ]+) /', $infos['nom_coste'], $matchNomRetenu)) {
-
 
292
					$nomSci = str_replace($matchSyno[1], $matchNomRetenu[1], $syno);
-
 
293
				}
-
 
294
			} else {
-
 
295
				$synoPrecedent = $this->obtenirSynoAvecGenreComplet($synonymes, $num);
-
 
296
 
-
 
297
				if ($matchSyno[2] == substr($synoPrecedent, 0, 1)) {
-
 
298
					if (preg_match('/^([^ ]+) /', $synoPrecedent, $matchSynoPrec)) {
-
 
299
						$nomSci = str_replace($matchSyno[1], $matchSynoPrec[1], $syno);
-
 
300
					}
-
 
301
				} else {
-
 
302
					$message = "L'initiale du synonyme ($syno) ne correspondant pas au nom retenu {$infos['num_nom_coste']} ({$infos['nom_coste']}) ".
-
 
303
							"ni au synonyme précédent ($synoPrecedent).";
-
 
304
					$this->ajouterLogProbleme($message);
-
 
305
				}
-
 
306
			}
-
 
307
		}
-
 
308
		return $nomSci;
-
 
309
	}
-
 
310
 
-
 
311
	private function obtenirSynoAvecGenreComplet($synonymes, $num) {
-
 
312
		$synoPrecedent = '';
-
 
313
		$synoOk = false;
-
 
314
		while ($synoOk == false) {
-
 
315
			if ($num < 0) {
-
 
316
				$synoOk = true;
-
 
317
			}
-
 
318
			$synoPrecedent = $this->obtenirSynoPrecedent($synonymes, $num);
-
 
319
			if (preg_match('/^[A-Zƌ][.] /', $synoPrecedent)) {
-
 
320
				$num = $num - 1;
-
 
321
			} else {
-
 
322
				$synoOk = true;
-
 
323
			}
-
 
324
		}
-
 
325
		return $synoPrecedent;
-
 
326
	}
-
 
327
 
-
 
328
	private function obtenirNomSci($syno, $infos, $synonymes, $num) {
-
 
329
		$nomSci = $this->remplacerAbreviationGenre($syno, $infos, $synonymes, $num);
-
 
330
 
-
 
331
		if (preg_match('/^([^ ]+) ([^ ]+) var. ([^ ]+)/', $nomSci, $match)) {
-
 
332
			$genre = ucfirst(strtolower($match[1]));
-
 
333
			$sp = strtolower($match[2]);
-
 
334
			$infrasp = strtolower($match[3]);
-
 
335
			$nomSci = "$genre $sp var. $infrasp";
-
 
336
		} else if (preg_match('/^([^ ]+) ([^ ]+)(?: |$)/', $nomSci, $match)) {
-
 
337
			$genre = ucfirst(strtolower($match[1]));
-
 
338
			$sp = strtolower($match[2]);
-
 
339
			$nomSci = "$genre $sp";
-
 
340
		} else {
-
 
341
			$message = "Le synonyme ($nomSci) du nom {$infos['num_nom_coste']} a une structure étrange.";
-
 
342
			$this->ajouterLogProbleme($message);
-
 
343
		}
-
 
344
		return $nomSci;
-
 
345
	}
-
 
346
 
-
 
347
	private function obtenirRangSyno($syno) {
-
 
348
		$rang = 290;
-
 
349
		if (strpos($syno, ' var. ')) {
-
 
350
			$rang = 340;
-
 
351
		}
-
 
352
		return $rang;
-
 
353
	}
-
 
354
 
-
 
355
	private function traiterNomSyno($syno) {
-
 
356
		$syno = trim($syno);
-
 
357
		$syno = trim($syno, ' ');
-
 
358
		$syno = preg_replace('/^(?:compr|incl)[.] /', '', $syno);
223
		}
359
		return $syno;
224
	}
360
	}
225
 
361
 
226
	private function creerFichierCsvCorrespondance() {
362
	private function creerFichierCsvCorrespondance() {
227
		$lignes[] = implode("\t", array_keys($this->infosCorrespondanceBase));
363
		$lignes[] = implode("\t", array_keys($this->infosCorrespondanceBase));
Line 302... Line 438...
302
	private function remplacerHtmlParSyntaxeWiki($txt) {
438
	private function remplacerHtmlParSyntaxeWiki($txt) {
303
		$txt = str_replace(array('<B>', '</B>'), '**', $txt);
439
		$txt = str_replace(array('<B>', '</B>'), '**', $txt);
304
		$txt = str_replace(array('<I>', '</I>'), '//', $txt);
440
		$txt = str_replace(array('<I>', '</I>'), '//', $txt);
305
		return $txt;
441
		return $txt;
306
	}
442
	}
-
 
443
 
-
 
444
	private function ajouterLogAnalyse($txt) {
-
 
445
		if (isset($this->log['analyse']) == false) {
-
 
446
			$this->log['analyse'] = '';
-
 
447
		}
-
 
448
		$this->log['analyse'] .= "$txt\n";
-
 
449
	}
-
 
450
 
-
 
451
	private function ajouterLogSyno($txt) {
-
 
452
		if (isset($this->log['synonymes']) == false) {
-
 
453
			$this->log['synonymes'] = '';
-
 
454
		}
-
 
455
		$this->log['synonymes'] .= "$txt\n";
-
 
456
	}
-
 
457
 
-
 
458
	private function ajouterLogAuteur($txt) {
-
 
459
		if (isset($this->log['auteurs']) == false) {
-
 
460
			$this->log['auteurs'] = '';
-
 
461
		}
-
 
462
		$this->log['auteurs'] .= "$txt\n";
-
 
463
	}
-
 
464
 
-
 
465
	private function ajouterLogProbleme($txt) {
-
 
466
		if (isset($this->log['problemes']) == false) {
-
 
467
			$this->log['problemes'] = '';
-
 
468
		}
-
 
469
		$this->log['problemes'] .= "$txt\n";
-
 
470
	}
-
 
471
 
-
 
472
	private function ecrireLogs() {
-
 
473
		foreach ($this->log as $nom => $log) {
-
 
474
			$fichier = $this->dossierBase.self::DOSSIER_LOG.$nom.'.log';
-
 
475
			file_put_contents($fichier, $log);
-
 
476
		}
-
 
477
	}
307
}
478
}
308
?>
479
?>
309
480