From a2255ebdf97a2b96081e8b8e8dd0eb4e829a53c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Schl=C3=B6gl?= Date: Wed, 13 Nov 2024 15:13:48 +0100 Subject: [PATCH] fix: add configs for place import from GND resolves #250 --- apis_ontology/importers.py | 17 +++++++++++ apis_ontology/rdfimport/PlaceFromDNB.toml | 35 +++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 apis_ontology/importers.py create mode 100644 apis_ontology/rdfimport/PlaceFromDNB.toml diff --git a/apis_ontology/importers.py b/apis_ontology/importers.py new file mode 100644 index 0000000..bc50d57 --- /dev/null +++ b/apis_ontology/importers.py @@ -0,0 +1,17 @@ +from apis_core.generic.importers import GenericModelImporter + + +class PlaceImporter(GenericModelImporter): + def mangle_data(self, data): + if "wkt" in data: + import re + + # Match coordinates in Point ( longitude latitude ) format + match = re.match( + r"Point\s*\(\s*([-+]?\d+\.\d+)\s+([-+]?\d+\.\d+)\s*\)", data["wkt"] + ) + if match: + data["longitude"] = float(match.group(1)) + data["latitude"] = float(match.group(2)) + del data["wkt"] + return data diff --git a/apis_ontology/rdfimport/PlaceFromDNB.toml b/apis_ontology/rdfimport/PlaceFromDNB.toml new file mode 100644 index 0000000..a25697b --- /dev/null +++ b/apis_ontology/rdfimport/PlaceFromDNB.toml @@ -0,0 +1,35 @@ + +###################################################### +# Create an apis_ontology Person object from an RDF endpoint. +# Source: DNB, https://d-nb.info +###################################################### +superclass = "apis_ontology.models.Place" +regex = "https://d-nb.info.*" +[[attributes]] +# name +sparql = """ +PREFIX gndo: +SELECT ?name +WHERE { + ?subject gndo:preferredNameForTheCorporateBody ?name; +} +""" +[[attributes]] +# name +sparql = """ +PREFIX gndo: +SELECT ?name +WHERE { + ?subject gndo:preferredNameForThePlaceOrGeographicName ?name; +} +""" +[[attributes]] +# wkt +sparql = """ +PREFIX gndo: +SELECT ?wkt +WHERE { + ?subject geo:hasGeometry ?geo . + ?geo geo:asWKT ?wkt . +} +"""