OpenStreetMap Wiki template equivalent to Wikidata Template:SPARQL2

Would be possible to have the Template equivalent to https://www.wikidata.org/wiki/Template:SPARQL2 on the OpenStreetMap wiki?

The https://wiki.openstreetmap.org/wiki/Template:SPARQL does exist, but uses https://sophox.org/, not https://query.wikidata.org/.

What I’m using now

At the moment I’m using as something like this (which requires both edit the code and the URL encoded link manually

<syntaxhighlight lang="sparql">
# SPARQL here
</syntaxhighlight>

[https://query.wikidata.org/#very-long-query-here Try it]

It works, but is a bit more verbose.

What I would like (if relevant to OSM Wiki)

The following code

{{SPARQL2|query=
SELECT ?item ?itemLabel
WHERE{
  ?item wdt:P31/wdt:P279* wd:Q1968122 .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
}}

would render similar to https://www.wikidata.org/wiki/Wikidata:WikiProject_IFRC/Queries

(However, the SPARQL2 could be different to explicitly hint that is to Wikidata, not Sophox)

Maybe a good place to discuss this topic is Talk:Wiki - OpenStreetMap Wiki

While adding such as template shouldn’t be a big issue, the name with the “2” at the end could cause some confusion. Maybe someone has a good idea for another name.

1 Like

Just call it WikidataSPARQL

You can probably also just use federated SPARQL queries to query wikidata instead of sophox without changing the template at all.
https://wiki.openstreetmap.org/wiki/Sophox#Hello_(OSM_SPARQL)_World

2 Likes

Thank you both! I marked the @Woazboat as answer, however as proposed to by @mmd I’ve created the discussion on the Talk page here https://wiki.openstreetmap.org/wiki/Talk:Wiki#Template:WikidataSPARQL (initial name suggestion of Template:WikidataSPARQL). Anyone here is invited to give extra notes there!

I already changed a bit the proposal on the Talk:Wiki based on your feedback here since if worth the idea of have the template hardcoded to Wikidata endpoint, then at this point make sense to explicitly give visual hints on the generated template that it would run directly on Wikidata as opposed to Sophox, which really reserves to be default since it even allows federated query.

However, the Wikidata SPARQL does have not 1 by 1 equivalence on the query, so two templates make sense. Maybe in some place later I could document how to convert from the (proposed) Template:WikidataSPARQL to existing Template:SPARQL side by side.


PS: I not tested yet, but since SPARQL specification allow federate not just endpoints, but static files, in theory this would allow pre-process very heavy Wikidata queries in 5 to 100 steps and dump smaller RDF files and host like on GitHub pages, so Sophox (as long as some domain is allowed to federate on such static files) could be faster. So, while I’m interested on a direct to Wikidata SPARQL template (several queries I do have would be compatible inside and outside OSM), the Sophox already offers more than Wikidata public endpoint even for data on Wikidata which could be pre-processed ahead of the use. Fantastic!

{{SPARQL|endpoint=https://query.wikidata.org/|query=
SELECT ?item ?itemLabel
WHERE{
  ?item wdt:P31/wdt:P279* wd:Q1968122 .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
}}

Update: The code above already work on the OpenStreetMap wiki. The Template:SPARQL template (see Template talk:SPARQL - OpenStreetMap Wiki) was updated to allow customize endpoints so the idea of new custom template WikidataSPARQL is not necessary. Thanks!

1 Like