Compare commits
No commits in common. "1cf0f9858a2301ef7736e6060184e97e1629dfa9" and "d1cee17ef5d2aa2ca87947c0011b62229b47cf61" have entirely different histories.
1cf0f9858a
...
d1cee17ef5
@ -168,9 +168,8 @@ final class NodaWikidataFetcher {
|
|||||||
*
|
*
|
||||||
* @return array<mixed>
|
* @return array<mixed>
|
||||||
*/
|
*/
|
||||||
public static function getWikidataEntity(string $wikidata_id):array {
|
private static function _getWikidataEntity(string $wikidata_id):array {
|
||||||
|
|
||||||
self::validateWikidataId($wikidata_id);
|
|
||||||
$data = json_decode(MD_STD::runCurl("https://www.wikidata.org/wiki/Special:EntityData/" . urlencode($wikidata_id) . ".json", 10000), true);
|
$data = json_decode(MD_STD::runCurl("https://www.wikidata.org/wiki/Special:EntityData/" . urlencode($wikidata_id) . ".json", 10000), true);
|
||||||
if ($data === null) {
|
if ($data === null) {
|
||||||
throw new MDhttpFailedException("Failed fetching from Wikidata. Try again later.");
|
throw new MDhttpFailedException("Failed fetching from Wikidata. Try again later.");
|
||||||
@ -1065,7 +1064,8 @@ final class NodaWikidataFetcher {
|
|||||||
*/
|
*/
|
||||||
public function retrievePersinstInfoFromWikidataID(string $lang, string $wikidata_id, int $persinst_id, string $erfasst_von) {
|
public function retrievePersinstInfoFromWikidataID(string $lang, string $wikidata_id, int $persinst_id, string $erfasst_von) {
|
||||||
|
|
||||||
$data = self::getWikidataEntity($wikidata_id);
|
self::validateWikidataId($wikidata_id);
|
||||||
|
$data = self::_getWikidataEntity($wikidata_id);
|
||||||
|
|
||||||
// Get links to wikipedia
|
// Get links to wikipedia
|
||||||
|
|
||||||
@ -1115,7 +1115,8 @@ final class NodaWikidataFetcher {
|
|||||||
*/
|
*/
|
||||||
public function retrievePersinstNormDataLinksFromWikidataID(string $wikidata_id, int $persinst_id, string $erfasst_von) {
|
public function retrievePersinstNormDataLinksFromWikidataID(string $wikidata_id, int $persinst_id, string $erfasst_von) {
|
||||||
|
|
||||||
$data = self::getWikidataEntity($wikidata_id);
|
self::validateWikidataId($wikidata_id);
|
||||||
|
$data = self::_getWikidataEntity($wikidata_id);
|
||||||
if (!empty($nodaLinks = $this->_getNodaLinksFromWikidataResult('persinst', $wikidata_id, $data))) {
|
if (!empty($nodaLinks = $this->_getNodaLinksFromWikidataResult('persinst', $wikidata_id, $data))) {
|
||||||
NodaBatchInserter::linkNodaForPersinst($this->_mysqli_noda, $persinst_id, $nodaLinks, $erfasst_von);
|
NodaBatchInserter::linkNodaForPersinst($this->_mysqli_noda, $persinst_id, $nodaLinks, $erfasst_von);
|
||||||
}
|
}
|
||||||
@ -1133,7 +1134,8 @@ final class NodaWikidataFetcher {
|
|||||||
*/
|
*/
|
||||||
public function retrievePlaceNormDataLinksFromWikidataID(string $wikidata_id, int $onum, string $erfasst_von) {
|
public function retrievePlaceNormDataLinksFromWikidataID(string $wikidata_id, int $onum, string $erfasst_von) {
|
||||||
|
|
||||||
$data = self::getWikidataEntity($wikidata_id);
|
self::validateWikidataId($wikidata_id);
|
||||||
|
$data = self::_getWikidataEntity($wikidata_id);
|
||||||
if (!empty($nodaLinks = $this->_getNodaLinksFromWikidataResult('place', $wikidata_id, $data))) {
|
if (!empty($nodaLinks = $this->_getNodaLinksFromWikidataResult('place', $wikidata_id, $data))) {
|
||||||
NodaBatchInserter::linkNodaForPlace($this->_mysqli_noda, $onum, $nodaLinks, $erfasst_von);
|
NodaBatchInserter::linkNodaForPlace($this->_mysqli_noda, $onum, $nodaLinks, $erfasst_von);
|
||||||
}
|
}
|
||||||
@ -1357,7 +1359,8 @@ final class NodaWikidataFetcher {
|
|||||||
*/
|
*/
|
||||||
public function retrievePlaceInfoFromWikidataID(string $lang, string $wikidata_id, int $onum, string $erfasst_von) {
|
public function retrievePlaceInfoFromWikidataID(string $lang, string $wikidata_id, int $onum, string $erfasst_von) {
|
||||||
|
|
||||||
$data = self::getWikidataEntity($wikidata_id);
|
self::validateWikidataId($wikidata_id);
|
||||||
|
$data = self::_getWikidataEntity($wikidata_id);
|
||||||
|
|
||||||
$wikilinks = self::_getWikipediaLinksFromWikidataOutput($data);
|
$wikilinks = self::_getWikipediaLinksFromWikidataOutput($data);
|
||||||
|
|
||||||
@ -1590,7 +1593,8 @@ final class NodaWikidataFetcher {
|
|||||||
*/
|
*/
|
||||||
public function retrieveTagInfoFromWikidataID(string $lang, string $wikidata_id, int $tag_id, string $erfasst_von) {
|
public function retrieveTagInfoFromWikidataID(string $lang, string $wikidata_id, int $tag_id, string $erfasst_von) {
|
||||||
|
|
||||||
$data = self::getWikidataEntity($wikidata_id);
|
self::validateWikidataId($wikidata_id);
|
||||||
|
$data = self::_getWikidataEntity($wikidata_id);
|
||||||
|
|
||||||
$wikilinks = self::_getWikipediaLinksFromWikidataOutput($data);
|
$wikilinks = self::_getWikipediaLinksFromWikidataOutput($data);
|
||||||
|
|
||||||
|
@ -6,27 +6,19 @@
|
|||||||
*/
|
*/
|
||||||
declare(strict_types = 1);
|
declare(strict_types = 1);
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use PHPUnit\Framework\Attributes\CoversClass;
|
|
||||||
use PHPUnit\Framework\Attributes\Medium;
|
|
||||||
use PHPUnit\Framework\Attributes\DataProvider;
|
|
||||||
|
|
||||||
require_once __DIR__ . '/../../MDMysqli/test_connections.conf.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This script contains tests for the Wikidata fetcher.
|
* This script contains tests for the Wikidata fetcher.
|
||||||
|
*
|
||||||
|
* @covers \NodaWikidataFetcher
|
||||||
*/
|
*/
|
||||||
#[medium]
|
|
||||||
#[CoversClass(\NodaWikidataFetcher::class)]
|
|
||||||
final class NodaWikidataFetcherTest extends TestCase {
|
final class NodaWikidataFetcherTest extends TestCase {
|
||||||
|
|
||||||
// Test for getting translations: Telugu
|
|
||||||
private const TEST_LANG = 'te';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test to check whether the HTML page is correctly generated.
|
* Test to check whether the HTML page is correctly generated.
|
||||||
*
|
*
|
||||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||||
* @group ValidOutput
|
* @group ValidOutput
|
||||||
|
* @small
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@ -42,6 +34,7 @@ final class NodaWikidataFetcherTest extends TestCase {
|
|||||||
*
|
*
|
||||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||||
* @group ValidOutput
|
* @group ValidOutput
|
||||||
|
* @small
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@ -54,7 +47,9 @@ final class NodaWikidataFetcherTest extends TestCase {
|
|||||||
/**
|
/**
|
||||||
* Test to check whether the HTML page is correctly generated.
|
* Test to check whether the HTML page is correctly generated.
|
||||||
*
|
*
|
||||||
|
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||||
* @group ValidOutput
|
* @group ValidOutput
|
||||||
|
* @small
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@ -67,7 +62,9 @@ final class NodaWikidataFetcherTest extends TestCase {
|
|||||||
/**
|
/**
|
||||||
* Test for cleaning wikidata info.
|
* Test for cleaning wikidata info.
|
||||||
*
|
*
|
||||||
|
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||||
* @group ValidOutput
|
* @group ValidOutput
|
||||||
|
* @small
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@ -268,7 +265,9 @@ Transclusion expansion time report (%,ms,calls,template)
|
|||||||
/**
|
/**
|
||||||
* Test for cleaning wikidata info.
|
* Test for cleaning wikidata info.
|
||||||
*
|
*
|
||||||
|
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||||
* @group ValidOutput
|
* @group ValidOutput
|
||||||
|
* @small
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@ -282,193 +281,4 @@ Transclusion expansion time report (%,ms,calls,template)
|
|||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Data provider for an actor that has a wikidata link and a Telugu translation.
|
|
||||||
*
|
|
||||||
* @return array<string, array{0: int, 1: string}>
|
|
||||||
*/
|
|
||||||
public static function actorWithTlAndWikidataLinkProvider():array {
|
|
||||||
|
|
||||||
$mysqli = md_main_mysqli_connect();
|
|
||||||
|
|
||||||
$result = $mysqli->do_read_query("SELECT `persinst_id`, `noda_nrinsource`
|
|
||||||
FROM `" . DATABASENAME_NODA . "`.`noda`
|
|
||||||
WHERE `noda_source` = 'Wikidata'
|
|
||||||
AND EXISTS (SELECT 1 FROM `" . DATABASENAME_NODA . "`.`persinst_translation`
|
|
||||||
WHERE `persinst_translation`.`persinst_id` = `noda`.`persinst_id`
|
|
||||||
AND `trans_language` = '" . $mysqli->escape_string(self::TEST_LANG) . "')");
|
|
||||||
|
|
||||||
if (!$cur = $result->fetch_row()) {
|
|
||||||
throw new Exception("Failed to identify an entry that has a wikidata entry and a translation for language " . self::TEST_LANG);
|
|
||||||
}
|
|
||||||
$result->close();
|
|
||||||
$mysqli->close();
|
|
||||||
|
|
||||||
return [
|
|
||||||
'Actor with wikidata and translation' => [$cur[0], $cur[1]],
|
|
||||||
];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data provider for a place that has a wikidata link and a Telugu translation.
|
|
||||||
*
|
|
||||||
* @return array<string, array{0: int, 1: string}>
|
|
||||||
*/
|
|
||||||
public static function placeWithTlAndWikidataLinkProvider():array {
|
|
||||||
|
|
||||||
$mysqli = md_main_mysqli_connect();
|
|
||||||
|
|
||||||
$result = $mysqli->do_read_query("SELECT `ort_id`, `noda_nrinsource`
|
|
||||||
FROM `" . DATABASENAME_NODA . "`.`noda_orte`
|
|
||||||
WHERE `noda_source` = 'Wikidata'
|
|
||||||
AND EXISTS (SELECT 1 FROM `" . DATABASENAME_NODA . "`.`ort_translation`
|
|
||||||
WHERE `ort_translation`.`ort_id` = `noda_orte`.`ort_id`
|
|
||||||
AND `trans_language` = '" . $mysqli->escape_string(self::TEST_LANG) . "')");
|
|
||||||
|
|
||||||
if (!$cur = $result->fetch_row()) {
|
|
||||||
throw new Exception("Failed to identify an entry that has a wikidata entry and a translation for language " . self::TEST_LANG);
|
|
||||||
}
|
|
||||||
$result->close();
|
|
||||||
$mysqli->close();
|
|
||||||
|
|
||||||
return [
|
|
||||||
'Place with wikidata and translation' => [$cur[0], $cur[1]],
|
|
||||||
];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data provider for an tag that has a wikidata link and a Telugu translation.
|
|
||||||
*
|
|
||||||
* @return array<string, array{0: int, 1: string}>
|
|
||||||
*/
|
|
||||||
public static function tagWithTlAndWikidataLinkProvider():array {
|
|
||||||
|
|
||||||
$mysqli = md_main_mysqli_connect();
|
|
||||||
|
|
||||||
$result = $mysqli->do_read_query("SELECT `tag_id`, `noda_nrinsource`
|
|
||||||
FROM `" . DATABASENAME_NODA . "`.`noda_tag`
|
|
||||||
WHERE `noda_source` = 'Wikidata'
|
|
||||||
AND EXISTS (SELECT 1 FROM `" . DATABASENAME_NODA . "`.`tag_translation`
|
|
||||||
WHERE `tag_translation`.`tag_id` = `noda_tag`.`tag_id`
|
|
||||||
AND `trans_language` = '" . $mysqli->escape_string(self::TEST_LANG) . "')");
|
|
||||||
|
|
||||||
if (!$cur = $result->fetch_row()) {
|
|
||||||
throw new Exception("Failed to identify an entry that has a wikidata entry and a translation for language " . self::TEST_LANG);
|
|
||||||
}
|
|
||||||
$result->close();
|
|
||||||
$mysqli->close();
|
|
||||||
|
|
||||||
return [
|
|
||||||
'Tag with wikidata and translation' => [$cur[0], $cur[1]],
|
|
||||||
];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test for fetching and recording translations for an actor.
|
|
||||||
*
|
|
||||||
* @param integer $actor_id Actor ID.
|
|
||||||
* @param string $wikidata_id Wikidata ID.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
#[DataProvider('actorWithTlAndWikidataLinkProvider')]
|
|
||||||
public function testFetchingTranslationForPersinst(int $actor_id, string $wikidata_id):void {
|
|
||||||
|
|
||||||
$mysqli = md_main_mysqli_connect();
|
|
||||||
|
|
||||||
$mysqli->do_update_query("DELETE FROM `" . DATABASENAME_NODA . "`.`persinst_translation`
|
|
||||||
WHERE `persinst_id` = " . $actor_id . "
|
|
||||||
AND `trans_language` = '" . $mysqli->escape_string(self::TEST_LANG) . "'");
|
|
||||||
|
|
||||||
self::assertEquals(0, MDMysqliTesting::queryNumRows($mysqli, "
|
|
||||||
FROM `" . DATABASENAME_NODA . "`.`persinst_translation`
|
|
||||||
WHERE `persinst_id` = " . $actor_id . "
|
|
||||||
AND `trans_language` = '" . $mysqli->escape_string(self::TEST_LANG) . "'"));
|
|
||||||
|
|
||||||
$data = NodaWikidataFetcher::getWikidataEntity($wikidata_id);
|
|
||||||
$fetcher = new NodaWikidataFetcher($mysqli);
|
|
||||||
$fetcher->getWikidataTranslationsForPersinst($data, $actor_id, [self::TEST_LANG]);
|
|
||||||
|
|
||||||
self::assertEquals(1, MDMysqliTesting::queryNumRows($mysqli, "
|
|
||||||
FROM `" . DATABASENAME_NODA . "`.`persinst_translation`
|
|
||||||
WHERE `persinst_id` = " . $actor_id . "
|
|
||||||
AND `trans_language` = '" . $mysqli->escape_string(self::TEST_LANG) . "'"));
|
|
||||||
|
|
||||||
$mysqli->close();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test for fetching and recording translations for an place.
|
|
||||||
*
|
|
||||||
* @param integer $place_id Place ID.
|
|
||||||
* @param string $wikidata_id Wikidata ID.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
#[DataProvider('placeWithTlAndWikidataLinkProvider')]
|
|
||||||
public function testFetchingTranslationForPlace(int $place_id, string $wikidata_id):void {
|
|
||||||
|
|
||||||
$mysqli = md_main_mysqli_connect();
|
|
||||||
|
|
||||||
$mysqli->do_update_query("DELETE FROM `" . DATABASENAME_NODA . "`.`ort_translation`
|
|
||||||
WHERE `ort_id` = " . $place_id . "
|
|
||||||
AND `trans_language` = '" . $mysqli->escape_string(self::TEST_LANG) . "'");
|
|
||||||
|
|
||||||
self::assertEquals(0, MDMysqliTesting::queryNumRows($mysqli, "
|
|
||||||
FROM `" . DATABASENAME_NODA . "`.`ort_translation`
|
|
||||||
WHERE `ort_id` = " . $place_id . "
|
|
||||||
AND `trans_language` = '" . $mysqli->escape_string(self::TEST_LANG) . "'"));
|
|
||||||
|
|
||||||
$data = NodaWikidataFetcher::getWikidataEntity($wikidata_id);
|
|
||||||
$fetcher = new NodaWikidataFetcher($mysqli);
|
|
||||||
$fetcher->getWikidataTranslationsForPlace($data, $place_id, [self::TEST_LANG]);
|
|
||||||
|
|
||||||
self::assertEquals(1, MDMysqliTesting::queryNumRows($mysqli, "
|
|
||||||
FROM `" . DATABASENAME_NODA . "`.`ort_translation`
|
|
||||||
WHERE `ort_id` = " . $place_id . "
|
|
||||||
AND `trans_language` = '" . $mysqli->escape_string(self::TEST_LANG) . "'"));
|
|
||||||
|
|
||||||
$mysqli->close();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test for fetching and recording translations for an tag.
|
|
||||||
*
|
|
||||||
* @param integer $tag_id Tag ID.
|
|
||||||
* @param string $wikidata_id Wikidata ID.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
#[DataProvider('tagWithTlAndWikidataLinkProvider')]
|
|
||||||
public function testFetchingTranslationForTag(int $tag_id, string $wikidata_id):void {
|
|
||||||
|
|
||||||
$mysqli = md_main_mysqli_connect();
|
|
||||||
|
|
||||||
$mysqli->do_update_query("DELETE FROM `" . DATABASENAME_NODA . "`.`tag_translation`
|
|
||||||
WHERE `tag_id` = " . $tag_id . "
|
|
||||||
AND `trans_language` = '" . $mysqli->escape_string(self::TEST_LANG) . "'");
|
|
||||||
|
|
||||||
self::assertEquals(0, MDMysqliTesting::queryNumRows($mysqli, "
|
|
||||||
FROM `" . DATABASENAME_NODA . "`.`tag_translation`
|
|
||||||
WHERE `tag_id` = " . $tag_id . "
|
|
||||||
AND `trans_language` = '" . $mysqli->escape_string(self::TEST_LANG) . "'"));
|
|
||||||
|
|
||||||
$data = NodaWikidataFetcher::getWikidataEntity($wikidata_id);
|
|
||||||
$fetcher = new NodaWikidataFetcher($mysqli);
|
|
||||||
$fetcher->getWikidataTranslationsForTag($data, $tag_id, [self::TEST_LANG]);
|
|
||||||
|
|
||||||
self::assertEquals(1, MDMysqliTesting::queryNumRows($mysqli, "
|
|
||||||
FROM `" . DATABASENAME_NODA . "`.`tag_translation`
|
|
||||||
WHERE `tag_id` = " . $tag_id . "
|
|
||||||
AND `trans_language` = '" . $mysqli->escape_string(self::TEST_LANG) . "'"));
|
|
||||||
|
|
||||||
$mysqli->close();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user