Skip to content

Commit

Permalink
fix: add place of birth for GND
Browse files Browse the repository at this point in the history
resolves #376

Also refactors importer to allow for related entities in a generic way;
adapts events config to that logic
  • Loading branch information
sennierer committed Nov 25, 2024
1 parent 67cde04 commit dc1ef5f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
41 changes: 30 additions & 11 deletions apis_ontology/importers.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
from django.apps import apps
from apis_core.generic.importers import GenericModelImporter
from apis_core.utils.helpers import create_object_from_uri
from apis_ontology.models import FandStattIn, Place


class PersonImporter(GenericModelImporter):
def mangle_data(self, data):
if "profession" in data:
del data["profession"]
return data
class BaseEntityImporter(GenericModelImporter):
"""Importer for all OEBL entities. Allows to define related objects directly in the RDF variable names.
Use `?something__RELATED_OBEJCT_CLASS__RELATION_CLASS` in your variables to auto create relations."""


class EventImporter(GenericModelImporter):
def create_instance(self):
data = self.get_data(drop_unknown_fields=False)
modelfields = [field.name for field in self.model._meta.fields]
data_croped = {key: data[key] for key in data if key in modelfields}
subj = self.model.objects.create(**data_croped)
if "related_place" in data:
place = create_object_from_uri(data["related_place"], Place)
FandStattIn.objects.create(subj=subj, obj=place)
related_keys = [
(x, x.split("__")[1], x.split("__")[2]) for x in data.keys() if "__" in x
]
for rk in related_keys:
key, obj, rel = rk
RelatedModel = apps.get_model("apis_ontology", obj)
RelationType = apps.get_model("apis_ontology", rel)
if key in data:
related_obj = create_object_from_uri(data[key], RelatedModel)
RelationType.objects.create(subj=subj, obj=related_obj)

return subj


class EventImporter(BaseEntityImporter):
pass


class PersonImporter(BaseEntityImporter):
def mangle_data(self, data):
if "profession" in data:
del data["profession"]
return data


class InstitutionImporter(BaseEntityImporter):
pass
4 changes: 2 additions & 2 deletions apis_ontology/rdfimport/EventFromDNB.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ WHERE {
# related_place
sparql = """
PREFIX gndo: <https://d-nb.info/standards/elementset/gnd#>
SELECT ?related_place
SELECT ?relatedPlace__Place__FandStattIn
WHERE {
?subject a gndo:HistoricSingleEventOrEra ;
gndo:place ?related_place .
gndo:place ?relatedPlace__Place__FandStattIn .
}
"""
13 changes: 11 additions & 2 deletions apis_ontology/rdfimport/PersonFromDNB.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,17 @@ WHERE {
# place_of_birth
sparql = """
PREFIX gndo: <https://d-nb.info/standards/elementset/gnd#>
SELECT ?place_of_birth
SELECT ?place_of_birth__Place__WurdeGeborenIn
WHERE {
?subject gndo:placeOfBirth ?place_of_birth
?subject gndo:placeOfBirth ?place_of_birth__Place__WurdeGeborenIn
}
"""
[[attributes]]
# place_of_death
sparql = """
PREFIX gndo: <https://d-nb.info/standards/elementset/gnd#>
SELECT ?place_of_death__Place__StarbIn
WHERE {
?subject gndo:placeOfDeath ?place_of_death__Place__StarbIn
}
"""

0 comments on commit dc1ef5f

Please sign in to comment.