User:Valor Naram/sparql

From OpenStreetMap Wiki
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".
}

Run it (edit query)

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

Run it (edit query)

Steps to use this query in your (end user) application:

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

Run it (edit query)

  1. 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.
  2. App iterates through the returned data set when rendering an OSM object.
  3. App e.g. finds that the subkeys Key:contact:facebook, Key:contact:tripadvisor have been mapped on the OSM object to render.
  4. App looks into the subfolder `./icons` for an image representing a link to the Facebook and another image analog for TripAdvisor.
  5. App loads the two images `./icons/contact:facebook.png` and `./icons/contact:tripadvisor.png`.
  6. 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)
}

Run it (edit query)

Steps to use this query in your application:

  1. Use the template!
  2. Execute this query on your development machine.
  3. Write the output of the query into a CSV or JSON and bundle it with your app.
  4. Whenever an OpenStreetMap mapper types in a key that key will be checked against the CSV or JSON list bundled in.
  5. 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.