Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 436 | Rev 459 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
424 jpm 1
<?php
2
// commande : /opt/lampp/bin/php cli.php description_sp -a tester -n /home/jennifer/Tela-botanica_projets/Coste/descriptions/html
3
class Description {
4
 
428 jpm 5
	const DOSSIER_V0 = '../../../donnees/coste/0.00/';
6
	const DOSSIER_DSC_HTML = '../../../donnees/coste/descriptions/html/';
7
	const DOSSIER_DSC_TXT = '../../../donnees/coste/descriptions/txt/';
8
	const DOSSIER_LOG = 'log/';
424 jpm 9
 
436 jpm 10
	private $atueurs = array();
428 jpm 11
	private $dossierBase = '';
424 jpm 12
	private $conteneur = null;
13
	private $outils = null;
14
	private $messages = null;
428 jpm 15
	private $action = '';
16
	private $nomFichier = '';
17
	private $nomDossier = '';
18
	private $listeFichiers = array();
424 jpm 19
	private $fichierNum = '';
428 jpm 20
	private $fichier = '';
21
	private $log = '';
22
	private $correspondance = array();
23
	private $infosCorrespondanceBase = array(
24
		'nom_sci' => '',
25
		'auteur' => '',
436 jpm 26
		'nom_addendum' => '',
430 jpm 27
		'annee' => '',
437 jpm 28
		'biblio_origine' => '',
436 jpm 29
		'rang' => 290,
428 jpm 30
		'nom_francais' => '',
31
		'nom_coste' => '',
430 jpm 32
		'auteur_coste' => '',
437 jpm 33
		'biblio_coste' => '',
428 jpm 34
		'num_nom_coste' => '',
430 jpm 35
		'num_nom_retenu_coste' => '',
428 jpm 36
		'num_tax_sup_coste' => '',
37
		'tome' => '',
38
		'page' => '',
430 jpm 39
		'synonymie_coste' => '',
428 jpm 40
		'bdnff_nn' => '',
41
		'bdnff_nt' => '');
424 jpm 42
 
43
	public function __construct(Conteneur $conteneur) {
437 jpm 44
		mb_internal_encoding('UTF-8');
45
		setlocale(LC_ALL, 'fr_FR.UTF-8');
424 jpm 46
		$this->conteneur = $conteneur;
47
		$this->outils = $conteneur->getOutils();
48
		$this->messages = $conteneur->getMessages();
428 jpm 49
		$this->dossierBase = dirname(__FILE__).'/';
424 jpm 50
	}
51
 
52
	public function genererDescriptionTxt() {
428 jpm 53
		$this->chargerFichiers();
54
 
55
		foreach ($this->listeFichiers as $this->fichierNum => $this->fichier) {
56
			$this->messages->afficherAvancement("Création des descriptions au format txt");
57
			$this->genererFichier();
58
		}
59
		echo "\n";
424 jpm 60
	}
61
 
428 jpm 62
	public function verifierDescriptionTxt() {
63
		$this->chargerFichiers();
64
 
65
		foreach ($this->listeFichiers as $this->fichierNum => $this->fichier) {
66
			$this->messages->afficherAvancement("Analyse des descriptions");
67
			$this->verifierFichier();
68
		}
69
		echo "\n";
436 jpm 70
		$this->ecrireLogs();
428 jpm 71
	}
72
 
73
	public function genererCorrespondance() {
74
		$this->chargerFichiers();
436 jpm 75
 
76
		$this->ajouterLogSyno(implode("\t", array_keys($this->infosCorrespondanceBase)));
428 jpm 77
		foreach ($this->listeFichiers as $this->fichierNum => $this->fichier) {
78
			$this->messages->afficherAvancement("Création du fichier de correspondance");
79
			$this->extraireInfosCorrespondance();
80
		}
81
		echo "\n";
82
 
83
		$fichierTxt = $this->dossierBase.self::DOSSIER_V0.'index_general_sp.tsv';
84
		$txtCorrespondance = $this->creerFichierCsvCorrespondance();
430 jpm 85
		file_put_contents($fichierTxt, $txtCorrespondance);
86
 
437 jpm 87
		ksort($this->auteurs);
88
		foreach ($this->auteurs as $auteur => $nbre) {
89
			$this->ajouterLogAuteur("$auteur\t$nbre");
90
		}
91
 
436 jpm 92
		$this->ecrireLogs();
428 jpm 93
	}
94
 
95
	private function chargerFichiers() {
96
		$this->nomDossier = $this->dossierBase.self::DOSSIER_DSC_HTML;
97
		if (file_exists($this->nomDossier) === true) {
98
			if (is_dir($this->nomDossier)) {
99
				if ($dossierOuvert = opendir($this->nomDossier)) {
100
					while (($this->nomFichier = readdir($dossierOuvert)) !== false) {
101
						if (! is_dir($this->nomFichier) && preg_match('/e([0-9]{4})\.htm/', $this->nomFichier, $match)) {
102
							$this->listeFichiers[$match[1]] = $this->nomDossier.'/'.$this->nomFichier;
424 jpm 103
						}
104
					}
105
					closedir($dossierOuvert);
106
				} else {
428 jpm 107
					$this->messages->traiterErreur("Le dossier {$this->nomDossier} n'a pas pu être ouvert.");
424 jpm 108
				}
109
			} else {
428 jpm 110
				$this->messages->traiterErreur("{$this->nomDossier} n'est pas un dossier.");
424 jpm 111
			}
112
		} else {
428 jpm 113
			$this->messages->traiterErreur("Le dossier {$this->nomDossier} est introuvable.");
424 jpm 114
		}
428 jpm 115
 
430 jpm 116
		arsort($this->listeFichiers);
424 jpm 117
	}
118
 
428 jpm 119
	private function verifierFichier() {
120
		$donnees = $this->analyserFichier();
121
		$txt = $donnees['texte'];
122
		$this->verifierOuvertureFermetureBalise($txt);
123
		$this->verifierAbscenceEgale($txt);
124
		$this->verifierNumero($txt);
430 jpm 125
		// TODO : vérifier les noms vernauclaire qui sont abrégés
428 jpm 126
	}
127
 
128
	private function verifierOuvertureFermetureBalise($txt) {
129
		$b_ouvert = substr_count($txt, '<B>');
130
		$b_ferme = substr_count($txt, '</B>');
131
		if ($b_ouvert != $b_ferme) {
436 jpm 132
			$message = "{$this->fichierNum} contient $b_ouvert balises B ouvertes et $b_ferme fermées";
133
			$this->ajouterLogAnalyse($message);
428 jpm 134
		}
135
		$i_ouvert = substr_count($txt, '<I>');
136
		$i_ferme = substr_count($txt, '</I>');
137
		if ($i_ouvert != $i_ferme) {
436 jpm 138
			$message = "{$this->fichierNum} contient $i_ouvert balises I ouvertes et $i_ferme fermées";
139
			$this->ajouterLogAnalyse($message);
428 jpm 140
		}
141
	}
142
 
143
	private function verifierAbscenceEgale($txt) {
144
		if (strripos($txt, '=') === false) {
436 jpm 145
			$message = "{$this->fichierNum} ne contient pas le séparateur de phénologie (=)";
146
			$this->ajouterLogAnalyse($message);
428 jpm 147
		}
148
	}
149
 
150
	private function verifierNumero($txt) {
151
		if (preg_match('/^<B>[0-9]{1,4}. – /', $txt) == 0) {
436 jpm 152
			$message = "{$this->fichierNum} ne contient pas un numéro bien formaté";
153
			$this->ajouterLogAnalyse($message);
428 jpm 154
		}
155
	}
156
 
157
	private function extraireInfosCorrespondance() {
158
		$donnees = $this->analyserFichier();
159
		$infos = $this->infosCorrespondanceBase;
160
 
161
		$titre = $donnees['titre'];
430 jpm 162
		if (preg_match('/^Coste ([0-9]+) - ((?:(?! - ).)+) - F[0-9]+, (?:(?! - ).)+ - (G[0-9]+), T([123])[.]p([0-9]+)$/', $titre, $match)) {
428 jpm 163
			$infos['num_nom_coste'] = $match[1];
164
			$infos['nom_sci'] = $match[2];
165
			$infos['num_tax_sup_coste'] = $match[3];
166
			$infos['tome'] = $match[4];
167
			$infos['page'] = $match[5];
168
		} else {
169
			$this->messages->traiterErreur("Le titre du fichier {$this->fichierNum} est mal formaté.");
170
		}
171
 
172
		$corres = $donnees['correspondance'];
430 jpm 173
		if (preg_match('/^Bdnff ([0-9]+) - (?:(?! - ).)+ - (?:(?! - ).)+ - Tax=([0-9]+)$/', $corres, $match)) {
428 jpm 174
			$infos['bdnff_nn'] = $match[1];
175
			$infos['bdnff_nt'] = $match[2];
176
		} else {
177
			$this->messages->traiterErreur("La correspondance du fichier {$this->fichierNum} est mal formatée.");
178
		}
179
 
180
		$txt = $donnees['texte'];
181
		$txt = $this->corrigerDescription($txt);
430 jpm 182
		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)) {
183
			$infos['nom_coste'] = trim($match[1]);
184
			$infos['auteur_coste'] = trim($match[2]);
185
			$infos['nom_francais'] = isset($match[3]) ? $match[3] : '';
186
			$infos['nom_francais'] = isset($match[4]) && isset($match[5]) ? $match[4].$match[5] : $infos['nom_francais'];
187
			if (strpos($infos['auteur_coste'], '(' ) !== false) {
188
				if (preg_match('/^([^(]*)\(([^)]+)\)(?:[.]?| ; ((?:(?! – ).)+))$/', $infos['auteur_coste'], $match)) {
437 jpm 189
					$infos['auteur_coste'] = $this->traiterAuteur(trim($match[1]));
190
					$infos['auteur'] = $this->normaliserAuteur($infos['auteur_coste']);
430 jpm 191
					$parentheseContenu = trim($match[2]);
192
					if (preg_match('/^[0-9]+$/', $parentheseContenu)) {
193
						$infos['annee'] = $parentheseContenu;
194
					} else {
195
						$infos['synonymie_coste'] = $parentheseContenu;
196
						$infos['biblio_coste'] = isset($match[3]) ? trim($match[3]) : '';
197
					}
198
				} else {
199
					$this->messages->traiterErreur("L'auteur du nom sciencitifique du fichier {$this->fichierNum} est mal formaté.");
200
				}
201
			}
428 jpm 202
		} else {
203
			$this->messages->traiterErreur("La texte du fichier {$this->fichierNum} est mal formaté.");
204
		}
