User:Valor Naram/sparql
Jump to navigation
Jump to search
The key "addr" with all its subkeys
App category: OpenStreetMap mapping
Returns the key Key:addr with all its subkeys (e.g. Key:addr:street).
TODO Does not work as of August 2023 (returns only 3 subkeys of addr:*).
SELECT ?key ?label
WHERE {
?key osmdt:P2 osmd:Q7 . # ?key instance of key (show only keys)
?key osmdt:P16 ?label . # ?key permanent key id (map value to column ?label) (filter by keys having a permanent key id and put value into ?label)
FILTER strstarts(?label, "addr") # show only keys which permanent key id values start with "addr".
}
The subkeys of a key
App category: OpenStreetMap mapping, end user apps
Returns all subkeys (e.g. Key:contact:facebook) of the key Key:contact excluding the key Key:contact itself from the result set. Use case:
- End user applications can support all contact:* subkeys at once without the developer having to actively add code to support all of these. That enables apps to display also less used communication channels like Mastoton to the end user.
SELECT ?key ?label
WHERE {
?key osmdt:P2 osmd:Q7 . # ?key instance of key (show only keys)
?key osmdt:P16 ?label . # ?key permanent key id (map value to column ?label) (filter by keys having a permanent key id and put value into ?label)
FILTER strstarts(?label, "contact:") # show only keys which permanent key id values start with "contact:".
}
Steps to use this query in your (end user) application:
- Use the template
SELECT ?label
WHERE {
?key osmdt:P2 osmd:Q7 . # ?key instance of key (show only keys)
?key osmdt:P16 ?label . # ?key permanent key id map value to column ?label (filter by keys having a permanent key id and put value into ?label)
FILTER strstarts(?label, "%mainkey:") # show only keys which permanent key id values start with "%mainkey".
}
- Replace `%mainkey` with the main key you want all subkeys for. If you want to show all subkeys of the key Key:contact then replace `%mainkey` with `contact` ( without the char : ) because that is already incorporated in the query.
- App iterates through the returned data set when rendering an OSM object.
- App e.g. finds that the subkeys Key:contact:facebook, Key:contact:tripadvisor have been mapped on the OSM object to render.
- App looks into the subfolder `./icons` for an image representing a link to the Facebook and another image analog for TripAdvisor.
- App loads the two images `./icons/contact:facebook.png` and `./icons/contact:tripadvisor.png`.
- App places the two images at the specified position for contact methods. The images are hyperlinks. If a user clicks on one of these images the website will be opened in a browser tab/the in-app browser.
List deprecated keys
Returns all deprecated keys and their respective successors.
App category: OpenStreetMap mapping
SELECT ?deprecatedKey ?deprecatedLabel ?newKey ?newLabel
WHERE {
?deprecatedKey osmdt:P2 osmd:Q7 . # ?deprecatedkey instance of key (show only keys)
?deprecatedKey osmdt:P16 ?deprecatedLabel . # ?deprecatedkey permanent key id (map value to column ?deprecatedlabel) (filter by keys having a permanent key id and put value into ?deprecatedLabel)
?deprecatedKey osmdt:P6 osmd:Q5061 . # ?deprecatedKey status deprecated (show only deprecated keys)
?deprecatedKey osmdt:P17 ?newKey . # ?deprecatedKey redirect to (map value to column ?newKey) (filter by keys having a redirect to and put value into ?newKey)
?newKey osmdt:P16 ?newLabel . # ?newKey permanent key id (map value to column ?newLabel) (show the key name of the successor of ?deprecatedKey)
}
Steps to use this query in your application:
- Use the template!
- Execute this query on your development machine.
- Write the output of the query into a CSV or JSON and bundle it with your app.
- Whenever an OpenStreetMap mapper types in a key that key will be checked against the CSV or JSON list bundled in.
- If found in the list then the app recommends to use the new key because the key the user wanted to use has been deprecated. Optionally the app should prevent the usage of deprecated keys. But that behaviour should have an opt-out in app settings to allow advanced users to use the deprecated one.