23,12 → 23,17 |
'nom_sci' => '', |
'rang' => 290, |
'auteur' => '', |
'annee' => '', |
'biblio_coste' => '', |
'nom_francais' => '', |
'nom_coste' => '', |
'auteur_coste' => '', |
'num_nom_coste' => '', |
'num_nom_retenu_coste' => '', |
'num_tax_sup_coste' => '', |
'tome' => '', |
'page' => '', |
'synonymie_coste' => '', |
'bdnff_nn' => '', |
'bdnff_nt' => ''); |
|
73,7 → 78,10 |
|
$fichierTxt = $this->dossierBase.self::DOSSIER_V0.'index_general_sp.tsv'; |
$txtCorrespondance = $this->creerFichierCsvCorrespondance(); |
file_put_contents($fichierTxt, $txtCorrespondance); |
file_put_contents($fichierTxt, $txtCorrespondance); |
|
$fichierLog = $this->dossierBase.self::DOSSIER_LOG.'synonymes.log'; |
file_put_contents($fichierLog, $this->log); |
} |
|
private function chargerFichiers() { |
97,7 → 105,7 |
$this->messages->traiterErreur("Le dossier {$this->nomDossier} est introuvable."); |
} |
|
asort($this->listeFichiers); |
arsort($this->listeFichiers); |
} |
|
private function verifierFichier() { |
106,6 → 114,7 |
$this->verifierOuvertureFermetureBalise($txt); |
$this->verifierAbscenceEgale($txt); |
$this->verifierNumero($txt); |
// TODO : vérifier les noms vernauclaire qui sont abrégés |
} |
|
private function verifierOuvertureFermetureBalise($txt) { |
138,7 → 147,7 |
$infos = $this->infosCorrespondanceBase; |
|
$titre = $donnees['titre']; |
if (preg_match('/^Coste ([0-9]+) - ([^ ]+ [^ ]+) - F[0-9]+, [^ ]+ - (G[0-9]+), T([123])[.]p([0-9]+)$/', $titre, $match)) { |
if (preg_match('/^Coste ([0-9]+) - ((?:(?! - ).)+) - F[0-9]+, (?:(?! - ).)+ - (G[0-9]+), T([123])[.]p([0-9]+)$/', $titre, $match)) { |
$infos['num_nom_coste'] = $match[1]; |
$infos['nom_sci'] = $match[2]; |
$infos['num_tax_sup_coste'] = $match[3]; |
149,10 → 158,9 |
} |
|
$corres = $donnees['correspondance']; |
if (preg_match('/^Bdnff ([0-9]+) -[^-]+-[^-]+- Tax=([0-9]+)$/', $corres, $match)) { |
if (preg_match('/^Bdnff ([0-9]+) - (?:(?! - ).)+ - (?:(?! - ).)+ - Tax=([0-9]+)$/', $corres, $match)) { |
$infos['bdnff_nn'] = $match[1]; |
$infos['bdnff_nt'] = $match[2]; |
|
} else { |
$this->messages->traiterErreur("La correspondance du fichier {$this->fichierNum} est mal formatée."); |
} |
159,17 → 167,62 |
|
$txt = $donnees['texte']; |
$txt = $this->corrigerDescription($txt); |
if (preg_match('/^<B>[0-9]{1,4}[.] – ([^<]+)<\/B> ([^–]+)– (?:<I>([^<]+)<\/I>|[A-Z])/u', $txt, $match)) { |
$infos['nom_coste'] = $match[1]; |
$infos['auteur'] = $match[2]; |
$infos['nom_francais'] = isset($match[3]) ? $match[3] : ''; |
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)) { |
$infos['nom_coste'] = trim($match[1]); |
$infos['auteur_coste'] = trim($match[2]); |
$infos['nom_francais'] = isset($match[3]) ? $match[3] : ''; |
$infos['nom_francais'] = isset($match[4]) && isset($match[5]) ? $match[4].$match[5] : $infos['nom_francais']; |
if (strpos($infos['auteur_coste'], '(' ) !== false) { |
if (preg_match('/^([^(]*)\(([^)]+)\)(?:[.]?| ; ((?:(?! – ).)+))$/', $infos['auteur_coste'], $match)) { |
$infos['auteur_coste'] = trim($match[1]); |
$infos['auteur'] = $this->traiterAuteur($infos['auteur_coste']); |
$parentheseContenu = trim($match[2]); |
if (preg_match('/^[0-9]+$/', $parentheseContenu)) { |
$infos['annee'] = $parentheseContenu; |
} else { |
$infos['synonymie_coste'] = $parentheseContenu; |
$infos['biblio_coste'] = isset($match[3]) ? trim($match[3]) : ''; |
} |
} else { |
$this->messages->traiterErreur("L'auteur du nom sciencitifique du fichier {$this->fichierNum} est mal formaté."); |
} |
} |
} else { |
$this->messages->traiterErreur("La texte du fichier {$this->fichierNum} est mal formaté."); |
} |
|
$this->correspondance[] = $infos; |
|
if ($infos['synonymie_coste'] != '') { |
$this->traiterSynonymie($infos); |
} |
} |
|
private function traiterAuteur($auteurCoste) { |
$auteur = ''; |
if ($auteurCoste != '') { |
$auteur = str_replace('et', '&', $auteurCoste); |
} |
return $auteur; |
} |
|
private function traiterSynonymie($infos) { |
$synoCoste = $infos['synonymie_coste']; |
$synoCoste = preg_replace('/^et /', '', $synoCoste); |
$synoCoste = preg_replace('/ et ([A-Z]{2,}|[A-Z][.] [A-Z]{2,})/', ' ; $1', $synoCoste); |
$synoCoste = preg_replace('/, ((?:(?!non |part[.]|an |G[.] G[.])[^,]+))/', ' ;$1', $synoCoste); |
|
$synonymes = explode(';', $synoCoste); |
|
foreach ($synonymes as $syno) { |
$syno = trim($syno); |
$syno = trim($syno, ' '); |
$infosSyno = $this->infosCorrespondanceBase; |
$this->log .= $infos['num_nom_coste']."\t$syno\n"; |
$this->correspondance[] = $infosSyno; |
} |
} |
|
private function creerFichierCsvCorrespondance() { |
$lignes[] = implode("\t", array_keys($this->infosCorrespondanceBase)); |
foreach ($this->correspondance as $infos) { |
203,16 → 256,13 |
while ($ligne = fgets($fichierOuvert)) { |
if ($i == 24) { |
$donnees['titre'] = $this->supprimerHtml($ligne); |
} elseif ($i >= 45 && $i <= 62) { |
} elseif ($i >= 45 && $i <= 60) { |
$donnees['texte'] .= $this->traiterLigneDescription($ligne); |
} elseif (($i == 63 || $i == 67) && preg_match('/Bdnff /ui', $ligne)) { |
} elseif ($i >= 61 && preg_match('/Bdnff /ui', $ligne)) { |
$donnees['correspondance'] = $this->supprimerHtml($ligne); |
} |
$i++; |
} |
if ($i > 94) { |
$this->messages->traiterErreur("Le fichier {$this->fichier} contient plus de 94 lignes ($i)."); |
} |
fclose($fichierOuvert); |
} else { |
$this->messages->traiterErreur("Le fichier {$this->fichier} n'a pas pu être ouvert."); |