The 'all cities' part of your query seems strange.  If you replace it with a simple 'instance of city' - ?x wdt:P31 wd:Q515 . it returns 145 results in 341ms.
Why would you ask for things that have 'occupation' or 'position' with value city?

Also, I'm not familiar with the use of the '/' in that line of the query.  My experience with that is as a mathematical operator.  What is it supposed to be doing?

On Wed, Apr 5, 2017 at 10:00 AM, Anatoly Zelenin <> wrote:
Hi all,
I am building a Question Answering System for Wikidata (I will put the
demo live in May) and would like to be able to ask quesitons like "Give
me the cities in Alaska". To query Wikidata I am using the Wikidata
SPARQL endpoint.

The SPARQL query for this question looks the following way [0]:

  # All things in Alaska
  ?x (wdt:P131+ | wdt:P276) wd:Q797 .
  #  All cities
  ?x ((wdt:P106 | wdt:P39 | wdt:P31) / wdt:P279*) wd:Q515 .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }

As it needs to join over two very large sets (the set of all cities and
the set of all things in Alaska) the query times out. Do you have an
idea how I could write the query without getting a timeout?
Thank you ;)


Anatoly Zelenin

Wikidata mailing list