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 RDF import for events #375

Merged
merged 1 commit 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
14 changes: 14 additions & 0 deletions apis_ontology/importers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
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 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)
return subj
213 changes: 213 additions & 0 deletions apis_ontology/migrations/0043_fandstattin_versionfandstattin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
# Generated by Django 5.1.3 on 2024-11-25 10:44

import apis_core.generic.abc
import django.db.models.deletion
import simple_history.models
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("apis_ontology", "0042_nobility_wargeburtstitelvon_wurdeerhobenin_and_more"),
("contenttypes", "0002_remove_content_type_name"),
("relations", "0001_initial"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name="FandStattIn",
fields=[
(
"relation_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="relations.relation",
),
),
("start_date", models.DateField(blank=True, editable=False, null=True)),
(
"start_start_date",
models.DateField(blank=True, editable=False, null=True),
),
(
"start_end_date",
models.DateField(blank=True, editable=False, null=True),
),
("end_date", models.DateField(blank=True, editable=False, null=True)),
(
"end_start_date",
models.DateField(blank=True, editable=False, null=True),
),
(
"end_end_date",
models.DateField(blank=True, editable=False, null=True),
),
(
"start_date_written",
models.CharField(
blank=True, max_length=255, null=True, verbose_name="Start"
),
),
(
"end_date_written",
models.CharField(
blank=True, max_length=255, null=True, verbose_name="End"
),
),
(
"review",
models.BooleanField(
default=False,
editable=False,
help_text="Should be set to True, if the data record holds up quality standards.",
),
),
(
"status",
models.CharField(
blank=True, editable=False, max_length=100, null=True
),
),
("references", models.TextField(blank=True, null=True)),
("notes", models.TextField(blank=True, null=True)),
],
options={
"abstract": False,
},
bases=("relations.relation", models.Model),
),
migrations.CreateModel(
name="VersionFandStattIn",
fields=[
(
"relation_ptr",
models.ForeignKey(
auto_created=True,
blank=True,
db_constraint=False,
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
parent_link=True,
related_name="+",
to="relations.relation",
),
),
(
"id",
models.IntegerField(
auto_created=True, blank=True, db_index=True, verbose_name="ID"
),
),
("subj_object_id", models.PositiveIntegerField()),
("obj_object_id", models.PositiveIntegerField()),
("start_date", models.DateField(blank=True, editable=False, null=True)),
(
"start_start_date",
models.DateField(blank=True, editable=False, null=True),
),
(
"start_end_date",
models.DateField(blank=True, editable=False, null=True),
),
("end_date", models.DateField(blank=True, editable=False, null=True)),
(
"end_start_date",
models.DateField(blank=True, editable=False, null=True),
),
(
"end_end_date",
models.DateField(blank=True, editable=False, null=True),
),
(
"start_date_written",
models.CharField(
blank=True, max_length=255, null=True, verbose_name="Start"
),
),
(
"end_date_written",
models.CharField(
blank=True, max_length=255, null=True, verbose_name="End"
),
),
(
"version_tag",
models.CharField(blank=True, max_length=255, null=True),
),
(
"review",
models.BooleanField(
default=False,
editable=False,
help_text="Should be set to True, if the data record holds up quality standards.",
),
),
(
"status",
models.CharField(
blank=True, editable=False, max_length=100, null=True
),
),
("references", models.TextField(blank=True, null=True)),
("notes", models.TextField(blank=True, null=True)),
("history_id", models.AutoField(primary_key=True, serialize=False)),
("history_date", models.DateTimeField(db_index=True)),
("history_change_reason", models.CharField(max_length=100, null=True)),
(
"history_type",
models.CharField(
choices=[("+", "Created"), ("~", "Changed"), ("-", "Deleted")],
max_length=1,
),
),
(
"history_user",
models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to=settings.AUTH_USER_MODEL,
),
),
(
"obj_content_type",
models.ForeignKey(
blank=True,
db_constraint=False,
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="+",
to="contenttypes.contenttype",
),
),
(
"subj_content_type",
models.ForeignKey(
blank=True,
db_constraint=False,
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="+",
to="contenttypes.contenttype",
),
),
],
options={
"verbose_name": "historical fand statt in",
"verbose_name_plural": "historical fand statt ins",
"ordering": ("-history_date", "-history_id"),
"get_latest_by": ("history_date", "history_id"),
},
bases=(
simple_history.models.HistoricalChanges,
models.Model,
apis_core.generic.abc.GenericModel,
),
),
]
13 changes: 13 additions & 0 deletions apis_ontology/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1301,3 +1301,16 @@ def name(self) -> str:
@classmethod
def reverse_name(self) -> str:
return "war Geburtstitel von [PIO]"


class FandStattIn(Relation, VersionMixin, TempTripleGenericAttributes, LegacyDateMixin):
subj_model = Event
obj_model = Place

@classmethod
def name(self) -> str:
return "fand statt in [PIO]"

@classmethod
def reverse_name(self) -> str:
return "war Ort von [PIO]"
35 changes: 35 additions & 0 deletions apis_ontology/rdfimport/EventFromDNB.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#################################################
# Create an Event from GND #
#################################################
superclass = "apis_ontology.models.Event"
regex = "https://d-nb.info.*"
[[attributes]]
# name
sparql = """
PREFIX gndo: <https://d-nb.info/standards/elementset/gnd#>
SELECT ?name
WHERE {
?subject a gndo:HistoricSingleEventOrEra ;
gndo:preferredNameForTheSubjectHeading ?name .
}
"""
[[attributes]]
# start_date_written
sparql = """
PREFIX gndo: <https://d-nb.info/standards/elementset/gnd#>
SELECT ?start_date_written
WHERE {
?subject a gndo:HistoricSingleEventOrEra ;
gndo:dateOfProduction ?start_date_written .
}
"""
[[attributes]]
# related_place
sparql = """
PREFIX gndo: <https://d-nb.info/standards/elementset/gnd#>
SELECT ?related_place
WHERE {
?subject a gndo:HistoricSingleEventOrEra ;
gndo:place ?related_place .
}
"""
Loading