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 . +} +"""