Allow different sub-vocabs of NDP-IKMK for places

This commit is contained in:
Joshua Ramon Enslin 2023-11-30 22:29:25 +01:00
parent c43cc7e42a
commit dcfba67422
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE
2 changed files with 39 additions and 2 deletions

View File

@ -205,7 +205,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
self::moebeltypologie => 'https://term.museum-digital.de/moebel/tag/', self::moebeltypologie => 'https://term.museum-digital.de/moebel/tag/',
self::ndb_adb => 'https://www.deutsche-biographie.de/pnd', self::ndb_adb => 'https://www.deutsche-biographie.de/pnd',
self::ndl => 'https://id.ndl.go.jp/auth/ndlna/', self::ndl => 'https://id.ndl.go.jp/auth/ndlna/',
self::ndp_ikmk => 'https://ikmk.smb.museum/ndp/land/', self::ndp_ikmk => 'https://ikmk.smb.museum/ndp/',
self::ndp_ikmk_persons => 'https://ikmk.smb.museum/ndp/person/', self::ndp_ikmk_persons => 'https://ikmk.smb.museum/ndp/person/',
self::nomisma => 'http://nomisma.org/id/', self::nomisma => 'http://nomisma.org/id/',
self::npg => 'https://www.npg.org.uk/collections/search/person/', self::npg => 'https://www.npg.org.uk/collections/search/person/',
@ -473,6 +473,36 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
} }
/**
* Validates an NDP-IKMK ID. The IKMK vocabularies for places are actually quite
* numerous, identifying places, countries, regions separately.
*
* @param string $id ID to validate.
*
* @return string|false
*/
private static function validateNdpIkmkForPlaces(string $id):string|false {
$id = str_replace("https://ikmk.smb.museum/ndp/", "", trim($id, '/'));
$parts = explode('/', $id);
if (count($parts) !== 2) {
return false;
}
if (!in_array($parts[0], ['ort', 'land', 'region'], true)) {
return false;
}
// There is an issue with this regex
if (self::_is_numeric($parts[1]) === false) {
return false;
}
return $parts[0] . '/' . $parts[1];
}
/** /**
* Validates a PIM ID, returning a string or false. * Validates a PIM ID, returning a string or false.
* *
@ -661,7 +691,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
'http://id.ndl.go.jp/auth/ndlna/', 'http://id.ndl.go.jp/auth/ndlna/',
'https://id.ndl.go.jp/auth/ndlna/', 'https://id.ndl.go.jp/auth/ndlna/',
]), ]),
self::ndp_ikmk => self::validateNumericId($id, ['https://ikmk.smb.museum/ndp/land/']), self::ndp_ikmk => self::validateNdpIkmkForPlaces($id),
self::ndp_ikmk_persons => self::validateNumericId($id, ['https://ikmk.smb.museum/ndp/person/']), self::ndp_ikmk_persons => self::validateNumericId($id, ['https://ikmk.smb.museum/ndp/person/']),
self::nomisma => str_replace('http://nomisma.org/id/', '', $id), self::nomisma => str_replace('http://nomisma.org/id/', '', $id),
self::npg => self::validateNpgId($id), self::npg => self::validateNpgId($id),

View File

@ -69,5 +69,12 @@ final class MDNodaRepositoryTest extends TestCase {
self::assertEquals("2869150688328112660005", MDNodaRepository::viaf->validateId("2869150688328112660005")); self::assertEquals("2869150688328112660005", MDNodaRepository::viaf->validateId("2869150688328112660005"));
self::assertEquals(false, MDNodaRepository::viaf->validateId("2869150688328112;;660005")); self::assertEquals(false, MDNodaRepository::viaf->validateId("2869150688328112;;660005"));
# NDP-IKMK (Places)
self::assertEquals("ort/2847", MDNodaRepository::ndp_ikmk->validateId("https://ikmk.smb.museum/ndp/ort/2847"));
self::assertEquals("land/123", MDNodaRepository::ndp_ikmk->validateId("https://ikmk.smb.museum/ndp/land/123"));
self::assertEquals("region/123", MDNodaRepository::ndp_ikmk->validateId("https://ikmk.smb.museum/ndp/region/123"));
self::assertEquals("land/123", MDNodaRepository::ndp_ikmk->validateId("land/123"));
self::assertEquals(false, MDNodaRepository::ndp_ikmk->validateId("123123"));
} }
} }