Page MenuHomePhabricator

Create Wikibase Query Service output format for urlencoded SPARQL API request
Closed, ResolvedPublic

Description

To be able to easily add a SPARQL query to OpenRefine as input, a urlencoded SPARQL API call can be used. This needs to be cut and pasted from differently processed parts. It can be easily created programmatically and could be an output format in the Query Service.

The url needs

https://query.wikidata.org/sparql?query=

as a body

urlencoded query with also quotation marks and question marks encoded. The output in the browser bar does not always convert all the necessary characters.
format=json

as appendix

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Isn’t that what the SPARQL endpoint entry in the Link menu is?

Screenshot from 2020-11-13 17-38-35.png (179×491 px, 13 KB)

I tried it for the “cats” query and it seems to have encoded all question marks and quotation marks:

SELECT ?item ?itemLabel WHERE {
  ?item wdt:P31 wd:Q146.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

https://query.wikidata.org/sparql?query=SELECT%20%3Fitem%20%3FitemLabel%20WHERE%20%7B%0A%20%20%3Fitem%20wdt%3AP31%20wd%3AQ146.%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22en%2Cen%22.%20%7D%0A%7D

The URL tab in the Code menu should also be equivalent:

Screenshot_2020-11-13 Wikidata Query Service.png (488×1 px, 45 KB)

(Hm, actually, I get a slightly different URL, where the [AUTO_LANGUAGE] hasn’t been replaced yet – but I don’t think that’s relevant to this task.)

I have never found any use for the SPARQL endpoint option, and now I understand why.

I have assumed I am supposed to click it rather than use the mouse right button to copy the query. Clicking produces a file to save as a result of the query. It is in xml by default.

Now I know that I can copy the link, paste it in my browser and add the json option in the end. I can live with this, but maybe the workflow could be enhanced a bit, allowing to choose the output format and making copying the query explicit.

The code tab is great though, and I am embarrassed that I have not used it. The json option could be added there as well. But again, it's a small task to add manually.

In fact, encoding the [AUTO LANGUAGE] is relevant, as it is the cause of an error in the OpenRefine import.

Gehel claimed this task.
Gehel added a subscriber: Gehel.

Looking at the above comments, it looks like the Link menu is a good enough solution. If that's not the case, please reopen!