static function tu_enrichment($id) { global $dbh; $requete = "select tu_databnf_uri from titres_uniformes where tu_id={$id}"; $resultat = pmb_mysql_query($requete, $dbh); if ($resultat && pmb_mysql_num_rows($resultat, $dbh)) { $uri = pmb_mysql_result($resultat, 0, 0, $dbh); } else { $uri = ""; } if ($uri) { $configbnf = array('remote_store_endpoint' => 'http://data.bnf.fr/sparql'); $storebnf = ARC2::getRemoteStore($configbnf); $sparql = "\n\t\t\tPREFIX dc: <http://purl.org/dc/terms/>\n\t\t\tPREFIX rdarelationships: <http://rdvocab.info/RDARelationshipsWEMI/>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\tSELECT min(?gallica) as ?gallica2 ?title ?date ?editeur WHERE {\n\t\t\t ?manifestation rdarelationships:workManifested <" . $uri . ">.\n\t\t\t ?manifestation rdarelationships:electronicReproduction ?gallica.\n\t\t\t ?manifestation dc:title ?title.\n\t\t\t OPTIONAL { ?manifestation dc:date ?date.}\n\t\t\t OPTIONAL { ?manifestation dc:publisher ?editeur.}\n\t\t\t} group by ?title ?date ?editeur"; $ret = false; $rows = $storebnf->query($sparql, 'rows'); // On vérifie qu'il n'y a pas d'erreur sinon on stoppe le programme et on renvoi une chaine vide $err = $storebnf->getErrors(); $tr = array(); if (!$err) { foreach ($rows as $row) { $t = array(); $t["uri_gallica"] = $row["gallica2"]; $t["titre"] = $row["title"]; $t["date"] = $row["date"]; $t["editeur"] = $row["editeur"]; $t["uri_gallica"] = $row["gallica2"]; $tr[] = $t; } } $tr = encoding_normalize::charset_normalize($tr, "utf-8"); //Stockage du tableau $requete = "update titres_uniformes set tu_enrichment='" . addslashes(serialize($tr)) . "', tu_enrichment_last_update=now() where tu_id={$id}"; pmb_mysql_query($requete, $dbh); } }
static function getAutomaticTu($notice) { global $dbh, $charset, $opac_enrichment_bnf_sparql; if (!$opac_enrichment_bnf_sparql) { return 0; } $requete = "select code, responsability_author from notices left join responsability on (responsability_notice={$notice} and responsability_type=0)\n\t\t\tleft join notices_titres_uniformes on notice_id=ntu_num_notice where notice_id={$notice} and ntu_num_notice is null"; $resultat = pmb_mysql_query($requete, $dbh); if (pmb_mysql_num_rows($resultat, $dbh)) { $code = pmb_mysql_result($resultat, 0, 0, $dbh); $id_author = pmb_mysql_result($resultat, 0, 1, $dbh); } else { $code = ""; } $id_tu = 0; if (isISBN($code)) { $uri = titre_uniforme::get_data_bnf_uri($code); if ($uri) { //Recherche du titre uniforme déjà existant ? $requete = "select tu_id from titres_uniformes where tu_databnf_uri='" . addslashes($uri) . "'"; $resultat = pmb_mysql_query($requete, $dbh); if (pmb_mysql_num_rows($resultat, $dbh)) { $id_tu = pmb_mysql_result($resultat, 0, 0, $dbh); } else { //Interrogation de data.bnf pour obtenir les infos ! $configbnf = array('remote_store_endpoint' => 'http://data.bnf.fr/sparql'); $storebnf = ARC2::getRemoteStore($configbnf); $sparql = "\n\t\t\t\t\t\tPREFIX dc: <http://purl.org/dc/terms/>\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\tSELECT ?title ?date ?description WHERE {\n\t\t\t\t\t\t <" . $uri . "> dc:title ?title.\n\t\t\t\t\t\t OPTIONAL { <" . $uri . "> dc:date ?date. }\n\t\t\t\t\t\t OPTIONAL { <" . $uri . "> dc:description ?description. }\n\t\t\t\t\t\t}"; $rows = $storebnf->query($sparql, 'rows'); // On vérifie qu'il n'y a pas d'erreur sinon on stoppe le programme et on renvoi une chaine vide $err = $storebnf->getErrors(); if (!$err) { $value = array("name" => encoding_normalize::charset_normalize($rows[0]['title'], "utf-8"), "num_author" => $id_author, "date" => encoding_normalize::charset_normalize($rows[0]['date'], "utf-8"), "comment" => encoding_normalize::charset_normalize($rows[0]['description'], "utf-8"), "databnf_uri" => $uri); $id_tu = titre_uniforme::import($value); } } } } if ($id_tu) { $titres_uniformes = array(array("num_tu" => $id_tu)); $ntu = new tu_notice($notice); $ntu->update($titres_uniformes); } return $id_tu; }