5

If I run this SPARQL query

#defaultView:BubbleChart
#TEMPLATE={"template":"Overall causes of death ranking of ?thing ","variables":{"?thing": {"query":"SELECT ?id  (COUNT(?id) AS ?count) WHERE {  ?sub wdt:P509 ?y.  ?sub wdt:P31 ?id. } GROUP BY ?id "} } }
SELECT ?cid ?cause (COUNT(*) AS ?count) WHERE {
  BIND(wd:Q5 AS ?thing)
  ?pid wdt:P31 ?thing.
  ?pid wdt:P509 ?cid.
  OPTIONAL {
    ?cid rdfs:label ?cause.
    FILTER((LANG(?cause)) = "en")
  }
}
GROUP BY ?cid ?cause
ORDER BY DESC(?count) ?cause
LIMIT 50

in the Wikidata Query Editor, I have the option to download the bubblechart as an SVG file using the menu Download > SVG Image

Resulting bubble chart of the SPARQL query

I am looking for a way to generate or retrieve the URL to this SVG file when I execute the same SPARQL script programatically. In that case, only the raw data is returned (as JSON).

{ "head" : { "vars" : [ "cid", "cause", "count" ] }, "results" : { "bindings" : [ { "cid" : { "type" : "uri", "value" : "http://www.wikidata.org/entity/Q12152" }, "cause" : { "xml:lang" : "en", "type" : "literal", "value" : "myocardial infarction" }, "count" : { "datatype" : "http://www.w3.org/2001/XMLSchema#integer", "type" : "literal", "value" : "5837" } }, { "cid" : { "type" : "uri", "value" : "http://www.wikidata.org/entity/Q12192" }, "cause" : { "xml:lang" : "en", "type" : "literal", "value" : "pneumonia" }, "count" : { "datatype" : "http://www.w3.org/2001/XMLSchema#integer", "type" : "literal", "value" : "2177" }.... etc

Orienteerix
  • 453
  • 1
  • 9
  • 16
Andy
  • 842
  • 1
  • 12
  • 24
  • I don't think this is possible. See at `Link -> Short URL to result`. When you open this in a browser, you can check the source code - there is a lot of embedded Javascript code, thus, it looks like being generated dynamically. Sure, that should be some export function to SVG, but I'm not sure whether this can be handled in a single HTTP request. You should ask for details on the Wikidata mailing list. – UninformedUser Sep 22 '17 at 07:49
  • Followup: All my research has led to the conclusion this is not possible. Feel free to prove me wrong, but maybe this can save others some time. – Andy Oct 28 '17 at 23:17
  • It is indeed generated dynamically, but you could request the feature on https://phabricator.wikimedia.org/ tagging #wikidata – Addshore Nov 13 '18 at 15:54
  • 1
    I filed https://phabricator.wikimedia.org/T209392 – Addshore Nov 13 '18 at 16:48

1 Answers1

1

There's no URL to this SVG because it is generated by the Javascript running in the browser after retrieving JSON results. If you want to get it programmatically, I think using browser automation to run the Javascript code and obtain the file using simulated user actions would be the quickest way to achieve it.

StasM
  • 10,593
  • 6
  • 56
  • 103