Source code for apis_core.utils.test_rdf

# SPDX-FileCopyrightText: 2023 Birger Schacht
# SPDX-License-Identifier: MIT

from pathlib import Path

from django.test import TestCase

from apis_core.entities.rdfconfigs.group import (
    E74_GroupFromDNB,
)
from apis_core.entities.rdfconfigs.person import (
    E21_PersonFromDNB,
)
from apis_core.entities.rdfconfigs.place import (
    E53_PlaceFromDNB,
    E53_PlaceFromGeonames,
    E53_PlaceFromWikidata,
)
from apis_core.utils import rdf

# use `curl -H "Accept: application/rdf+xml" -L $URI` to fetch data

testdata = Path(__file__).parent / "testdata"
rdf_configs = Path(__file__).parent.parent / "apis_entities/triple_configs"


[docs] class RdfTest(TestCase):
[docs] def test_get_definition_from_dict_place_from_geonames(self): achensee = { "latitude": ["47.5"], "longitude": ["11.7"], "label": ["Achensee"], } # https://www.geonames.org/2783029/achensee.html uri = str(testdata / "achensee.rdf") attributes = rdf.load_uri_using_path(uri, E53_PlaceFromGeonames) self.assertEqual(achensee["latitude"], attributes["latitude"]) self.assertEqual(achensee["longitude"], attributes["longitude"]) self.assertEqual(achensee["label"], attributes["label"])
[docs] def test_get_definition_from_dict_place_from_dnb(self): wien = { "label": ["Wien"], "latitude": ["+048.208199"], "longitude": ["016.371690"], } # https://d-nb.info/gnd/4066009-6 uri = str(testdata / "wien.rdf") attributes = rdf.load_uri_using_path(uri, E53_PlaceFromDNB) self.assertEqual(wien["latitude"], attributes["latitude"]) self.assertEqual(wien["longitude"], attributes["longitude"]) self.assertEqual(wien["label"], attributes["label"])
[docs] def test_get_definition_from_dict_person_from_dnb(self): pierre = { "forename": [ "Pierre", "Pʹer", "Rudolf", "Rodolphe", "...", "Ramus, Pierre", ], "surname": ["Ramus", "Großmann", "Grossmann", "Grossman", "Libertarian"], "alternative_names": [ "Ramus, Pʹer", "Großmann, Rudolf", "Grossmann, Rudolf", "Grossman, Rudolf", "Grossman, Rodolphe", "Grossmann, Rodolphe", "Libertarian, ...", ], "date_of_birth": ["1882-04-15"], "date_of_death": ["1942"], } # https://d-nb.info/gnd/118833197 uri = str(testdata / "ramus.rdf") attributes = rdf.load_uri_using_path(uri, E21_PersonFromDNB) self.assertEqual(pierre["forename"], attributes["forename"]) self.assertEqual(pierre["surname"], attributes["surname"]) # self.assertEqual(pierre["alternative_names"], attributes["alternative_names"]) self.assertEqual(pierre["date_of_birth"], attributes["date_of_birth"]) self.assertEqual(pierre["date_of_death"], attributes["date_of_death"])
[docs] def test_get_definition_from_dict_institution_from_dnb(self): pierre_ges = { "label": [ "Pierre-Ramus-Gesellschaft", "Ramus-Gesellschaft", "Pierre Ramus-Gesellschaft", ], } # https://d-nb.info/gnd/415006-5 uri = str(testdata / "ramus_gesellschaft.rdf") attributes = rdf.load_uri_using_path(uri, E74_GroupFromDNB) self.assertEqual(pierre_ges["label"], attributes["label"])
[docs] def test_get_definition_from_dict_institution_from_dnb2(self): oeaw = { "label": [ "Akademie der Wissenschaften in Wien", "Academy of Sciences in Vienna", "Akademie der Wissenschaften (Wien)", ], } # https://d-nb.info/gnd/35077-1 uri = str(testdata / "oeaw.rdf") attributes = rdf.load_uri_using_path(uri, E74_GroupFromDNB) self.assertEqual(oeaw["label"], attributes["label"])
[docs] def test_dnb_geographic_unit(self): expected = {"label": "Wutai Shan"} # https://d-nb.info/gnd/4241848-3 uri = str(testdata / "wutaishan.rdf") attributes = rdf.load_uri_using_path(uri, E53_PlaceFromDNB) self.assertEqual(len(attributes.get("latitude", [])), 0) self.assertEqual(len(attributes.get("longitude", [])), 0) self.assertIn(expected["label"], attributes["label"])
[docs] def test_wikidata_geographic_unit(self): # https://www.wikidata.org/wiki/Q82601 uri = str(testdata / "tierra_del_fugo.rdf") attributes = rdf.load_uri_using_path(uri, E53_PlaceFromWikidata) self.assertEqual(["-70"], attributes["longitude"]) self.assertEqual(["-54"], attributes["latitude"])
[docs] def test_empty_rdf_file(self): uri = str(testdata / "empty.rdf") attributes = rdf.load_uri_using_path(uri, E53_PlaceFromWikidata) self.assertEqual(attributes, None)
[docs] def test_dnb_MusicalCorporateBody(self): # https://d-nb.info/gnd/2098220-3 uri = str(testdata / "groups/Salzburger_Marionettentheater.ttl") attributes = rdf.load_uri_using_path(uri, E74_GroupFromDNB) label = [ "Salzburger Marionettentheater", "Salzburger Marionettentheater Gesellschaft m.b.H.", "Salzburger Marionettentheater Ges.m.b.H.", "Salzburger Marionettentheater GmbH", "Marionettentheater (Salzburger Marionettentheater)", "Salzburger Marionetten (Körperschaft)", "Aichlers Marionettentheater", "Marionette Theatre Salzburg", "Salzburg Marionette Theatre", "Marionettentheater Salzburg", ] sameas = [ "http://viaf.org/viaf/149602965", "https://isni.org/isni/0000000115374839", "http://www.wikidata.org/entity/Q2215994", "http://id.loc.gov/rwo/agents/n86090792", "https://d-nb.info/gnd/4198684-2", ] self.assertEqual(attributes["label"], label) self.assertEqual(attributes["sameas"], sameas)
[docs] def test_dnb_OrganOfCorporateBody(self): # https://d-nb.info/gnd/4257718-4 uri = str(testdata / "groups/Landgericht_Meran.ttl") attributes = rdf.load_uri_using_path(uri, E74_GroupFromDNB) label = ["Meran. Landgericht Meran"] sameas = ["http://viaf.org/viaf/248639199"] self.assertEqual(attributes["label"], label) self.assertEqual(attributes["sameas"], sameas)