205
 
206
		$this->correspondance[] = $infos;
430 jpm 207
 
208
		if ($infos['synonymie_coste'] != '') {
209
			$this->traiterSynonymie($infos);
210
		}
428 jpm 211
	}
212
 
437 jpm 213
	private function normaliserAuteur($auteurCoste) {
430 jpm 214
		$auteur = '';
215
		if ($auteurCoste != '') {
437 jpm 216
			$auteur = str_replace(' et ', ' & ', $auteurCoste);
430 jpm 217
		}
218
		return $auteur;
219
	}
220
 
221
	private function traiterSynonymie($infos) {
222
		$synoCoste = $infos['synonymie_coste'];
223
		$synoCoste = preg_replace('/^et /', '', $synoCoste);
437 jpm 224
		$synoCoste = preg_replace('/^(([A-Z][.]|[A-Z]{3,}) [A-Z]{3,}(?:(?! et ).+)) et ([A-Z]{3,}) ((?![A-Z]{3,}).+)$/', '$1 ; $2 $3 $4', $synoCoste);
225
		$synoCoste = preg_replace('/ et ((?:[A-Z][.]|[A-Z]{3,}) [A-Z]{3,})/', ' ; $1', $synoCoste);
435 jpm 226
		$synoCoste = preg_replace('/, ((?:(?!non |part[.]|an |G[.] G[.]|part[.]|centr[.])[^,]+))/', ' ;$1', $synoCoste);
430 jpm 227
 
228
		$synonymes = explode(';', $synoCoste);
229
 
436 jpm 230
		foreach ($synonymes as $num => $syno) {
231
			$synoTraite = $this->traiterNomSyno($syno);
437 jpm 232
			$complementNom = $this->obtenirComplementNom($synoTraite);
233
			$auteurCoste = $this->obtenirAuteur($synoTraite);
234
			$auteur = $this->normaliserAuteur($auteurCoste);
235
			$this->ajouterAuteur($auteur);
236
			$biblioCoste = $this->obtenirBiblio($complementNom);
237
 
430 jpm 238
			$infosSyno = $this->infosCorrespondanceBase;
437 jpm 239
			$infosSyno['nom_sci'] = $this->obtenirNomSci($synoTraite, $infos, $synonymes, $num);
240
			$infosSyno['auteur'] = $auteur;
241
			$infosSyno['biblio_origine'] = $biblioCoste;
242
			$infosSyno['nom_addendum'] =  $this->obtenirNomAddendum($syno);
243
 
436 jpm 244
			$infosSyno['rang'] = $this->obtenirRangSyno($syno);
245
			$infosSyno['nom_coste'] = $synoTraite;
437 jpm 246
			$infosSyno['auteur_coste'] = $auteurCoste;
247
			$infosSyno['biblio_coste'] =  $biblioCoste;
436 jpm 248
			$infosSyno['num_nom_coste'] = $infos['num_nom_coste'].'.'.($num + 1);
249
			$infosSyno['num_nom_retenu_coste'] = $infos['num_nom_coste'];
250
			$this->ajouterLogSyno(implode("\t", $infosSyno));
430 jpm 251
			$this->correspondance[] = $infosSyno;
252
		}
253
	}
