Skip to content

Commit

Permalink
fix: add configs for place import from GND
Browse files Browse the repository at this point in the history
resolves #250
  • Loading branch information
sennierer committed Nov 13, 2024
1 parent 588e396 commit a2255eb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
17 changes: 17 additions & 0 deletions apis_ontology/importers.py
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions apis_ontology/rdfimport/PlaceFromDNB.toml
Original file line number Diff line number Diff line change
@@ -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: <https://d-nb.info/standards/elementset/gnd#>
SELECT ?name
WHERE {
?subject gndo:preferredNameForTheCorporateBody ?name;
}
"""
[[attributes]]
# name
sparql = """
PREFIX gndo: <https://d-nb.info/standards/elementset/gnd#>
SELECT ?name
WHERE {
?subject gndo:preferredNameForThePlaceOrGeographicName ?name;
}
"""
[[attributes]]
# wkt
sparql = """
PREFIX gndo: <https://d-nb.info/standards/elementset/gnd#>
SELECT ?wkt
WHERE {
?subject geo:hasGeometry ?geo .
?geo geo:asWKT ?wkt .
}
"""

0 comments on commit a2255eb

Please sign in to comment.