Talk:Wikibase/Indexing/SPARQL Query Examples

Why no comments?
It is hard to understand the queries without comments. Does SPARQL interface allow them? --Techtonik (talk) 15:00, 6 June 2015 (UTC)

programatic access
I am trying to execute SPARQL queries at the endpoint http://wdqs-beta.wmflabs.org/ from an Apache Jena program. It works fine for the DBpedia endpoint, but its failing on this one because the response is in HTML - presumably for human consumption. Is there a query parameter that can be set to control the response type? Code:

public static void main(String[] args) {

String queryStr = "select distinct ?Concept where {[] a ?Concept} LIMIT 10";

Query query = QueryFactory.create(queryStr);

//does not work:  Endpoint returned Content-Type: text/html

//try ( QueryExecution qexec = QueryExecutionFactory.sparqlService("http://wdqs-beta.wmflabs.org/", query) ) {

//works

try ( QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query) ) {

// Set the DBpedia specific timeout.

((QueryEngineHTTP)qexec).addParam("timeout", "10000") ;

// Execute.

ResultSet rs = qexec.execSelect;

ResultSetFormatter.out(System.out, rs, query);

} catch (Exception e) {

e.printStackTrace;

}

}

--I9606 (talk) 00:27, 4 September 2015 (UTC)

Note that changing the URL of the endpoint to http://wdqs-beta.wmflabs.org/bigdata/namespace/wdq/sparql did not make any difference and that the same code seems to work fine on all the other endpoints that I have tried.

Female mayors
Hello,

I do not understand why Martine Aubry does not appear in the top 100 of female mayors : [https://query.wikidata.org/#PREFIX%20wikibase%3A%20%3Chttp%3A%2F%2Fwikiba.se%2Fontology%23%3E%0APREFIX%20wd%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fentity%2F%3E%20%0APREFIX%20wdt%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fprop%2Fdirect%2F%3E%0APREFIX%20rdfs%3A%20%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E%0APREFIX%20p%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fprop%2F%3E%0APREFIX%20q%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fprop%2Fqualifier%2F%3E%0APREFIX%20v%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fprop%2Fstatement%2F%3E%0A%0ASELECT%20DISTINCT%20%3Fcity%20%3FcityLabel%20%3Fmayor%20%3FmayorLabel%20%3Fpopulation%20WHERE%20{%0A%20%20%3Fcity%20wdt%3AP31%2Fwdt%3AP279*%20wd%3AQ515%20.%20%20%23%20find%20instances%20of%20subclasses%20of%20city%0A%20%20%3Fcity%20p%3AP6%20%3Fstatement%20.%20%20%20%20%20%20%20%20%20%20%20%20%23%20with%20a%20P6%20%28head%20of%20goverment%29%20statement%0A%20%20%3Fstatement%20v%3AP6%20%3Fmayor%20.%20%20%20%20%20%20%20%20%20%20%20%23%20...%20that%20has%20the%20value%20%3Fmayor%0A%20%20%3Fmayor%20wdt%3AP21%20wd%3AQ6581072%20.%20%20%20%20%20%20%20%23%20...%20where%20the%20%3Fmayor%20has%20P21%20%28sex%20or%20gender%29%20female%0A%20%20FILTER%20NOT%20EXISTS%20{%20%3Fstatement%20q%3AP582%20%3Fx%20}%20%20%23%20...%20but%20the%20statement%20has%20no%20P582%20%28end%20date%29%20qualifier%0A%20%0A%20%20%23%20Now%20select%20the%20population%20value%20of%20the%20%3Fcity%0A%20%20%23%20%28wdt%3A%20properties%20use%20only%20statements%20of%20%22preferred%22%20rank%20if%20any%2C%20usually%20meaning%20%22current%20population%22%29%0A%20%20%3Fcity%20wdt%3AP1082%20%3Fpopulation%20.%0A%20%20%23%20Optionally%2C%20find%20English%20labels%20for%20city%20and%20mayor%3A%0A%20%20SERVICE%20wikibase%3Alabel%20{%0A%20%20%20%20bd%3AserviceParam%20wikibase%3Alanguage%20%22fr%22%20.%0A%20%20}%0A%20}%20ORDER%20BY%20DESC%28%3Fpopulation%29%20LIMIT%20100 try the query]

Best regards,

--Gloumouth1 (talk) 11:25, 15 September 2015 (UTC)
 * Hello Gloumouth1. Lille is not an instance of city, nor an instance of an item which is a subclass of city. There is a query to list all items which are subclass of city. Yep, it's weird that commune of France is not a subclass of city. — Envlh (talk) 17:05, 18 September 2015 (UTC)

No claim items
Would you please write an query to list the items which are linked to enwiki and don't have any claims? Yamaha5 (talk) 13:36, 18 September 2015 (UTC)

Sitelinks
This page would use an example on how to extract/select sitelinks (in some language) for the Wikidata items corresponding to the query. --Nemo 09:39, 11 October 2015 (UTC)

References and qualifiers
Besides sitelinks it might also be interesting to see a simple query for references and qualifiers. The example with "Properties that are defined as "qualifier only" but are used in references" is fairly complex, and I find it difficult to generalize that one to other queries. &mdash; Fnielsen (talk) 12:07, 11 October 2015 (UTC)