437 jpm 254
 
255
	private function traiterNomSyno($syno) {
256
		$syno = $this->nettoyerEspacesNomSyno($syno);
257
		$syno = preg_replace('/^(?:avec|(?:compr|incl)[.]) /', '', $syno);
258
		return $syno;
259
	}
430 jpm 260
 
437 jpm 261
	private function nettoyerEspacesNomSyno($syno) {
262
		$syno = trim($syno);
263
		$syno = trim($syno, ' ');
264
		return $syno;
265
	}
266
 
267
	private function obtenirComplementNom($syno) {
268
		$complementNom = '';
269
		if (preg_match('/^(?:[^ ]+ [^ ]+ (?:var|V)[.] [^ ]+|[^ ]+ [^ ]+) (.+)$/', $syno, $match)) {
270
			$complementNom = $match[1];
271
		}
272
		return $complementNom;
273
	}
274
 
275
	private function obtenirBiblio($complementNom) {
276
		$biblioCoste = '';
277
		if (preg_match("/ (p[.] [0-9]{1,}|in .+||Fl[.] fr[.]|(?: Sp[.])? ed[.] [1-2])$/", $complementNom, $match)) {
278
			$biblioCoste = $match[1];
279
		}
280
		return $biblioCoste;
281
	}
282
 
