-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add configs for place import from GND
resolves #250
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 . | ||
} | ||
""" |