Skip to content

Commit

Permalink
fix: change sparql defs and add get_or_create function
Browse files Browse the repository at this point in the history
changes the SPARQL functions to populate only names and lat/long; adds
a `get_or_create_uri` function in the models that calls the create
function if the URI does not exist.
  • Loading branch information
sennierer committed May 27, 2024
1 parent de16e54 commit 15a7343
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 61 deletions.
11 changes: 11 additions & 0 deletions apis_ontology/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.utils.translation import gettext_lazy as _
from multiselectfield import MultiSelectField
import re
from apis_core.utils.helpers import create_object_from_uri


class StatusMixin(models.Model):
Expand Down Expand Up @@ -766,6 +767,11 @@ class Person(PersonNameMixin, DescriptionMixin, StatusMixin, AbstractEntity):
class Meta:
verbose_name_plural = _("personen")

@classmethod
def get_or_create_uri(cls, uri):
print(f"using custom get_or_create_uri with {uri}")
return create_object_from_uri(uri, cls) or cls.objects.get(pk=uri)


class Organisation(
GenericNameMixin,
Expand Down Expand Up @@ -911,6 +917,11 @@ class Place(
verbose_name=_("Datenquelle"),
)

@classmethod
def get_or_create_uri(cls, uri):
print(f"using custom get_or_create_uri with {uri}")
return create_object_from_uri(uri, cls) or cls.objects.get(pk=uri)

class Meta:
verbose_name = _("ort")
verbose_name_plural = _("orte")
Expand Down
40 changes: 1 addition & 39 deletions apis_ontology/rdfimport/PersonFromDNB.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,4 @@ WHERE {
?subject gndo:preferredNameEntityForThePerson/gndo:forename ?first_name .
BIND(?first_name as ?forename)
}
"""
[[attributes]]
# profession
sparql = """
PREFIX gndo: <https://d-nb.info/standards/elementset/gnd#>
SELECT (GROUP_CONCAT(?professionlist) AS ?profession)
WHERE {
?subject gndo:professionOrOccupation ?profession_seq.
?profession_seq ?seq ?professionlist
}
GROUP BY ?subject
"""
[[attributes]]
# date_of_birth
sparql = """
PREFIX gndo: <https://d-nb.info/standards/elementset/gnd#>
SELECT ?start_date_written
WHERE {
?subject gndo:dateOfBirth ?start_date_written .
}
"""
[[attributes]]
# date_of_death
sparql = """
PREFIX gndo: <https://d-nb.info/standards/elementset/gnd#>
SELECT ?end_date_written
WHERE {
?subject gndo:dateOfDeath ?end_date_written .
}
"""
[[attributes]]
# place_of_birth
sparql = """
PREFIX gndo: <https://d-nb.info/standards/elementset/gnd#>
SELECT ?place_of_birth
WHERE {
?subject gndo:placeOfBirth ?place_of_birth
}
"""
"""
37 changes: 15 additions & 22 deletions apis_ontology/rdfimport/PlaceFromGeonames.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,20 @@ regex = "https://sws.geonames.org.*"
#FILTER (LANGMATCHES(LANG(?prefName), "de") || LANGMATCHES(LANG(?prefName), "en") || LANG(?prefName) = "")
sparql = """
PREFIX gn: <http://www.geonames.org/ontology#>
SELECT ?label
WHERE
{
SELECT ?name
WHERE {
OPTIONAL {
?subject gn:name ?gnname_de .
FILTER(LANGMATCHES(LANG(?gnname_de), "de"))
}
OPTIONAL {
?subject gn:officialName ?officialName_de
FILTER(LANGMATCHES(LANG(?officialName_de), "de"))
}
OPTIONAL {
?subject gn:alternateName ?alternateName_de
FILTER(LANGMATCHES(LANG(?alternateName_de), "de"))
}
OPTIONAL {
?subject gn:name ?gnname .
}
Expand All @@ -21,16 +32,7 @@ WHERE
OPTIONAL {
?subject gn:alternateName ?alternateName
}
BIND(COALESCE(?gnname, ?officialName, ?alternateName) AS ?label)
}
"""
[[attributes]]
# kind
sparql = """
PREFIX gn: <http://www.geonames.org/ontology#>
SELECT ?kind
WHERE {
?subject gn:featureCode ?kind
BIND(COALESCE(?gnname_de, ?officialName_de, ?alternateName_de, ?gnname, ?officialName, ?alternateName) AS ?name)
}
"""
[[attributes]]
Expand All @@ -53,12 +55,3 @@ WHERE {
?subject wgs84_pos:long ?longitude
}
"""
[[attributes]]
# parent
sparql = """
PREFIX gn: <http://www.geonames.org/ontology#>
SELECT ?parent
WHERE {
?subject gn:parentCountry ?parent
}
"""

0 comments on commit 15a7343

Please sign in to comment.