283
	private function obtenirAuteur($complementNom) {
284
		$auteurCoste = '';
285
		if (preg_match("/^((?!(?:auct.+|(?:, )?(?:non|an) .+|p[.] p[.])$).+)$/", $complementNom, $match)) {
286
			$auteurCoste = $this->traiterAuteur($match[1]);
436 jpm 287
		} else {
437 jpm 288
			$message = "Impossible de récupérer l'auteur pour le complément de nom ($complementNom).";
436 jpm 289
			$this->ajouterLogProbleme($message);
290
		}
437 jpm 291
		return $auteurCoste;
436 jpm 292
	}
293
 
437 jpm 294
	private function traiterAuteur($auteurCoste) {
295
		$auteur = '';
296
		if ($auteurCoste != '') {
297
			$remplacementTxt = array(' p. p.', ' saltem part.', 'Fl. fr.');
298
			$auteurCoste = str_replace($remplacementTxt, '', $auteurCoste);
299
			$remplacementsRegExp = array(
300
				' [0-9]{4}',
301
				' auct.+',
302
				',? part[.]',
303
				' p[.] [0-9]{1,}',
304
				' in .+|,? (?:non|an) .+',
305
				'(?: Sp[.])? ed[.] [1-2]');
306
			$auteur = preg_replace('/(?:'.implode('|', $remplacementsRegExp).')$/', '', $auteurCoste);
307
		}
308
		return $auteur;
309
	}
