Skip to content

Commit

Permalink
In cases where multiple Wikipedia links exist, try and pick English
Browse files Browse the repository at this point in the history
Otherwise, fall back to the first article
  • Loading branch information
mikesname committed Oct 9, 2024
1 parent 9f711d5 commit 65bb3ae
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
15 changes: 14 additions & 1 deletion helpers/TeiEditions_Helpers_DataFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion plugin.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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"
14 changes: 12 additions & 2 deletions test/unit/TeiEditions_TeiEnhancerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 : "";
}
Expand Down Expand Up @@ -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(
Expand All @@ -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!
Expand Down

0 comments on commit 65bb3ae

Please sign in to comment.