2

I'm using this SPARQL query to obtain a list of European countries:

SELECT ?item $itemLabel
    WHERE {
        ?item wdt:P31 wd:Q6256.
        #?item wdt:P30 wd:Q46
        #?item wdt:P361* wd:Q46.
        ?item wdt:P30|wdt:P361* wd:Q46.
        SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
    }
    ORDER BY ASC($itemLabel)
  • Line 3 limits the results to instances of Q6256, i.e. countries.
  • Line 4 (currently commented out) limits the results to items which are on the continent Q46 (Europe).
  • Line 5 (currently commented out) limits the results to items which are part of Europe, or which are part of something that is part of Europe, etc.
  • Line 6 is an OR-clause which combines line 4 and 5.

I'm running the query with one of the lines 4-6 active, and the other two commented out.

No matter which predicate is active, Austria is not part of the results (other countries are missing as well). However, looking at https://www.wikidata.org/wiki/Q40, we can see that

  • Austria is an instance of Q6256.
  • Austria's continent (P30) is Europe.
  • Austria is part of Central Europe (Q27509), which is part of Europe.

What am I doing wrong?

Here's the relevant query.

Jonas Sourlier
  • 13,684
  • 16
  • 77
  • 148
  • same question was asked here (and basically got the same explanation and solution): https://stackoverflow.com/questions/55253246/wikidata-query-missing-out-countries-in-europe – UninformedUser May 05 '19 at 02:51

1 Answers1

2

Austria is actually not declared as an instance of country (Q6256). It is declared as an instance of sovereign state (Q3624078), which is a subclass (P279) of country. The instance relationship to country that can be seen on Austria's page is inferred, and not available when queried.

To fix this, we can query for items that are instances of country or its subclasses:

?item wdt:P31/wdt:P279* wd:Q6256.

Unfortunately this also pulls in historical countries, so the query will need some additional work to filter those out (e.g., with FILTER NOT EXISTS { ... }). It also needs SELECT DISTINCT.

cygri
  • 9,412
  • 1
  • 25
  • 47
  • Thanks. Are you sure that Austria is not an instance of country (Q6256)? On the page https://www.wikidata.org/wiki/Q40, there are six classes of which Austria is an instance. The first one is sovereign state (Q3624078), and the last one is country (Q6256). – Jonas Sourlier May 04 '19 at 21:22
  • 1
    I can see that Austria's membership of sovereign state has "Preferred rank", might that be the reason it's not found in my query? ("country" has only "Normal rank"). – Jonas Sourlier May 04 '19 at 21:24
  • If you query for the wdt:P31’s of Q40, country is not in the results. You might be right that it is because wdt: only returns values with preferred rank, [see here](https://en.wikibooks.org/wiki/SPARQL/WIKIDATA_Qualifiers,_References_and_Ranks#Ranks). Regarding P30, the “is in Europe” part of your query works for Austria; it is the “is a country” part that fails, and both parts must succeed for an item to be included in the results. – cygri May 04 '19 at 21:34
  • was asked [here](https://stackoverflow.com/questions/55253246/wikidata-query-missing-out-countries-in-europe) as well. in the end, working beyond *truthy statement* + some filters like `filter not exists{?country p:P31/ps:P31 wd:Q3024240 }` or maybe check whether there is an end time. There is also an "issue" with Kingdom of the Netherlands showing up in addition to Netherlands, which seems to be because both include different areas like also the regions in the Carribean – UninformedUser May 05 '19 at 02:57