310
 
436 jpm 311
	private function ajouterAuteur($auteur) {
312
		if (!isset($this->auteurs[$auteur])) {
313
			$this->auteurs[$auteur] = 1;
314
		} else {
315
			$this->auteurs[$auteur]++;
316
		}
317
	}
318
 
319
	private function obtenirNomAddendum($syno) {
437 jpm 320
		$syno = $this->nettoyerEspacesNomSyno($syno);
436 jpm 321
		$nomAddendum = array();
322
		if (preg_match('/^((?:compr|incl)[.]) /', $syno, $match)) {
323
			$nomAddendum[] = '['.$match[1].']';
324
		}
325
		if (preg_match('/ (auct[.] .+)$/', $syno, $match)) {
326
			$nomAddendum[] = '['.$match[1].']';
437 jpm 327
		} else if (preg_match('/,? ((?:non|an) .+)$/', $syno, $match)) {
436 jpm 328
			$nomAddendum[] = '['.$match[1].']';
329
		} else if (preg_match('/ (p[.] p[.])$/', $syno, $match)) {
330
			$nomAddendum[] = '['.$match[1].']';
331
		} else if (preg_match('/ (saltem part[.])$/', $syno, $match)) {
332
			$nomAddendum[] = '['.$match[1].']';
437 jpm 333
		} else if (preg_match('/,? (part[.])$/', $syno, $match)) {
334
			$nomAddendum[] = '['.$match[1].']';
436 jpm 335
		}
336
 
337
		$nomAddendum = implode(' ; ', $nomAddendum);
338
		return $nomAddendum;
339
	}
340
 
341
	private function remplacerAbreviationGenre($syno, $infos, $synonymes, $num) {
342
		$nomSci = $syno;
343
 
344
		if (preg_match('/^(([A-Zƌ])[.]) /', $syno, $matchSyno)) {
345
			if ($matchSyno[2] == substr($infos['nom_coste'], 0, 1)) {
346
				if (preg_match('/^([^ ]+) /', $infos['nom_coste'], $matchNomRetenu)) {
347
					$nomSci = str_replace($matchSyno[1], $matchNomRetenu[1], $syno);
348
				}
349
			} else {
350
				$synoPrecedent = $this->obtenirSynoAvecGenreComplet($synonymes, $num);
351
 
352
				if ($matchSyno[2] == substr($synoPrecedent, 0, 1)) {
353
					if (preg_match('/^([^ ]+) /', $synoPrecedent, $matchSynoPrec)) {
354
						$nomSci = str_replace($matchSyno[1], $matchSynoPrec[1], $syno);
355
					}
356
				} else {
357
					$message = "L'initiale du synonyme ($syno) ne correspondant pas au nom retenu {$infos['num_nom_coste']} ({$infos['nom_coste']}) ".
358
							"ni au synonyme précédent ($synoPrecedent).";
359
					$this->ajouterLogProbleme($message);
360
				}
361
			}
362
		}
363
		return $nomSci;
364
	}
365
 
366
	private function obtenirSynoAvecGenreComplet($synonymes, $num) {
367
		$synoPrecedent = '';
368
		$synoOk = false;
369
		while ($synoOk == false) {
370
			if ($num < 0) {
371
				$synoOk = true;
372
			}
373
			$synoPrecedent = $this->obtenirSynoPrecedent($synonymes, $num);
374
			if (preg_match('/^[A-Zƌ][.] /', $synoPrecedent)) {
375
				$num = $num - 1;
376
			} else {
377
				$synoOk = true;
378
			}
379
		}
380
		return $synoPrecedent;
381
	}
