Talk:Wikibase/Indexing/SPARQL Query Examples
Add topicWhy no comments?
[edit]It is hard to understand the queries without comments. Does SPARQL interface allow them? --Techtonik (talk) 15:00, 6 June 2015 (UTC)
- Yes it does. Some queries have them. Please add comments, comments are good :) --Smalyshev (WMF) (talk) 07:41, 11 June 2016 (UTC)
programatic access
[edit]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
[edit]Hello,
I do not understand why Martine Aubry does not appear in the top 100 of female mayors : 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)
- Thank you Envlh, difficult to understand for mee too, even if I'm French. --Gloumouth1 (talk) 09:36, 8 November 2017 (UTC)
No claim items
[edit]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
[edit]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
[edit]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. â Fnielsen (talk) 12:07, 11 October 2015 (UTC)
- I was helped by reading this paper: Reifying RDF: What Works Well With Wikidata?. â Fnielsen (talk) 13:43, 16 October 2015 (UTC)
- I am also interested in simple examples involving references or qualifiers. For instance, how can the query for Wikidata items with a PMID (P698) or PMCID (P932) be modified to give all Wikidata items that have statements referenced to Wikidata items with a PMID (P698) or PMCID (P932)? --Daniel Mietchen (talk) 01:59, 4 January 2016 (UTC)
- @Fnielsen and Daniel Mietchen: This page of example SPARQL queries on Wikidata itself may be helpful, see for example the following sections there:
- The page could use some work -- for example, it would be better if more of the queries were shown explicitly on the page (perhaps in collapse boxes), rather than just as links. It also could use some more relevant queries. But you may find it worth a look. Jheald (talk) 17:42, 20 January 2016 (UTC)
African women without an article in French?
[edit]Hello, as part of WikiLovesWomen writing challenge, I was looking for dieas of article and have not been able to create the query I was willing which would list wikidata elenments :
- for women
- with a country that is on the continent Africa (excluding P30=Q15 with an attribute, as we don't want women from France, which has a P30=Q15 with an extra P518 as the P30 is not for the whole country)
- bonus: ordered by number of existing interwiki for the subject, descending order
If someone knows how to do that, thanks in advance! Symac (talk) 14:09, 20 January 2016 (UTC)
- @Symac: For requests like this, you may get more response by posting at the SPARQL queries talk page on Wikidata itself, which I think may watched by more people than this page at MediaWiki. Jheald (talk) 17:47, 20 January 2016 (UTC)
- @Jheald: thanks for the pointer, I have added my request there Symac (talk) 20:42, 20 January 2016 (UTC)
Who's birthday is it today
[edit]It doesnt run as an example. I think its to expensive for the enpoint to querry right now.
[try-it]
I am having this right now with a lot of my querries i am trying.
Is there somewhere a good tutorial on how i could setup my own sparql enpoint? Like DBpedia has
cheers
Air accidents
[edit]This should include subclasses. Thierry Caro (talk) 15:58, 20 March 2016 (UTC)
Wikibase/Indexing/SPARQL_Query_Examples#Wikidata_people_per_million_inhabitants_for_all_EU_countries
[edit]Not sure why, but I can't seem to be able to make this appear in "examples" on https://query.wikidata.org --Jura1 (talk) 16:35, 10 June 2016 (UTC)
Sorry @Jura1: there seems to be a bug omitting the last query...
Method in madness
[edit]I am trying to sort some of the queries into categories, because otherwise it is hard to comprehend them now (good problem to have, but still :). I think is it possible to achieve the situation when no category would have more than 10-15 items, and subdivide them as needed. Let's see if it works. --Smalyshev (WMF) (talk) 07:49, 11 June 2016 (UTC)
inventors killed by their own invention
[edit]Currently, the query 'inventors killed by their own invention' only returns a single result (Francis Edgar Stanley), but the list of inventors killed by their own inventions gives about thirty examples. Does this mean that the query is not good enough, that the metadata lacks or is there another cause? And how can we rectify this?
81.246.4.66 11:50, 27 July 2016 (UTC)
No/unknown value?
[edit]Could we have a sample query for those each, please? Thanks! --Magnus Manske (talk) 00:02, 13 August 2016 (UTC)
Inconsistent result
[edit]I am running this query and results are inconsistent. Sometimes wWikiTreeID has value and sometimes it is empty. On object Q1392324 P2949 is defined.
SELECT ?p ?w ?wWikiTreeID WHERE {
{ ?p wdt:P22 wd:Q1392324. ?p wdt:P22 ?w. Optional {?w wdt:P2949 ?wWikiTreeID. } }
}
Result: [{"p":"http://www.wikidata.org/entity/Q1376676","w":"http://www.wikidata.org/entity/Q1392324"}, {"p":"http://www.wikidata.org/entity/Q11724775","w":"http://www.wikidata.org/entity/Q1392324"}]
Wikibase install queries
[edit]I know how to use the Wikidata SPARQL Query well enough. The issue is the install that comes with the Wikibase package is very much tied into Wikidata, and seems impossible to separate. Is there a way to easily configure the Sparql query engine to allow for defaulting on the local wikibase install? Or are there easy to understand configuration directions to do a query using a wikibase install on a non-wikimedia wiki?
Where say a query like:
- Cats
SELECT ?item ?itemLabel WHERE { ?item wdt:P31 wd:Q146 . SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } }
could be run on "mediawikidevelopersareawesome.com"? --LauraHale (talk) 13:47, 25 February 2017 (UTC)