Simplify NodaWikidataFetcher, unify list of langs, simplify linking to noda sources
Close #2
This commit is contained in:
parent
f0b5a08cdf
commit
1fd87c7e6d
|
@ -12,22 +12,10 @@ declare(strict_types = 1);
|
|||
*/
|
||||
class NodaWikidataFetcher {
|
||||
|
||||
const LANGUAGES_MAIN_DESC = ['da', 'de', 'en', 'es', 'fr', 'hu', 'it', 'nl', 'sv', 'ru', 'zh', 'jp', 'pt'];
|
||||
const LANGUAGES_MAIN_DESC = ['de', 'da', 'en', 'es', 'fr', 'hu', 'it', 'jp', 'nl', 'pt', 'ru', 'sv', 'zh'];
|
||||
const LANGUAGES_TO_CHECK = ['ar', 'bn', 'cs', 'da', 'de', 'el', 'en', 'es', 'fa', 'fi', 'fr', 'ha', 'he', 'hi', 'hu', 'id', 'it', 'ja', 'ka', 'ko', 'nl', 'pl', 'pt', 'ro', 'ru', 'sv', 'sw', 'ta', 'th', 'tl', 'tr', 'ur', 'vi', 'zh'];
|
||||
|
||||
const URL_PREFIXES_PERSINST_NODA_SOURCE = [
|
||||
"gnd_id" => "https://d-nb.info/gnd/",
|
||||
"viaf_id" => "https://viaf.org/viaf/",
|
||||
"bnf_id" => "https://catalogue.bnf.fr/ark:/12148/cb",
|
||||
"ulan_id" => "http://vocab.getty.edu/page/ulan/",
|
||||
"rkd_id" => "https://rkd.nl/explore/artists/",
|
||||
"pim_id" => "https://opac-nevter.pim.hu/en/record/-/record/",
|
||||
"ndl_id" => "https://id.ndl.go.jp/auth/ndlna/",
|
||||
"npg_id" => "https://www.npg.org.uk/collections/search/person/",
|
||||
"loc_id" => "http://id.loc.gov/authorities/names/",
|
||||
"bne_id" => "http://datos.bne.es/persona/",
|
||||
"nomisma_id" => "http://nomisma.org/id/",
|
||||
];
|
||||
const LANGUAGES_TO_CAPITALIZE = ["cs", "da", "de", "en", "es", "fr", "fi", "id", "it", "nl", "pl", "pt", "ru", "sv", "tl", "tr"];
|
||||
|
||||
const URL_PREFIXES_PLACES_NODA_SOURCE = [
|
||||
"gnd" => "https://d-nb.info/gnd/",
|
||||
|
@ -35,6 +23,59 @@ class NodaWikidataFetcher {
|
|||
"osm" => "https://www.openstreetmap.org/relation/",
|
||||
"loc" => "http://id.loc.gov/authorities/names/",
|
||||
"cona" => "http://vocab.getty.edu/page/cona/",
|
||||
"aat" => "http://vocab.getty.edu/page/aat/",
|
||||
"iconclass" => "http://iconclass.org/rkd/",
|
||||
"lcsh" => "http://id.loc.gov/authorities/subjects/",
|
||||
"wikidata" => "https://www.wikidata.org/wiki/",
|
||||
"bne" => "http://datos.bne.es/persona/",
|
||||
"viaf" => "https://viaf.org/viaf/",
|
||||
"bnf" => "https://catalogue.bnf.fr/ark:/12148/cb",
|
||||
"ulan" => "http://vocab.getty.edu/page/ulan/",
|
||||
"rkd" => "https://rkd.nl/explore/artists/",
|
||||
"pim" => "https://opac-nevter.pim.hu/en/record/-/record/",
|
||||
"ndl" => "https://id.ndl.go.jp/auth/ndlna/",
|
||||
"npg" => "https://www.npg.org.uk/collections/search/person/",
|
||||
];
|
||||
|
||||
const P_IDS_NODA_TAGS = [
|
||||
'gnd' => 'P227',
|
||||
'lcsh' => 'P244',
|
||||
'aat' => 'P1014',
|
||||
'iconclass' => 'P1256',
|
||||
'rkd' => 'P650',
|
||||
'osm' => 'P402',
|
||||
'loc' => 'P244',
|
||||
'nomisma' => 'P2950',
|
||||
'cona' => 'P1669',
|
||||
|
||||
"rkd" => "P650",
|
||||
"ulan" => "P245",
|
||||
"viaf" => "P214",
|
||||
"bnf" => "P268",
|
||||
"pim" => "P3973",
|
||||
"ndl" => "P349", // National Diet Library (Japan)
|
||||
"npg" => "P1816", // "National" portrait gallery
|
||||
//"bmpi" => "P6077", // British Museum Person-Institution
|
||||
"bne" => "P950", // Espana National Library
|
||||
];
|
||||
|
||||
const WIKIPEDIA_REMOVE_LITERALS = [
|
||||
"<p>Si vous disposez d'ouvrages ou d'articles de référence ou si vous ",
|
||||
'<p><b>En pratique :</b> <a href="/wiki/Wikip%C3%A9dia:Citez_vos_sources#Qualité_des_sources" title="Wikipédia:Citez vos sources">Quelles sources sont attendu',
|
||||
'<pVous pouvez partager vos connaissances en l’améliorant (',
|
||||
'<p class="mw-empty-elt">',
|
||||
'<p><small>Géolocalisation sur la carte',
|
||||
'<p><b>Koordinaatit:</b>',
|
||||
'<p><span class="executeJS" data-gadgetname="ImgToggle"></span',
|
||||
'<p><span class="imgtoggleboxTitle">',
|
||||
//'<div class="mw-parser-output"><p>',
|
||||
'<p><span style="font-size: small;"><span id="coordinates">',
|
||||
'<p><span></span></p>',
|
||||
'<p><a rel="nofollow" class="external text" href="https://maps.gs',
|
||||
'<p><span class="plainlinks nourlexpansion"><a class="external text" href="//tools.wmflabs.org/geohack/geohack.php?langu',
|
||||
'<p><span style="display:none">',
|
||||
'<p> </p>',
|
||||
'<p><span class="geo noexcerpt"',
|
||||
];
|
||||
|
||||
/** @var MDMysqli */
|
||||
|
@ -155,26 +196,7 @@ class NodaWikidataFetcher {
|
|||
|
||||
$input = str_replace(PHP_EOL, '', $input);
|
||||
|
||||
$stableToRemoveWHTML = [
|
||||
"<p>Si vous disposez d'ouvrages ou d'articles de référence ou si vous ",
|
||||
'<p><b>En pratique :</b> <a href="/wiki/Wikip%C3%A9dia:Citez_vos_sources#Qualité_des_sources" title="Wikipédia:Citez vos sources">Quelles sources sont attendu',
|
||||
'<pVous pouvez partager vos connaissances en l’améliorant (',
|
||||
'<p class="mw-empty-elt">',
|
||||
'<p><small>Géolocalisation sur la carte',
|
||||
'<p><b>Koordinaatit:</b>',
|
||||
'<p><span class="executeJS" data-gadgetname="ImgToggle"></span',
|
||||
'<p><span class="imgtoggleboxTitle">',
|
||||
//'<div class="mw-parser-output"><p>',
|
||||
'<p><span style="font-size: small;"><span id="coordinates">',
|
||||
'<p><span></span></p>',
|
||||
'<p><a rel="nofollow" class="external text" href="https://maps.gs',
|
||||
'<p><span class="plainlinks nourlexpansion"><a class="external text" href="//tools.wmflabs.org/geohack/geohack.php?langu',
|
||||
'<p><span style="display:none">',
|
||||
'<p> </p>',
|
||||
'<p><span class="geo noexcerpt"',
|
||||
];
|
||||
|
||||
foreach ($stableToRemoveWHTML as $tToRemove) $input = str_replace($tToRemove, "", $input);
|
||||
foreach (self::WIKIPEDIA_REMOVE_LITERALS as $tToRemove) $input = str_replace($tToRemove, "", $input);
|
||||
|
||||
$first_mention_of_paragraph = strpos($input, '<p>');
|
||||
if ($first_mention_of_paragraph !== false) $input = substr($input, $first_mention_of_paragraph, (strrpos($input, '</p>') ?: strlen($input)) - $first_mention_of_paragraph);
|
||||
|
@ -271,12 +293,6 @@ class NodaWikidataFetcher {
|
|||
|
||||
$input = str_replace("'", "´", MD_STD::preg_replace_str("/\&\#91\;[0-9]\&\#93\;/", '', $input));
|
||||
|
||||
/*
|
||||
if (strpos($input, " ") !== false) {
|
||||
echo html_entity_decode($input);
|
||||
die();
|
||||
}
|
||||
*/
|
||||
$input = html_entity_decode($input);
|
||||
|
||||
return $input;
|
||||
|
@ -484,8 +500,7 @@ class NodaWikidataFetcher {
|
|||
$wikidata_gender = "other";
|
||||
break;
|
||||
default:
|
||||
echo "Unknown gender: Q-ID is " . $wikidata_gender_id;
|
||||
exit;
|
||||
throw new Exception("Unknown gender: Q-ID is " . $wikidata_gender_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -522,50 +537,13 @@ class NodaWikidataFetcher {
|
|||
}
|
||||
$data = $data['entities'][$wikidata_id];
|
||||
|
||||
// Get links to other norm data sources
|
||||
$normDataSources = [
|
||||
"gnd_id" => "P227",
|
||||
"rkd_id" => "P650",
|
||||
"ulan_id" => "P245",
|
||||
"viaf_id" => "P214",
|
||||
"nomisma_id" => "P2950",
|
||||
"bnf_id" => "P268",
|
||||
"pim_id" => "P3973",
|
||||
"ndl_id" => "P349", // National Diet Library (Japan)
|
||||
"npg_id" => "P1816", // "National" portrait gallery
|
||||
//"bmpi_id" => "P6077", // British Museum Person-Institution
|
||||
"loc_id" => "P244", // National library of Brazil
|
||||
"bne_id" => "P950", // Espana National Library
|
||||
];
|
||||
|
||||
foreach ($normDataSources as $sourceName => $sourceIDWikidata) {
|
||||
if (isset($data['claims'][$sourceIDWikidata])) $$sourceName = $data['claims'][$sourceIDWikidata][0]['mainsnak']['datavalue']['value'];
|
||||
}
|
||||
|
||||
// Get links to wikipedia
|
||||
$wikilink = $wikilinkterm = [];
|
||||
if (isset($data['sitelinks']['dawiki']['url'])) $wikilink['da'] = $data['sitelinks']['dawiki']['url'];
|
||||
if (isset($data['sitelinks']['dawiki']['title'])) $wikilinkterm['da'] = str_replace(' ', '_', $data['sitelinks']['dawiki']['title']);
|
||||
if (isset($data['sitelinks']['dewiki']['url'])) $wikilink['de'] = $data['sitelinks']['dewiki']['url'];
|
||||
if (isset($data['sitelinks']['dewiki']['title'])) $wikilinkterm['de'] = str_replace(' ', '_', $data['sitelinks']['dewiki']['title']);
|
||||
if (isset($data['sitelinks']['enwiki']['url'])) $wikilink['en'] = $data['sitelinks']['enwiki']['url'];
|
||||
if (isset($data['sitelinks']['enwiki']['title'])) $wikilinkterm['en'] = str_replace(' ', '_', $data['sitelinks']['enwiki']['title']);
|
||||
if (isset($data['sitelinks']['eswiki']['url'])) $wikilink['es'] = $data['sitelinks']['eswiki']['url'];
|
||||
if (isset($data['sitelinks']['eswiki']['title'])) $wikilinkterm['es'] = str_replace(' ', '_', $data['sitelinks']['eswiki']['title']);
|
||||
if (isset($data['sitelinks']['frwiki']['url'])) $wikilink['fr'] = $data['sitelinks']['frwiki']['url'];
|
||||
if (isset($data['sitelinks']['frwiki']['title'])) $wikilinkterm['fr'] = str_replace(' ', '_', $data['sitelinks']['frwiki']['title']);
|
||||
if (isset($data['sitelinks']['huwiki']['url'])) $wikilink['hu'] = $data['sitelinks']['huwiki']['url'];
|
||||
if (isset($data['sitelinks']['huwiki']['title'])) $wikilinkterm['hu'] = str_replace(' ', '_', $data['sitelinks']['huwiki']['title']);
|
||||
if (isset($data['sitelinks']['itwiki']['url'])) $wikilink['it'] = $data['sitelinks']['itwiki']['url'];
|
||||
if (isset($data['sitelinks']['itwiki']['title'])) $wikilinkterm['it'] = str_replace(' ', '_', $data['sitelinks']['itwiki']['title']);
|
||||
if (isset($data['sitelinks']['nlwiki']['url'])) $wikilink['nl'] = $data['sitelinks']['nlwiki']['url'];
|
||||
if (isset($data['sitelinks']['nlwiki']['title'])) $wikilinkterm['nl'] = str_replace(' ', '_', $data['sitelinks']['nlwiki']['title']);
|
||||
if (isset($data['sitelinks']['ruwiki']['url'])) $wikilink['ru'] = $data['sitelinks']['ruwiki']['url'];
|
||||
if (isset($data['sitelinks']['ruwiki']['title'])) $wikilinkterm['ru'] = str_replace(' ', '_', $data['sitelinks']['ruwiki']['title']);
|
||||
if (isset($data['sitelinks']['svwiki']['url'])) $wikilink['sv'] = $data['sitelinks']['svwiki']['url'];
|
||||
if (isset($data['sitelinks']['svwiki']['title'])) $wikilinkterm['sv'] = str_replace(' ', '_', $data['sitelinks']['svwiki']['title']);
|
||||
if (isset($data['sitelinks']['zhwiki']['url'])) $wikilink['zh'] = $data['sitelinks']['zhwiki']['url'];
|
||||
if (isset($data['sitelinks']['zhwiki']['title'])) $wikilinkterm['zh'] = str_replace(' ', '_', $data['sitelinks']['zhwiki']['title']);
|
||||
|
||||
foreach (self::LANGUAGES_MAIN_DESC as $tLang) {
|
||||
if (isset($data['sitelinks'][$tLang . 'wiki']['url'])) $wikilink[$tLang] = $data['sitelinks'][$tLang . 'wiki']['url'];
|
||||
if (isset($data['sitelinks'][$tLang . 'wiki']['title'])) $wikilinkterm[$tLang] = str_replace(' ', '_', $data['sitelinks'][$tLang . 'wiki']['title']);
|
||||
}
|
||||
|
||||
$alreadyEntered = false;
|
||||
|
||||
|
@ -598,9 +576,19 @@ class NodaWikidataFetcher {
|
|||
|
||||
$this->enterPersinstBirthDeathDatesFromWikidata($data, $persinst_id);
|
||||
|
||||
// Get links to other norm data sources
|
||||
|
||||
$nodaLinks = [
|
||||
"wikidata" => $wikidata_id,
|
||||
];
|
||||
foreach (self::P_IDS_NODA_TAGS as $vocabName => $pId) {
|
||||
if ($vocabName === 'lcsh') continue;
|
||||
if (isset($data['claims'][$pId])) $nodaLinks[$vocabName] = $data['claims'][$pId][0]['mainsnak']['datavalue']['value'];
|
||||
}
|
||||
|
||||
// GET links to other noda entries.
|
||||
|
||||
$insertNodaRelationsStmt = $this->_mysqli_noda->do_prepare("INSERT INTO `noda`
|
||||
$insertNodaLinkStmt = $this->_mysqli_noda->do_prepare("INSERT INTO `noda`
|
||||
(`persinst_id`, `noda_source`, `noda_nrinsource`, `noda_link`, `noda_erfasst_von`)
|
||||
VALUES
|
||||
(?, ?, ?, ?, ?)
|
||||
|
@ -610,30 +598,21 @@ class NodaWikidataFetcher {
|
|||
|
||||
$this->_mysqli_noda->autocommit(false);
|
||||
|
||||
foreach (self::URL_PREFIXES_PERSINST_NODA_SOURCE as $idVar => $urlStart) {
|
||||
foreach ($nodaLinks as $noda_source => $nodaId) {
|
||||
|
||||
if (empty($$idVar)) continue;
|
||||
|
||||
$tNoda_id = $$idVar;
|
||||
$nameInDB = str_replace("_id", "", $idVar);
|
||||
|
||||
$tNodaurl = $urlStart . $tNoda_id;
|
||||
|
||||
$insertNodaRelationsStmt->bind_param("isssssss", $persinst_id, $nameInDB, $tNoda_id, $tNodaurl, $erfasst_von, $tNoda_id, $tNodaurl, $erfasst_von);
|
||||
$insertNodaRelationsStmt->execute();
|
||||
if (!isset(self::URL_PREFIXES_PLACES_NODA_SOURCE[$noda_source])) {
|
||||
throw new Exception("Unknown noda link: " . $noda_source);
|
||||
}
|
||||
$noda_link_url = self::URL_PREFIXES_PLACES_NODA_SOURCE[$noda_source] . $nodaId;
|
||||
|
||||
$insertNodaLinkStmt->bind_param("isssssss", $persinst_id, $noda_source, $nodaId, $noda_link_url, $erfasst_von, $nodaId, $noda_link_url, $noda_link_url);
|
||||
$insertNodaLinkStmt->execute();
|
||||
}
|
||||
|
||||
$nameInDB = 'wikidata';
|
||||
$wikidataurl = "https://www.wikidata.org/wiki/" . $wikidata_id;
|
||||
|
||||
$insertNodaRelationsStmt->bind_param("isssssss", $persinst_id, $nameInDB, $wikidata_id, $wikidataurl, $erfasst_von, $wikidata_id, $wikidataurl, $erfasst_von);
|
||||
$insertNodaRelationsStmt->execute();
|
||||
|
||||
$this->_mysqli_noda->commit();
|
||||
$this->_mysqli_noda->autocommit(true);
|
||||
|
||||
$insertNodaRelationsStmt->close();
|
||||
$insertNodaLinkStmt->close();
|
||||
|
||||
$this->getWikidataTranslationsForPersinst($data, $persinst_id);
|
||||
|
||||
|
@ -894,13 +873,15 @@ class NodaWikidataFetcher {
|
|||
unset($currentPlaceResult);
|
||||
|
||||
if (isset($data['claims']['P1566'])) $geonames_id = $data['claims']['P1566'][0]['mainsnak']['datavalue']['value'];
|
||||
if (isset($data['claims']['P227'])) $gnd_id = $data['claims']['P227'][0]['mainsnak']['datavalue']['value'];
|
||||
if (isset($data['claims']['P650'])) $rkd_id = $data['claims']['P650'][0]['mainsnak']['datavalue']['value'];
|
||||
if (isset($data['claims']['P1667'])) $tgn_id = $data['claims']['P1667'][0]['mainsnak']['datavalue']['value'];
|
||||
if (isset($data['claims']['P402'])) $osm_id = $data['claims']['P402'][0]['mainsnak']['datavalue']['value'];
|
||||
if (isset($data['claims']['P244'])) $loc_id = $data['claims']['P244'][0]['mainsnak']['datavalue']['value'];
|
||||
if (isset($data['claims']['P2950'])) $nomisma_id = $data['claims']['P2950'][0]['mainsnak']['datavalue']['value'];
|
||||
if (isset($data['claims']['P1669'])) $cona_id = $data['claims']['P1669'][0]['mainsnak']['datavalue']['value'];
|
||||
|
||||
$nodaLinks = [
|
||||
"wikidata" => $wikidata_id,
|
||||
];
|
||||
foreach (self::P_IDS_NODA_TAGS as $vocabName => $pId) {
|
||||
if ($vocabName === 'lcsh') continue;
|
||||
if (isset($data['claims'][$pId])) $nodaLinks[$vocabName] = $data['claims'][$pId][0]['mainsnak']['datavalue']['value'];
|
||||
}
|
||||
|
||||
if (isset($data['claims']['P625'])) {
|
||||
$latitude_wd = $data['claims']['P625'][0]['mainsnak']['datavalue']['value']['latitude'];
|
||||
|
@ -916,38 +897,20 @@ class NodaWikidataFetcher {
|
|||
ON DUPLICATE KEY UPDATE `noda_nrinsource` = ?,
|
||||
`noda_link` = ?");
|
||||
|
||||
foreach (self::URL_PREFIXES_PLACES_NODA_SOURCE as $noda_source => $noda_url_base) {
|
||||
|
||||
if (!empty(${"{$noda_source}_id"})) {
|
||||
|
||||
$noda_link_url = $noda_url_base . ${"{$noda_source}_id"};
|
||||
|
||||
$insertNodaLinkStmt->bind_param("issssss", $onum, $noda_source, ${"{$noda_source}_id"}, $noda_link_url, $erfasst_von, ${"{$noda_source}_id"}, $noda_link_url);
|
||||
$insertNodaLinkStmt->execute();
|
||||
foreach ($nodaLinks as $noda_source => $nodaId) {
|
||||
|
||||
if (!isset(self::URL_PREFIXES_PLACES_NODA_SOURCE[$noda_source])) {
|
||||
throw new Exception("Unknown noda link: " . $noda_source);
|
||||
}
|
||||
$noda_link_url = self::URL_PREFIXES_PLACES_NODA_SOURCE[$noda_source] . $nodaId;
|
||||
|
||||
$insertNodaLinkStmt->bind_param("issssss", $onum, $noda_source, $nodaId, $noda_link_url, $erfasst_von, $nodaId, $noda_link_url);
|
||||
$insertNodaLinkStmt->execute();
|
||||
}
|
||||
|
||||
$insertNodaLinkStmt->close();
|
||||
unset($insertNodaLinkStmt);
|
||||
|
||||
if (!empty($wikidata_id)) {
|
||||
|
||||
$wikidataurl = "https://www.wikidata.org/wiki/" . $wikidata_id;
|
||||
|
||||
$insertStmt = $this->_mysqli_noda->do_prepare("INSERT INTO `noda_orte`
|
||||
(`ort_id`, `noda_source`, `noda_nrinsource`, `noda_link`, `noda_erfasst_von`)
|
||||
VALUES
|
||||
(?, 'wikidata', ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE `noda_nrinsource` = ?,
|
||||
`noda_link` = ?");
|
||||
$insertStmt->bind_param("isssss", $onum, $wikidata_id, $wikidataurl, $erfasst_von, $wikidata_id, $wikidataurl);
|
||||
$insertStmt->execute();
|
||||
$insertStmt->close();
|
||||
unset($insertStmt);
|
||||
}
|
||||
|
||||
if (!empty($tgn_id)) {
|
||||
|
||||
$updateStmt = $this->_mysqli_noda->do_prepare("UPDATE `orte`
|
||||
|
@ -1001,8 +964,6 @@ class NodaWikidataFetcher {
|
|||
|
||||
$checkagainstLanguage = self::LANGUAGES_TO_CHECK;
|
||||
|
||||
$insertStmt = $this->_mysqli_noda->do_prepare("CALL `nodaInsertOrtTranslation`(?, ?, ?, ?, ?)");
|
||||
|
||||
list($languagesToFetch, $wikilinks) = self::getWikidataWikipediaTranslationSources($checkagainstLanguage, $data);
|
||||
|
||||
try {
|
||||
|
@ -1012,6 +973,8 @@ class NodaWikidataFetcher {
|
|||
throw new MDExpectedException("Failed to initialize a request. Try pressing F5 to run the requests again.");
|
||||
}
|
||||
|
||||
$insertStmt = $this->_mysqli_noda->do_prepare("CALL `nodaInsertOrtTranslation`(?, ?, ?, ?, ?)");
|
||||
|
||||
$this->_mysqli_noda->autocommit(false);
|
||||
|
||||
foreach ($checkagainstLanguage as $lang) {
|
||||
|
@ -1196,6 +1159,48 @@ class NodaWikidataFetcher {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes relations to norm data sources to DB.
|
||||
*
|
||||
* @param array<array<string>> $nodaLinks Links to other noda sources.
|
||||
* @param integer $tag_id Tag ID.
|
||||
* @param string $erfasst_von Name of the user to edit this.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function writeNodaLinksTag(array $nodaLinks, int $tag_id, string $erfasst_von):void {
|
||||
|
||||
$this->_mysqli_noda->autocommit(false);
|
||||
|
||||
$insertNodaTagStmt = $this->_mysqli_noda->do_prepare("INSERT INTO `noda_tag`
|
||||
(`tag_id`, `noda_source`, `noda_nrinsource`, `noda_link`, `noda_erfasst_von`)
|
||||
VALUES
|
||||
(?, ?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`noda_nrinsource` = ?,
|
||||
`noda_link` = ?,
|
||||
`noda_erfasst_von` = ?");
|
||||
|
||||
foreach ($nodaLinks as $vocabName => $nodaId) {
|
||||
|
||||
if (empty(self::URL_PREFIXES_PLACES_NODA_SOURCE[$vocabName])) {
|
||||
throw new Exception("Unknown URL prefix for: " . $vocabName);
|
||||
}
|
||||
|
||||
$noda_link = self::URL_PREFIXES_PLACES_NODA_SOURCE[$vocabName] . $nodaId;
|
||||
|
||||
$insertNodaTagStmt->bind_param("isssssss", $tag_id, $vocabName, $nodaId, $noda_link, $erfasst_von, $nodaId, $noda_link, $erfasst_von);
|
||||
$insertNodaTagStmt->execute();
|
||||
}
|
||||
|
||||
$insertNodaTagStmt->close();
|
||||
$insertNodaTagStmt = null;
|
||||
|
||||
$this->_mysqli_noda->commit();
|
||||
$this->_mysqli_noda->autocommit(true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for retrieving information.
|
||||
*
|
||||
|
@ -1216,28 +1221,11 @@ class NodaWikidataFetcher {
|
|||
$data = $data['entities'][$wikidata_id];
|
||||
|
||||
$wikilink = $wikilinkterm = [];
|
||||
if (isset($data['sitelinks']['dawiki']['url'])) $wikilink['da'] = $data['sitelinks']['dawiki']['url'];
|
||||
if (isset($data['sitelinks']['dawiki']['title'])) $wikilinkterm['da'] = str_replace(' ', '_', $data['sitelinks']['dawiki']['title']);
|
||||
if (isset($data['sitelinks']['dewiki']['url'])) $wikilink['de'] = $data['sitelinks']['dewiki']['url'];
|
||||
if (isset($data['sitelinks']['dewiki']['title'])) $wikilinkterm['de'] = str_replace(' ', '_', $data['sitelinks']['dewiki']['title']);
|
||||
if (isset($data['sitelinks']['enwiki']['url'])) $wikilink['en'] = $data['sitelinks']['enwiki']['url'];
|
||||
if (isset($data['sitelinks']['enwiki']['title'])) $wikilinkterm['en'] = str_replace(' ', '_', $data['sitelinks']['enwiki']['title']);
|
||||
if (isset($data['sitelinks']['eswiki']['url'])) $wikilink['es'] = $data['sitelinks']['eswiki']['url'];
|
||||
if (isset($data['sitelinks']['eswiki']['title'])) $wikilinkterm['es'] = str_replace(' ', '_', $data['sitelinks']['eswiki']['title']);
|
||||
if (isset($data['sitelinks']['frwiki']['url'])) $wikilink['fr'] = $data['sitelinks']['frwiki']['url'];
|
||||
if (isset($data['sitelinks']['frwiki']['title'])) $wikilinkterm['fr'] = str_replace(' ', '_', $data['sitelinks']['frwiki']['title']);
|
||||
if (isset($data['sitelinks']['huwiki']['url'])) $wikilink['hu'] = $data['sitelinks']['huwiki']['url'];
|
||||
if (isset($data['sitelinks']['huwiki']['title'])) $wikilinkterm['hu'] = str_replace(' ', '_', $data['sitelinks']['huwiki']['title']);
|
||||
if (isset($data['sitelinks']['itwiki']['url'])) $wikilink['it'] = $data['sitelinks']['itwiki']['url'];
|
||||
if (isset($data['sitelinks']['itwiki']['title'])) $wikilinkterm['it'] = str_replace(' ', '_', $data['sitelinks']['itwiki']['title']);
|
||||
if (isset($data['sitelinks']['nlwiki']['url'])) $wikilink['nl'] = $data['sitelinks']['nlwiki']['url'];
|
||||
if (isset($data['sitelinks']['nlwiki']['title'])) $wikilinkterm['nl'] = str_replace(' ', '_', $data['sitelinks']['nlwiki']['title']);
|
||||
if (isset($data['sitelinks']['ruwiki']['url'])) $wikilink['ru'] = $data['sitelinks']['ruwiki']['url'];
|
||||
if (isset($data['sitelinks']['ruwiki']['title'])) $wikilinkterm['ru'] = str_replace(' ', '_', $data['sitelinks']['ruwiki']['title']);
|
||||
if (isset($data['sitelinks']['svwiki']['url'])) $wikilink['sv'] = $data['sitelinks']['svwiki']['url'];
|
||||
if (isset($data['sitelinks']['svwiki']['title'])) $wikilinkterm['sv'] = str_replace(' ', '_', $data['sitelinks']['svwiki']['title']);
|
||||
if (isset($data['sitelinks']['zhwiki']['url'])) $wikilink['zh'] = $data['sitelinks']['zhwiki']['url'];
|
||||
if (isset($data['sitelinks']['zhwiki']['title'])) $wikilinkterm['zh'] = str_replace(' ', '_', $data['sitelinks']['zhwiki']['title']);
|
||||
|
||||
foreach (self::LANGUAGES_MAIN_DESC as $tLang) {
|
||||
if (isset($data['sitelinks'][$tLang . 'wiki']['url'])) $wikilink[$tLang] = $data['sitelinks'][$tLang . 'wiki']['url'];
|
||||
if (isset($data['sitelinks'][$tLang . 'wiki']['title'])) $wikilinkterm[$tLang] = str_replace(' ', '_', $data['sitelinks'][$tLang . 'wiki']['title']);
|
||||
}
|
||||
|
||||
$alreadyEntered = false;
|
||||
|
||||
|
@ -1268,57 +1256,17 @@ class NodaWikidataFetcher {
|
|||
|
||||
}
|
||||
|
||||
if (isset($data['claims']['P227'])) $gnd_id = $data['claims']['P227'][0]['mainsnak']['datavalue']['value'];
|
||||
if (isset($data['claims']['P244'])) $lcsh_id = $data['claims']['P244'][0]['mainsnak']['datavalue']['value'];
|
||||
if (isset($data['claims']['P1014'])) $aat_id = $data['claims']['P1014'][0]['mainsnak']['datavalue']['value'];
|
||||
if (isset($data['claims']['P1256'])) $iconclass_id = $data['claims']['P1256'][0]['mainsnak']['datavalue']['value'];
|
||||
|
||||
$insertNodaTagLink = function(MDMysqliStmt $insertNodaTagStmt,
|
||||
string $noda_nrinsource, string $noda_source, string $noda_link, string $erfasst_von, int $tag_id) :void {
|
||||
|
||||
$insertNodaTagStmt->bind_param("isssssss", $tag_id, $noda_source, $noda_nrinsource, $noda_link, $erfasst_von, $noda_nrinsource, $noda_link, $erfasst_von);
|
||||
$insertNodaTagStmt->execute();
|
||||
};
|
||||
|
||||
$this->_mysqli_noda->autocommit(false);
|
||||
|
||||
$insertNodaTagStmt = $this->_mysqli_noda->do_prepare("INSERT INTO `noda_tag`
|
||||
(`tag_id`, `noda_source`, `noda_nrinsource`, `noda_link`, `noda_erfasst_von`)
|
||||
VALUES
|
||||
(?, ?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`noda_nrinsource` = ?,
|
||||
`noda_link` = ?,
|
||||
`noda_erfasst_von` = ?");
|
||||
|
||||
if (!empty($gnd_id)) {
|
||||
$insertNodaTagLink($insertNodaTagStmt,
|
||||
$gnd_id, 'gnd', "https://d-nb.info/gnd/" . $gnd_id, $erfasst_von, $tag_id);
|
||||
$nodaLinks = [
|
||||
"wikidata" => $wikidata_id,
|
||||
];
|
||||
foreach (self::P_IDS_NODA_TAGS as $vocabName => $pId) {
|
||||
if ($vocabName === 'loc') continue;
|
||||
if (isset($data['claims'][$pId])) $nodaLinks[$vocabName] = $data['claims'][$pId][0]['mainsnak']['datavalue']['value'];
|
||||
}
|
||||
|
||||
if (!empty($aat_id)) {
|
||||
$insertNodaTagLink($insertNodaTagStmt,
|
||||
$aat_id, 'aat', "http://vocab.getty.edu/page/aat/" . $aat_id, $erfasst_von, $tag_id);
|
||||
}
|
||||
|
||||
if (!empty($iconclass_id)) {
|
||||
$insertNodaTagLink($insertNodaTagStmt,
|
||||
$iconclass_id, 'iconclass', "http://iconclass.org/rkd/{$iconclass_id}/", $erfasst_von, $tag_id);
|
||||
}
|
||||
|
||||
if (!empty($lcsh_id)) {
|
||||
$insertNodaTagLink($insertNodaTagStmt,
|
||||
$lcsh_id, 'lcsh', "http://id.loc.gov/authorities/subjects/" . $lcsh_id, $erfasst_von, $tag_id);
|
||||
}
|
||||
|
||||
$insertNodaTagLink($insertNodaTagStmt,
|
||||
$wikidata_id, 'wikidata', "https://www.wikidata.org/wiki/" . $wikidata_id, $erfasst_von, $tag_id);
|
||||
|
||||
$insertNodaTagStmt->close();
|
||||
|
||||
$this->_mysqli_noda->commit();
|
||||
$this->_mysqli_noda->autocommit(true);
|
||||
$this->writeNodaLinksTag($nodaLinks, $tag_id, $erfasst_von);
|
||||
|
||||
// Get translations
|
||||
if (!empty($data)) $this->getWikidataTranslationsForTag($data, $tag_id);
|
||||
|
||||
}
|
||||
|
@ -1337,8 +1285,6 @@ class NodaWikidataFetcher {
|
|||
|
||||
$insertStmt = $this->_mysqli_noda->do_prepare("CALL nodaInsertTagTranslation(?, ?, ?, ?, ?)");
|
||||
|
||||
$toCapitalize = ["cs", "da", "de", "en", "es", "fr", "fi", "id", "it", "nl", "pl", "pt", "ru", "sv", "tl", "tr"];
|
||||
|
||||
list($languagesToFetch, $wikilinks) = self::getWikidataWikipediaTranslationSources($checkagainstLanguage, $data);
|
||||
|
||||
try {
|
||||
|
@ -1387,7 +1333,7 @@ class NodaWikidataFetcher {
|
|||
$tLang = self::_cleanWikidataInput((string)$data['labels'][$lang]['language']);
|
||||
$tLabel = self::_cleanWikidataInput((string)$data['labels'][$lang]['value']);
|
||||
|
||||
if (in_array($tLang, $toCapitalize, true)) {
|
||||
if (in_array($tLang, self::LANGUAGES_TO_CAPITALIZE, true)) {
|
||||
$tLabel = ucfirst(trim($tLabel));
|
||||
$tDescription = ucfirst(trim($tDescription));
|
||||
}
|
||||
|
@ -1404,7 +1350,7 @@ class NodaWikidataFetcher {
|
|||
|
||||
$wikilink = "";
|
||||
|
||||
if (in_array($lang, $toCapitalize, true)) {
|
||||
if (in_array($lang, self::LANGUAGES_TO_CAPITALIZE, true)) {
|
||||
$data['labels'][$lang]['value'] = ucfirst(trim($data['labels'][$lang]['value']));
|
||||
$data['descriptions'][$lang]['value'] = ucfirst(trim($data['descriptions'][$lang]['value']));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user