382
 
437 jpm 383
	private function obtenirSynoPrecedent($synonymes, $num) {
384
		$synoPrecedent = '';
385
		if (isset($synonymes[($num - 1 )])) {
386
			$synoPrecedent = $this->traiterNomSyno($synonymes[($num - 1 )]);
387
		}
388
		return $synoPrecedent;
389
	}
390
 
391
 
436 jpm 392
	private function obtenirNomSci($syno, $infos, $synonymes, $num) {
393
		$nomSci = $this->remplacerAbreviationGenre($syno, $infos, $synonymes, $num);
394
 
437 jpm 395
		if (preg_match('/^([^ ]+) ([^ ]+) (?:(?:var|V)[.] ([^ ]+)|(STELATUM) )/', $nomSci, $match)) {
396
			$genre = $this->normaliserGenre($match[1]);
397
			$sp = $this->normaliserEpithete($match[2]);
398
			$infrasp = isset($match[4]) ? $match[4] : $match[3];
399
			$infrasp = $this->normaliserEpithete($infrasp);
436 jpm 400
			$nomSci = "$genre $sp var. $infrasp";
401
		} else if (preg_match('/^([^ ]+) ([^ ]+)(?: |$)/', $nomSci, $match)) {
437 jpm 402
			$genre = $this->normaliserGenre($match[1]);
403
			$sp = $this->normaliserEpithete($match[2]);
436 jpm 404
			$nomSci = "$genre $sp";
405
		} else {
406
			$message = "Le synonyme ($nomSci) du nom {$infos['num_nom_coste']} a une structure étrange.";
407
			$this->ajouterLogProbleme($message);
408
		}
409
		return $nomSci;
410
	}
411
 
437 jpm 412
	private function normaliserGenre($genre) {
413
		$genre = mb_convert_case(mb_strtolower($genre), MB_CASE_TITLE);
414
		$genre = str_replace('Æ', 'æ', $genre);
415
		return $genre;
416
	}
417
 
418
	private function normaliserEpithete($sp) {
419
		$sp = mb_strtolower($sp);
420
		$sp = str_replace('Æ', 'æ', $sp);
421
		return $sp;
422
	}
423
 
436 jpm 424
	private function obtenirRangSyno($syno) {
425
		$rang = 290;
426
		if (strpos($syno, ' var. ')) {
427
			$rang = 340;
428
		}
429
		return $rang;
430
	}
431
 
428 jpm 432
	private function creerFichierCsvCorrespondance() {
433
		$lignes[] = implode("\t", array_keys($this->infosCorrespondanceBase));
434
		foreach ($this->correspondance as $infos) {
435
			$lignes[] = implode("\t", $infos);
436
		}
437
 
438
		$txt = '';
439
		$txt = implode("\n", $lignes);
440
		return $txt;
441
	}
442
 
443
	private function genererFichier() {
444
		$donnees = $this->analyserFichier();
445
 
446
		$txt = $this->nettoyerDescription($donnees['texte']);
447
		$txt = $this->corrigerDescription($txt);
448
		$txt = $this->remplacerHtmlParSyntaxeWiki($txt);
449
		$fichierTxt = $this->dossierBase.self::DOSSIER_DSC_TXT.$this->fichierNum.'.txt';
450
		file_put_contents($fichierTxt, $txt);
451
 
452
		unset($donnees['texte']);
453
		$txt = implode("\n", $donnees);
454
		$fichierTxt = $this->dossierBase.self::DOSSIER_DSC_TXT.$this->fichierNum.'.json';
424 jpm 455
		file_put_contents($fichierTxt, $txt);
456
	}
457
 
