7,6 → 7,7 |
const DOSSIER_DSC_TXT = '../../../donnees/coste/descriptions/txt/'; |
const DOSSIER_LOG = 'log/'; |
|
private $atueurs = array(); |
private $dossierBase = ''; |
private $conteneur = null; |
private $outils = null; |
21,10 → 22,11 |
private $correspondance = array(); |
private $infosCorrespondanceBase = array( |
'nom_sci' => '', |
'rang' => 290, |
'auteur' => '', |
'nom_addendum' => '', |
'annee' => '', |
'biblio_coste' => '', |
'rang' => 290, |
'nom_francais' => '', |
'nom_coste' => '', |
'auteur_coste' => '', |
62,14 → 64,13 |
$this->verifierFichier(); |
} |
echo "\n"; |
|
$fichierTxt = $this->dossierBase.self::DOSSIER_LOG.'analyse.log'; |
file_put_contents($fichierTxt, $this->log); |
$this->ecrireLogs(); |
} |
|
public function genererCorrespondance() { |
$this->chargerFichiers(); |
|
|
$this->ajouterLogSyno(implode("\t", array_keys($this->infosCorrespondanceBase))); |
foreach ($this->listeFichiers as $this->fichierNum => $this->fichier) { |
$this->messages->afficherAvancement("Création du fichier de correspondance"); |
$this->extraireInfosCorrespondance(); |
80,8 → 81,7 |
$txtCorrespondance = $this->creerFichierCsvCorrespondance(); |
file_put_contents($fichierTxt, $txtCorrespondance); |
|
$fichierLog = $this->dossierBase.self::DOSSIER_LOG.'synonymes.log'; |
file_put_contents($fichierLog, $this->log); |
$this->ecrireLogs(); |
} |
|
private function chargerFichiers() { |
121,24 → 121,28 |
$b_ouvert = substr_count($txt, '<B>'); |
$b_ferme = substr_count($txt, '</B>'); |
if ($b_ouvert != $b_ferme) { |
$this->log .= "{$this->fichierNum} contient $b_ouvert balises B ouvertes et $b_ferme fermées\n"; |
$message = "{$this->fichierNum} contient $b_ouvert balises B ouvertes et $b_ferme fermées"; |
$this->ajouterLogAnalyse($message); |
} |
$i_ouvert = substr_count($txt, '<I>'); |
$i_ferme = substr_count($txt, '</I>'); |
if ($i_ouvert != $i_ferme) { |
$this->log .= "{$this->fichierNum} contient $i_ouvert balises I ouvertes et $i_ferme fermées\n"; |
$message = "{$this->fichierNum} contient $i_ouvert balises I ouvertes et $i_ferme fermées"; |
$this->ajouterLogAnalyse($message); |
} |
} |
|
private function verifierAbscenceEgale($txt) { |
if (strripos($txt, '=') === false) { |
$this->log .= "{$this->fichierNum} ne contient pas le séparateur de phénologie (=)\n"; |
$message = "{$this->fichierNum} ne contient pas le séparateur de phénologie (=)"; |
$this->ajouterLogAnalyse($message); |
} |
} |
|
private function verifierNumero($txt) { |
if (preg_match('/^<B>[0-9]{1,4}. – /', $txt) == 0) { |
$this->log .= "{$this->fichierNum} ne contient pas un numéro bien formaté\n"; |
$message = "{$this->fichierNum} ne contient pas un numéro bien formaté"; |
$this->ajouterLogAnalyse($message); |
} |
} |
|
214,15 → 218,147 |
|
$synonymes = explode(';', $synoCoste); |
|
foreach ($synonymes as $syno) { |
$syno = trim($syno); |
$syno = trim($syno, ' '); |
foreach ($synonymes as $num => $syno) { |
$synoTraite = $this->traiterNomSyno($syno); |
$infosSyno = $this->infosCorrespondanceBase; |
$this->log .= $infos['num_nom_coste']."\t$syno\n"; |
$infosSyno['rang'] = $this->obtenirRangSyno($syno); |
$infosSyno['nom_sci'] = $this->obtenirNomSci($synoTraite, $infos, $synonymes, $num); |
$infosSyno['nom_coste'] = $synoTraite; |
$infosSyno['auteur'] = $this->obtenirAuteur($synoTraite); |
$infosSyno['nom_addendum'] = $this->obtenirNomAddendum($syno); |
$infosSyno['num_nom_coste'] = $infos['num_nom_coste'].'.'.($num + 1); |
$infosSyno['num_nom_retenu_coste'] = $infos['num_nom_coste']; |
$this->ajouterLogSyno(implode("\t", $infosSyno)); |
$this->correspondance[] = $infosSyno; |
} |
} |
|
private function obtenirAuteur($syno) { |
$auteur = ''; |
$nomSciRE = '(?:[^ ]+ [^ ]+ var. [^ ]+|[^ ]+ [^ ]+)'; |
if (preg_match("/^$nomSciRE ((?!(?:auct.+|, non.+|p[.] p[.])$).+)$/", $syno, $match)) { |
$auteur = $match[1]; |
$auteur = preg_replace('/(?: p[.] p[.]|, non .+|(?: Sp[.])? ed[.] [1-2])$/', '', $auteur); |
$this->ajouterAuteur($auteur); |
} else { |
$message = "Impossible de récupérer l'auteur pour le synonyme ($syno)."; |
$this->ajouterLogProbleme($message); |
} |
return $auteur; |
} |
|
private function ajouterAuteur($auteur) { |
if (!isset($this->auteurs[$auteur])) { |
$this->auteurs[$auteur] = 1; |
$this->ajouterLogAuteur($auteur); |
} else { |
$this->auteurs[$auteur]++; |
} |
} |
|
private function obtenirNomAddendum($syno) { |
$nomAddendum = array(); |
if (preg_match('/^((?:compr|incl)[.]) /', $syno, $match)) { |
$nomAddendum[] = '['.$match[1].']'; |
} |
if (preg_match('/ (auct[.] .+)$/', $syno, $match)) { |
$nomAddendum[] = '['.$match[1].']'; |
} else if (preg_match('/, (non .+)$/', $syno, $match)) { |
$nomAddendum[] = '['.$match[1].']'; |
} else if (preg_match('/ (p[.] p[.])$/', $syno, $match)) { |
$nomAddendum[] = '['.$match[1].']'; |
} else if (preg_match('/ (saltem part[.])$/', $syno, $match)) { |
$nomAddendum[] = '['.$match[1].']'; |
} |
|
$nomAddendum = implode(' ; ', $nomAddendum); |
return $nomAddendum; |
} |
|
private function obtenirSynoPrecedent($synonymes, $num) { |
$synoPrecedent = ''; |
if (isset($synonymes[($num - 1 )])) { |
$synoPrecedent = $this->traiterNomSyno($synonymes[($num - 1 )]); |
} |
return $synoPrecedent; |
} |
|
private function remplacerAbreviationGenre($syno, $infos, $synonymes, $num) { |
$nomSci = $syno; |
|
if (preg_match('/^(([A-Zƌ])[.]) /', $syno, $matchSyno)) { |
if ($matchSyno[2] == substr($infos['nom_coste'], 0, 1)) { |
if (preg_match('/^([^ ]+) /', $infos['nom_coste'], $matchNomRetenu)) { |
$nomSci = str_replace($matchSyno[1], $matchNomRetenu[1], $syno); |
} |
} else { |
$synoPrecedent = $this->obtenirSynoAvecGenreComplet($synonymes, $num); |
|
if ($matchSyno[2] == substr($synoPrecedent, 0, 1)) { |
if (preg_match('/^([^ ]+) /', $synoPrecedent, $matchSynoPrec)) { |
$nomSci = str_replace($matchSyno[1], $matchSynoPrec[1], $syno); |
} |
} else { |
$message = "L'initiale du synonyme ($syno) ne correspondant pas au nom retenu {$infos['num_nom_coste']} ({$infos['nom_coste']}) ". |
"ni au synonyme précédent ($synoPrecedent)."; |
$this->ajouterLogProbleme($message); |
} |
} |
} |
return $nomSci; |
} |
|
private function obtenirSynoAvecGenreComplet($synonymes, $num) { |
$synoPrecedent = ''; |
$synoOk = false; |
while ($synoOk == false) { |
if ($num < 0) { |
$synoOk = true; |
} |
$synoPrecedent = $this->obtenirSynoPrecedent($synonymes, $num); |
if (preg_match('/^[A-Zƌ][.] /', $synoPrecedent)) { |
$num = $num - 1; |
} else { |
$synoOk = true; |
} |
} |
return $synoPrecedent; |
} |
|
private function obtenirNomSci($syno, $infos, $synonymes, $num) { |
$nomSci = $this->remplacerAbreviationGenre($syno, $infos, $synonymes, $num); |
|
if (preg_match('/^([^ ]+) ([^ ]+) var. ([^ ]+)/', $nomSci, $match)) { |
$genre = ucfirst(strtolower($match[1])); |
$sp = strtolower($match[2]); |
$infrasp = strtolower($match[3]); |
$nomSci = "$genre $sp var. $infrasp"; |
} else if (preg_match('/^([^ ]+) ([^ ]+)(?: |$)/', $nomSci, $match)) { |
$genre = ucfirst(strtolower($match[1])); |
$sp = strtolower($match[2]); |
$nomSci = "$genre $sp"; |
} else { |
$message = "Le synonyme ($nomSci) du nom {$infos['num_nom_coste']} a une structure étrange."; |
$this->ajouterLogProbleme($message); |
} |
return $nomSci; |
} |
|
private function obtenirRangSyno($syno) { |
$rang = 290; |
if (strpos($syno, ' var. ')) { |
$rang = 340; |
} |
return $rang; |
} |
|
private function traiterNomSyno($syno) { |
$syno = trim($syno); |
$syno = trim($syno, ' '); |
$syno = preg_replace('/^(?:compr|incl)[.] /', '', $syno); |
return $syno; |
} |
|
private function creerFichierCsvCorrespondance() { |
$lignes[] = implode("\t", array_keys($this->infosCorrespondanceBase)); |
foreach ($this->correspondance as $infos) { |
304,5 → 440,40 |
$txt = str_replace(array('<I>', '</I>'), '//', $txt); |
return $txt; |
} |
|
private function ajouterLogAnalyse($txt) { |
if (isset($this->log['analyse']) == false) { |
$this->log['analyse'] = ''; |
} |
$this->log['analyse'] .= "$txt\n"; |
} |
|
private function ajouterLogSyno($txt) { |
if (isset($this->log['synonymes']) == false) { |
$this->log['synonymes'] = ''; |
} |
$this->log['synonymes'] .= "$txt\n"; |
} |
|
private function ajouterLogAuteur($txt) { |
if (isset($this->log['auteurs']) == false) { |
$this->log['auteurs'] = ''; |
} |
$this->log['auteurs'] .= "$txt\n"; |
} |
|
private function ajouterLogProbleme($txt) { |
if (isset($this->log['problemes']) == false) { |
$this->log['problemes'] = ''; |
} |
$this->log['problemes'] .= "$txt\n"; |
} |
|
private function ecrireLogs() { |
foreach ($this->log as $nom => $log) { |
$fichier = $this->dossierBase.self::DOSSIER_LOG.$nom.'.log'; |
file_put_contents($fichier, $log); |
} |
} |
} |
?> |