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

fix: add place of birth for GND #379

Merged
merged 2 commits into from
Nov 25, 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
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
24 changes: 22 additions & 2 deletions apis_ontology/rdfimport/EventFromDNB.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ WHERE {
}
"""
[[attributes]]
# name
sparql = """
PREFIX gndo: <https://d-nb.info/standards/elementset/gnd#>
SELECT ?name
WHERE {
?subject a gndo:ConferenceOrEvent ;
gndo:preferredNameForTheConferenceOrEvent ?name .
}
"""
[[attributes]]
# start_date_written
sparql = """
PREFIX gndo: <https://d-nb.info/standards/elementset/gnd#>
Expand All @@ -24,12 +34,22 @@ WHERE {
}
"""
[[attributes]]
# start_date_written
sparql = """
PREFIX gndo: <https://d-nb.info/standards/elementset/gnd#>
SELECT ?start_date_written
WHERE {
?subject a gndo:ConferenceOrEvent ;
gndo:dateOfConferenceOrEvent ?start_date_written .
}
"""
[[attributes]]
# 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
}
"""
Loading