Page MenuHomePhabricator

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


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

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.

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

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!