Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a Wikidata SPARQL Query and get the url to SVG image of chart

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

like image 900
Andy Avatar asked Sep 22 '17 01:09

Andy


1 Answers

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.

like image 169
StasM Avatar answered Oct 01 '22 02:10

StasM