Subversion Repositories eFlore/Projets.eflore-projets

Compare Revisions

Ignore whitespace Rev 1044 → Rev 1045

/trunk/scripts/modules/sauvages/sauvages.ini
1,5 → 1,5
version="1"
projet="cles_sauvages.csv"
dossierCsv = "{ref:dossierDonneesEflore}sauvages/1/"
dossierCsv = "{ref:dossierDonneesEflore}sauvages/3/"
chemin_appli = "php:Framework::getCheminAppli()"
 
/trunk/scripts/modules/sauvages/Sauvages.php
82,7 → 82,7
<media>images/pictos/icone_arbre.png</media>
<criteres>';
foreach ($label as $id=>$criteres) {
if ($id > 2) {
if ($id > 3) {
$xml .= '<critere id="1.'.$id.'">
<label>'.$criteres.'</label>
<description>'.$description[$id].'</description>
108,11 → 108,16
$valeurs = array();
foreach ($this->contenu_fichier as $ligne) {
$i = 0;
foreach ($ligne as $critere) {
if (!isset($valeurs[$i]) || !in_array(trim($critere), $valeurs[$i])) {
$valeurs[$i][] = trim($critere);
if ($ligne != "") {
foreach ($ligne as $critere) {
$valeur_multiple = explode("/", $critere);
foreach ($valeur_multiple as $valeur) {
if (!isset($valeurs[$i]) || !in_array(trim($valeur), $valeurs[$i])) {
$valeurs[$i][] = trim($valeur);
}
}
$i++;
}
$i++;
}
}
return $valeurs;
134,28 → 139,54
$xml='<?xml version="1.0" ?><TAXONS SUBJECT="XML">';
$rest = new RestClient();
foreach ($this->contenu_fichier as $id=>$taxon) {
$infos_taxon = $this->rechercherInfosTaxon($rest, $taxon[$criteres_label["nom scientifique"]]);
$xml .= '<TAXON id="'.$id.'" value="'.
ucfirst($taxon[$criteres_label["nom vernaculaire"]]).'" sciName="'.trim($taxon[$criteres_label["nom scientifique"]]).'" groupe="1">
<DESCRIPTION>'.$infos_taxon["description"].'</DESCRIPTION>
<PICTURES>';
if ($infos_taxon["images"] != array()) {
foreach ($infos_taxon["images"] as $image) {
$xml .= '<PICTURE media="'.$image["binaire.href"].'"><author>'.$image["auteur.libelle"].'</author></PICTURE>';
if ($taxon != "") {
$infos_taxon = $this->rechercherInfosTaxon($rest, $taxon[$criteres_label["nom scientifique"]]);
$xml .= '<TAXON id="'.$id.'" value="'.
ucfirst($taxon[$criteres_label["nom vernaculaire"]]).'" sciName="'.trim($taxon[$criteres_label["nom scientifique"]]).'" groupe="1">
<DESCRIPTION>'.$infos_taxon["description"].'</DESCRIPTION>
<PICTURES>';
if ($infos_taxon["images"] != array()) {
if (isset($infos_taxon["images"][$taxon[$criteres_label["image priorite"]]])) {
$auteur = $this->rechercherInfosAuteurImage($infos_taxon["images"][$taxon[$criteres_label["image priorite"]]], $rest).", www.tela-botanica.org, CC-Licence (by-sa)";
$xml .= '<PICTURE media="'.$infos_taxon["images"][$taxon[$criteres_label["image priorite"]]]["binaire.href"].'"><author>'.$auteur.'</author></PICTURE>';
unset($infos_taxon["images"][$taxon[$criteres_label["image priorite"]]]);
}
foreach ($infos_taxon["images"] as $image) {
$auteur = $this->rechercherInfosAuteurImage($image, $rest).", www.tela-botanica.org, CC-Licence (by-sa)";
$xml .= '<PICTURE media="'.$image["binaire.href"].'"><author>'.$auteur.'</author></PICTURE>';
}
}
}
$xml .= '</PICTURES><CRITERIAS>';
for ($i=3; $i < count($taxon); $i++) {
if (trim($taxon[$i]) !== "0") {
$xml .= '<VALUE code="1.'.$i.'.'.array_search(trim($taxon[$i]), $criteres_valeurs[$i]).'"/>';
$xml .= '</PICTURES><CRITERIAS>';
for ($i=4; $i < count($taxon); $i++) {
if (trim($taxon[$i]) !== "0") {
$valeurs = array();
foreach (explode("/",$taxon[$i]) as $valeur) {
$valeurs[] = '1.'.$i.'.'.array_search(trim($valeur), $criteres_valeurs[$i]);
}
$xml .= '<VALUE code="'.implode(',', $valeurs).'"/>';
}
}
$xml .= '</CRITERIAS></TAXON>';
}
$xml .= '</CRITERIAS></TAXON>';
}
$xml .= "</TAXONS>";
return $xml;
}
// interroge l'annuaire pour récupérer le pseudo
private function rechercherInfosAuteurImage($image, $rest) {
$courriel = $image["observation"]["auteur.courriel"];
$url_auteur = "http://www.tela-botanica.org/service:annuaire:utilisateur/identite-par-courriel/".$courriel;
$reponse = $rest->consulter($url_auteur);
$reponse = json_decode($reponse, true);
if (isset($reponse[$courriel]) && $reponse[$courriel]["pseudoUtilise"] == true) {
$auteur = $reponse[$courriel]["pseudo"];
} else{
$auteur = $image["observation"]["auteur.prenom"]." ".$image["observation"]["auteur.nom"];
}
return $auteur;
}
private function rechercherInfosTaxon($rest, $ns) {
$info = array("description" => "", "images" => array());
166,47 → 197,158
$num_taxon = $reponse["resultat"][key($reponse["resultat"])]['num_taxonomique'];
}
$info["description"] = $this->rechercherDescription($num_taxon, $num_nom, $rest);
$info["images"] =array();
$tags = array('fleur', 'feuille', 'rameau', 'port', 'fruit');
$cles = array();
foreach ($tags as $tag) {
$url_image = "http://www.tela-botanica.org/service:del:0.1/images".
"?masque.referentiel=bdtfx&masque.tag={$tag}&tri=votes&ordre=desc&protocole=3&navigation.limite=1&format=CRS&masque.nn=".$num_nom;
$image = $rest->consulter($url_image);
$image = json_decode($image, true);
if ($image["resultats"] !== array()) {
$info["images"][$tag]["binaire.href"] = $image["resultats"][key($image["resultats"])]["binaire.href"];
$info["images"][$tag]["observation"] = $image["resultats"][key($image["resultats"])]["observation"];
$cles[key($image["resultats"])] = "";
}
}
//si image taguée absente
$url_image = "http://www.tela-botanica.org/service:del:0.1/images".
"?masque.referentiel=bdtfx&tri=votes&ordre=desc&protocole=3&navigation.limite=5&format=CRS&masque.nn=".$num_nom;
$reponse = $rest->consulter($url_image);
$reponse = json_decode($reponse, true);
if ($cles !== array()) {
// supprimer les images communes au tag et les mieux notés
$reponse["resultats"] = array_diff_key($reponse["resultats"], $cles);
for ($i = 0; $i < 5-count($cles); $i++) {
$image = array_shift($reponse["resultats"]);
$info["images"][$i]["binaire.href"] = $image["binaire.href"];
$info["images"][$i]["observation"] = $image["observation"];
}
} else {
$info["images"] = $reponse["resultats"];
}
return $info;
}
private function rechercherDescription($num_taxon, $num_nom, $rest) {
$url_wiki = "http://www.tela-botanica.org/wikini/eFloreRedaction/api/rest/0.5/pages/SmartFloreBDTFXnt".
$num_taxon."?txt.format=text/plain&txt.section.titre=Comment%20la%20reconnaître%20%3F";
$num_taxon."?txt.format=text/plain&txt.section.titre=Comment%20la%20reconnaître%20%3F";
$wiki = $rest->consulter($url_wiki); $wiki = json_decode($wiki, true);
if ($wiki['texte'] != ""){
$info["description"] = $this->formaterSmatflore($wiki['texte']);
if ($wiki['texte'] != "" && strstr($wiki['texte'], 'Brève phrase sur son type biologique (simplifié)') === false ){
$description = $this->formaterSmartflore($wiki['texte']);
} else {
$coste = $this->consulterWebService($rest, "coste", "textes", "/bdtfx.nn:".$num_nom);
if ($coste['resultats'] != array() && $coste['resultats'][key($coste["resultats"])]['texte'] != "") {
$texte = str_replace("**", "", $coste['resultats'][key($coste["resultats"])]['texte']);
$texte = str_replace("//", "", $texte);
$texte = explode(" – ", $texte);
unset($texte[0],$texte[1]);
if (strpos($texte[2], ";") === false) {unset($texte[2]);} //else {print_r($texte[2]);}
if (preg_match('/^[\w|\s|\-|,]*\.*\s*$/', $texte[2]) == true) {print_r($texte[2]); unset($texte[2]);}
$info["description"] = implode(" – ", $texte);
$description = $this->formaterCoste($coste['resultats']);
} else {
$baseflor = $this->consulterWebService($rest, "baseflor", "informations", "/bdtfx.nn:".$num_nom);
$info["description"] = $this->formaterBaseflor($baseflor);
$description = $this->formaterBaseflor($baseflor);
}
}
if ($info["description"] == "En cours de rédaction.") {echo $num_nom." ".$ns;
print_r($coste);
}
$reponse = $this->consulterWebService($rest, "cel", "images", "?navigation.limite=5&retour.format=CRS&masque.nn=".$num_nom);
$info["images"] = $reponse["resultats"];
return $info;
return $description;
}
 
private function formaterSmatflore($texte) {
$a_enlever = array(Chr(10).'=', '='.Chr(10), Chr(10).''.Chr(10));
//remplacement des \n par <br />
private function formaterSmartflore($texte) {
$a_enlever = array(Chr(10).'=', '='.Chr(10), Chr(10).''.Chr(10), '*');
$texte = str_replace($a_enlever, '', $texte);
$texte = str_replace(Chr(10), '<br />', $texte);
//supprimer image et lien
$texte = preg_replace('/\[\[http\:\/\/upload.*\.jpg [a-z| |A-Z]*\]\]/', '', $texte);
$texte = str_replace('[[http://fr.wikipedia.org/wiki/Corymbe corymbes]]', 'corymbes', $texte);
$texte = preg_replace('/\[\[SmartFlore.*[0-9] (.*)\]\]/', '\1', $texte);
$texte = preg_replace('/\[\[http\:\/\/www\..* (.*)\]\]/', '\1', $texte);
$texte = trim(str_replace('<br /><br />', '<br />', $texte));
return $texte;
}
private function formaterCoste($coste) {
$texte = $this->mettreEnFormeCoste($coste[key($coste)]['texte']);
return $texte;
}
static function mettreEnFormeCoste($texte) {
$txt_fmt = array();
//decouper elements remarquables avant le texte
self::separerNomScientifique_a_NomCommun($texte, $txt_fmt);
$txt_fmt = array();
$texte = preg_replace('/\//','',$texte);
//decouper elements remarquables après le texte
self::separerEcologie_a_Usages($texte, $txt_fmt);
//le morceau qui reste est le gros de la description
$texte = str_replace(';','</br> -','- '.$texte);
$texte = str_replace('–','',$texte);
$txt_fmt['description'] = $texte;
$retour = "";
foreach ($txt_fmt as $titre=>$parag) {
$parag = preg_replace('/\- \. /','- ',$parag);
$parag = preg_replace('/\. \./','.',$parag);
$retour .= ucfirst($titre)." : ".trim($parag)." ; ";
}
return $retour;
}
static function separerNomScientifique_a_NomCommun(&$txt, &$txt_fmt){
if ( preg_match('/\*\*(.+)\*\*([^–]*)–/', $txt, $retour)){
/* !! attention on enlève un tiret cadratin – pas un trait d'union - !! */
$a_enlever = array('/–/','/\./' );
$txt_fmt['nom_scientifique'] = preg_replace($a_enlever,'',$retour[1]);
if(preg_match('/\((.+)\)/',$retour[2],$synonymes)){
$txt_fmt['synonymes'] = $synonymes[1];
} else {
$txt_fmt['nom_scientifique'] .= $retour[2];
}
$txt = str_replace($retour[0],'',$txt);
}
/* !! attention il y a un espace avant les // du début !! */
if ( preg_match('/^ \/\/([^\/\/]+)\/\//', $txt, $retour)){
$a_enlever = array('/–/','/\./' );
$txt_fmt['nom_commun'] = preg_replace($a_enlever,'',$retour[1]);
$txt = str_replace($retour[0],'',$txt);
}
}
static function separerEcologie_a_Usages(&$txt, &$txt_fmt) {
if (preg_match('/\.\s*([A-ZÉÀÈ].+)$/',$txt, $retour)) {
$txt_fmt['ecologie'] = $retour[1];
$txt = str_replace($retour[0],'.',$txt);
if (isset($txt_fmt['ecologie']) && preg_match('/–(.+)/', $txt_fmt['ecologie'] , $retour)){
$txt_fmt['repartition'] = $retour[1];
$txt_fmt['ecologie'] = str_replace($retour[0],'',$txt_fmt['ecologie']);
}
if (isset($txt_fmt['repartition']) && preg_match('/=(.+)$/', $txt_fmt['repartition'], $retour)){
$txt_fmt['floraison'] = $retour[1];
$txt_fmt['repartition'] = str_replace($retour[0],'',$txt_fmt['repartition']);
$txt_fmt['repartition'] = str_replace(';',',',$txt_fmt['repartition']);
}
if (isset($txt_fmt['floraison']) && preg_match('/–(.+)$|\n(.+)$/',$txt_fmt['floraison'], $retour)){
$txt_fmt['usages'] = isset($retour[1]) ? $retour[1] : $retour[2];
$txt_fmt['floraison'] = str_replace($retour[0],'.',$txt_fmt['floraison']);
}
if (isset($txt_fmt['floraison']) && preg_match('/([Ff]l\.) (.+)/',$txt_fmt['floraison'], $retour)){
$txt_fmt['floraison'] = $retour[2];
$txt_fmt['floraison'] = str_replace($retour[1],'',$txt_fmt['floraison']);
}
if (isset($txt_fmt['floraison']) && preg_match('/([Ff]r\.) (.+)/',$txt_fmt['floraison'], $retour)){
$txt_fmt['fructification'] = $retour[2];
$txt_fmt['floraison'] = str_replace($retour[0],'',$txt_fmt['floraison']);
$txt_fmt['floraison'] = str_replace(',','',$txt_fmt['floraison']);
$txt_fmt['fructification'] = str_replace($retour[1],'',$txt_fmt['fructification']);
$txt_fmt['fructification'] = str_replace('.','',$txt_fmt['fructification']);
}
}
}
private function formaterBaseflor($reponse) {
$description = "En cours de rédaction.";
if ($reponse["nom_sci"] != "") {
if (isset($reponse["nom_sci"]) && $reponse["nom_sci"] != "") {
$description = "Formation végétale : ".$reponse["form_vegetale"]."; ".
"Inflorescence : ".$reponse["inflorescence"]."; ".
"Couleur de la fleur : ".$reponse["couleur_fleur"]."; ".
222,7 → 364,7
}
private function consulterWebService($rest, $projet,$resssource,$parametres) {
$url_id = "http://www.tela-botanica.org/service:eflore:0.1/".$projet."/".$resssource.$parametres;
$url_id = "http://api.tela-botanica.org/service:eflore:0.1/".$projet."/".$resssource.$parametres;
$reponse = $rest->consulter($url_id);
return json_decode($reponse, true);
}