428 jpm 458
	private function analyserFichier() {
459
		$donnees = array('titre' => '', 'texte' => '', 'correspondance' => '');
460
		if ($fichierOuvert = fopen($this->fichier, 'r')) {
424 jpm 461
			$i = 1;
462
			while ($ligne = fgets($fichierOuvert)) {
463
				if ($i == 24) {
428 jpm 464
					$donnees['titre'] = $this->supprimerHtml($ligne);
430 jpm 465
				} elseif ($i >= 45 && $i <= 60) {
428 jpm 466
					$donnees['texte'] .= $this->traiterLigneDescription($ligne);
430 jpm 467
				} elseif ($i >= 61 && preg_match('/Bdnff /ui', $ligne)) {
428 jpm 468
					$donnees['correspondance'] = $this->supprimerHtml($ligne);
469
				}
424 jpm 470
				$i++;
471
			}
472
			fclose($fichierOuvert);
473
		} else {
428 jpm 474
			$this->messages->traiterErreur("Le fichier {$this->fichier} n'a pas pu être ouvert.");
424 jpm 475
		}
476
		return $donnees;
477
	}
478
 
428 jpm 479
	private function supprimerHtml($txt) {
480
		$txt = strip_tags($txt,'<b>,<i>');
481
		$txt = str_replace('&#173;', '', $txt);
482
		$txt = str_ireplace('&nbsp;', ' ', $txt);
483
		$txt = trim($txt);
484
		$txt = preg_replace('/^<\/I>/', '', $txt);
485
		$txt = html_entity_decode($txt, ENT_NOQUOTES, 'UTF-8');
486
		return $txt;
424 jpm 487
	}
488
 
428 jpm 489
	private function traiterLigneDescription($txt) {
490
		$txt = $this->supprimerHtml($txt);
491
		$txt = $txt."\n";
492
		return $txt;
493
	}
494
 
495
	private function nettoyerDescription($txt) {
496
		$txt = preg_replace("/\n{2,}+/", "\n", $txt);
424 jpm 497
		$txt = trim($txt);
498
		return $txt;
499
	}
428 jpm 500
 
501
	private function corrigerDescription($txt) {
502
		$txt = preg_replace("/– <I>([^.]+?)[.] – <\/I>/", "– <I>$1</I>. – ", $txt);
503
		$txt = preg_replace("/– <I>([^.]+?)[.] – ([A-Z])<\/I>/", "– <I>$1</I>. – $2", $txt);
504
		$txt = preg_replace("/– <I>([^.]+?) – <\/I>/", "– <I>$1</I>. – ", $txt);
505
		return $txt;
506
	}
507
 
508
	private function remplacerHtmlParSyntaxeWiki($txt) {
509
		$txt = str_replace(array('<B>', '</B>'), '**', $txt);
510
		$txt = str_replace(array('<I>', '</I>'), '//', $txt);
511
		return $txt;
512
	}
436 jpm 513
 
514
	private function ajouterLogAnalyse($txt) {
515
		if (isset($this->log['analyse']) == false) {
516
			$this->log['analyse'] = '';
517
		}
518
		$this->log['analyse'] .= "$txt\n";
519
	}
520
 
521
	private function ajouterLogSyno($txt) {
522
		if (isset($this->log['synonymes']) == false) {
523
			$this->log['synonymes'] = '';
524
		}
525
		$this->log['synonymes'] .= "$txt\n";
526
	}
527
 
528
	private function ajouterLogAuteur($txt) {
529
		if (isset($this->log['auteurs']) == false) {
530
			$this->log['auteurs'] = '';
531
		}
532
		$this->log['auteurs'] .= "$txt\n";
533
	}
534
 
535
	private function ajouterLogProbleme($txt) {
536
		if (isset($this->log['problemes']) == false) {
537
			$this->log['problemes'] = '';
538
		}
539
		$this->log['problemes'] .= "$txt\n";
540
	}
541
 
542
	private function ecrireLogs() {
543
		foreach ($this->log as $nom => $log) {
544
			$fichier = $this->dossierBase.self::DOSSIER_LOG.$nom.'.log';
545
			file_put_contents($fichier, $log);
546
		}
547
	}
424 jpm 548
}
549
?>