David
David

Reputation: 37

How to avoid timeout in Wikidata - SPARQL for a specific query : SELECT DISTINCT all types values of a property?

I would like to get all DISTINCT type value of P31 property for all entities. For example : enter image description here

Here the query:

SELECT DISTINCT ?item ?itemLabel ?itemDescription
WHERE {  

  VALUES (?property) {
     (wdt:P31)
  }  
  ?article schema:about ?item .
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "fr". }
  
}LIMIT 100

https://query.wikidata.org/#SELECT%20DISTINCT%20%3Fitem%20%3FitemLabel%20%3FitemDescription%0AWHERE%20%7B%20%20%0A%0A%20%20VALUES%20%28%3Fproperty%29%20%7B%0A%20%20%20%20%20%28wdt%3AP31%29%0A%20%20%7D%20%20%0A%20%20%3Farticle%20schema%3Aabout%20%3Fitem%20.%0A%20%20%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22fr%22.%20%7D%0A%20%20%0A%7DOFFSET%200%20LIMIT%20100

Result is an exception timeout :

SPARQL-QUERY: queryStr=SELECT DISTINCT ?item ?itemLabel ?itemDescription
WHERE {  

  VALUES (?property) {
     (wdt:P31)
  }  
  ?article schema:about ?item .
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "fr". }
  
}LIMIT 100
java.util.concurrent.TimeoutException
    at java.util.concurrent.FutureTask.get(FutureTask.java:205)
    at com.bigdata.rdf.sail.webapp.BigdataServlet.submitApiTask(BigdataServlet.java:292)
    at com.bigdata.rdf.sail.webapp.QueryServlet.doSparqlQuery(QueryServlet.java:678)
    at com.bigdata.rdf.sail.webapp.QueryServlet.doGet(QueryServlet.java:290)
    at com.bigdata.rdf.sail.webapp.RESTServlet.doGet(RESTServlet.java:240)
    at com.bigdata.rdf.sail.webapp.MultiTenancyServlet.doGet(MultiTenancyServlet.java:273)

Upvotes: 1

Views: 62

Answers (1)

David
David

Reputation: 37

With the help of the others in question's comments, here the correct query :

    SELECT ?type ?typeLabel WHERE {
      {
        SELECT DISTINCT ?type WHERE { ?item wdt:P31 ?type. }
        OFFSET 0 LIMIT 10000
      }
      SERVICE wikibase:label { bd:serviceParam wikibase:language "fr". }    
}

Use offset for pagignated results.

Upvotes: 1

Related Questions