Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In cases where multiple Wikipedia links exist, try and pick English #48

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading