Skip to content

Commit

Permalink
feat(apis_entities): import improvements for E53_Place imports
Browse files Browse the repository at this point in the history
  • Loading branch information
b1rger committed Apr 2, 2024
1 parent 72234cd commit 4eedfe9
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 26 deletions.
9 changes: 4 additions & 5 deletions apis_core/apis_entities/rdfimport/E53_PlaceFromDNB.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#####################################################
# Create an E53_Place from a d-nb.info RDF endpoint #
#####################################################
superclass = "apis_core.apis_entities.abc.E53_Place"
superclass = "apis_core.apis_entities.abc.Place"
# the second regex is for testing
regex = "https://d-nb.info.*|/.*wien.rdf"
[[attributes]]
Expand All @@ -10,12 +10,11 @@ sparql = """
PREFIX gndo: <https://d-nb.info/standards/elementset/gnd#>
SELECT ?label
WHERE {
?subject gndo:preferredNameForThePlaceOrGeographicName ?prefName
BIND(?prefName AS ?label)
?subject gndo:preferredNameForThePlaceOrGeographicName ?label
}
"""
[[attributes]]
# lon
# longitude
sparql = '''
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
SELECT ?longitude
Expand All @@ -26,7 +25,7 @@ WHERE {
}
'''
[[attributes]]
# lat
# latitude
sparql = '''
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
SELECT ?latitude
Expand Down
39 changes: 18 additions & 21 deletions apis_core/apis_entities/rdfimport/E53_PlaceFromGeonames.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,22 @@ superclass = "apis_core.apis_entities.abc.E53_Place"
regex = "https://sws.geonames.org.*|/.*achensee.rdf"
[[attributes]]
# name
#FILTER (LANGMATCHES(LANG(?prefName), "de") || LANGMATCHES(LANG(?prefName), "en") || LANG(?prefName) = "")
sparql = """
PREFIX gn: <http://www.geonames.org/ontology#>
SELECT ?name
SELECT ?label
WHERE
{
?subject gn:name|gn:officialName|gn:alternateName ?prefName
FILTER (LANGMATCHES(LANG(?prefName), "de") || LANGMATCHES(LANG(?prefName), "en") || LANG(?prefName) = "")
BIND(?prefName AS ?name)
}
ORDER BY ?lang
"""
[[attributes]]
# alternative_label
sparql = """
PREFIX gn: <http://www.geonames.org/ontology#>
SELECT ?altName (LANG(?altName) AS ?lang)
WHERE {
?subject gn:alternateName ?altName
FILTER (LANGMATCHES(LANG(?altName), "de") || LANGMATCHES(LANG(?altName), "en") || LANG(?prefName) = "")
OPTIONAL {
?subject gn:name ?gnname .
}
OPTIONAL {
?subject gn:officialName ?officialName
}
OPTIONAL {
?subject gn:alternateName ?alternateName
}
BIND(COALESCE(?gnname, ?officialName, ?alternateName) AS ?label)
}
"""
[[attributes]]
Expand All @@ -40,20 +37,20 @@ WHERE {
# lat
sparql = """
PREFIX wgs84_pos: <http://www.w3.org/2003/01/geo/wgs84_pos#>
SELECT ?lat
SELECT ?latitude
WHERE {
?subject wgs84_pos:lat ?lat.
?subject wgs84_pos:long ?long
?subject wgs84_pos:lat ?latitude.
?subject wgs84_pos:long ?longitude
}
"""
[[attributes]]
# long
sparql = """
PREFIX wgs84_pos: <http://www.w3.org/2003/01/geo/wgs84_pos#>
SELECT ?long
SELECT ?longitude
WHERE {
?subject wgs84_pos:lat ?lat.
?subject wgs84_pos:long ?long
?subject wgs84_pos:lat ?latitude.
?subject wgs84_pos:long ?longitude
}
"""
[[attributes]]
Expand Down
38 changes: 38 additions & 0 deletions apis_core/apis_entities/rdfimport/E53_PlaceFromWikidata.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
####################################################
# Create an E53_Place from a wikidata RDF endpoint #
####################################################
superclass = "apis_core.apis_entities.abc.E53_Place"
regex = "http://www.wikidata.org.*"
[[attributes]]
# name
sparql = """
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX schema: <http://schema.org/>
SELECT ?label
WHERE {
?something schema:about ?subject .
?subject rdfs:label ?label .
OPTIONAL { ?subject wdt:P1448/rdfs:label ?official_label }
BIND(COALESCE(?official_label, ?label) AS ?label)
}
"""
[[attributes]]
# longitude
sparql = '''
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT ?longitude
WHERE {
?subject wdt:P625 ?geo1 .
BIND(REPLACE(str(?geo1), "Point\\((\\d+\\.\\d+).*$", "$1") as ?longitude)
}
'''
[[attributes]]
# latitude
sparql = '''
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT ?latitude
WHERE {
?subject wdt:P625 ?geo1 .
BIND(REPLACE(str(?geo1), "Point\\((\\d+\\.\\d+) (\\d+\\.\\d+).*$", "$2") as ?latitude)
}
'''

0 comments on commit 4eedfe9

Please sign in to comment.