From 72b3e49cdccab3cfbafeabcc2bdefe87a47083a0 Mon Sep 17 00:00:00 2001 From: Mike Bryant Date: Wed, 9 Oct 2024 12:08:08 +0100 Subject: [PATCH] In cases where multiple Wikipedia links exist, try and pick English Otherwise, fall back to the first article --- helpers/TeiEditions_Helpers_DataFetcher.php | 15 ++++++++++++++- package-lock.json | 4 ++-- package.json | 2 +- plugin.ini | 2 +- test/unit/TeiEditions_TeiEnhancerTest.php | 14 ++++++++++++-- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/helpers/TeiEditions_Helpers_DataFetcher.php b/helpers/TeiEditions_Helpers_DataFetcher.php index 13f97cc..5ed9803 100644 --- a/helpers/TeiEditions_Helpers_DataFetcher.php +++ b/helpers/TeiEditions_Helpers_DataFetcher.php @@ -201,7 +201,20 @@ private function _getPlace($url, $lang = null) $lat = @(float)$xpath->query("/rdf:RDF/gn:Feature/wgs84_pos:lat")->item(0)->textContent; $lon = @(float)$xpath->query("/rdf:RDF/gn:Feature/wgs84_pos:long")->item(0)->textContent; - $wiki = @$xpath->query("/rdf:RDF/gn:Feature/gn:wikipediaArticle/@rdf:resource")->item(0)->textContent; + $wikis = $xpath->query("/rdf:RDF/gn:Feature/gn:wikipediaArticle/@rdf:resource"); + // Sigh: try and prefer the English Wikipedia article if one exists, otherwise take the first: + $wiki = null; + if ($wikis->length) { + foreach ($wikis as $w) { + if (preg_match('/en.wikipedia.org\/wiki/', $w->textContent)) { + $wiki = $w->textContent; + break; + } + } + if (!$wiki) { + $wiki = $wikis->item(0)->textContent; + } + } $entity = TeiEditionsEntity::create( $this->_parseGeonamesPlaceName($xpath, $lang), diff --git a/package-lock.json b/package-lock.json index 377d72a..cee496e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "tei-editions", - "version": "1.0.0-pre10", + "version": "1.0.0-pre11", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "tei-editions", - "version": "1.0.0-pre10", + "version": "1.0.0-pre11", "license": "EUPL-1.2", "devDependencies": { "grunt": "^1.5.3", diff --git a/package.json b/package.json index e79e31b..7e3bcd7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "tei-editions", "description": "An Omeka plugin for importing and rendering structured TEI files for EHRI digital editions.", - "version": "1.0.0-pre10", + "version": "1.0.0-pre11", "devDependencies": { "grunt": "^1.5.3", "grunt-cli": "^1.4.3", diff --git a/plugin.ini b/plugin.ini index 3a3b646..2c4195a 100755 --- a/plugin.ini +++ b/plugin.ini @@ -7,4 +7,4 @@ link="https://github.com/EHRI/TeiEditions" support_link="https://github.com/EHRI/TeiEditions/issues" omeka_minimum_version="2.6" omeka_target_version="2.6" -version="1.0.0-pre10" +version="1.0.0-pre11" diff --git a/test/unit/TeiEditions_TeiEnhancerTest.php b/test/unit/TeiEditions_TeiEnhancerTest.php index 67f6971..6e162cc 100644 --- a/test/unit/TeiEditions_TeiEnhancerTest.php +++ b/test/unit/TeiEditions_TeiEnhancerTest.php @@ -24,7 +24,8 @@ public function setUp(): void $this->xpath->registerNamespace("t", TeiEditions_Helpers_DocumentProxy::TEI_NS); } - private function valueOf($path) { + private function valueOf($path) + { $n = $this->xpath->query($path); return $n->length ? $n->item(0)->textContent : ""; } @@ -56,7 +57,7 @@ public function test_addRefs() $this->valueOf("//t:fileDesc/t:sourceDesc/t:listPerson/t:person[1]/t:persName") ); $this->assertRegExp( - "/11\/10\/1902\s+15\/10\/1980/", + "/11\/10\/1902\s+15\/10\/1980/", $this->valueOf("//t:fileDesc/t:sourceDesc/t:listPerson/t:person[1]/t:note/t:p[1]") ); $this->assertEquals( @@ -65,6 +66,15 @@ public function test_addRefs() ); } + public function test_addCorrectWikipediaRefs() + { + $testdata = TeiEditions_Helpers_DocumentProxy::fromUriOrPath( + TEI_EDITIONS_TEST_DIR . "/resources/enhance-tei-2.xml"); + $src = new TeiEditions_Helpers_DataFetcher([], "eng"); + $num = (new TeiEditions_Helpers_TeiEnhancer($src))->addReferences($testdata); + $this->assertEquals(13, $num); + } + public function test_addRefsWithLang() { // TODO: fix this so we can mock the data lookups!