6

While examining the results of the official example query "Continents, countries, regions and capitals" (on https://query.wikidata.org/, limited to Germany for your convenience here: link), I noticed that some capitals of German federal states were missing. For example Wiesbaden as capital of Hesse. I noticed that Wiesbaden is an instance of big city, but not of city (see https://www.wikidata.org/wiki/Q1721), in contrast to some other cities. I was able to alleviate the problem by also including cities that are subclasses of city by changing line 17 to ?city wdt:P31/wdt:P279? wd:Q515.
One of the four cities that are still missing is Magdeburg, the capital of Saxony-Anhalt.
The diagnostic query

SELECT ?cityLabel ?props
WHERE {
  ?city wdt:P31 ?props.
  FILTER(?city = wd:Q1733 || ?city = wd:Q1726).
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

shows that Magdeburg is not even an instance of city, although it clearly is according to its Wikidata page https://www.wikidata.org/wiki/Q1733.

I am new to Wikidata and SPARQL. However, this seems wrong to me. What can I do to get all capitals of the german federal states? And what is the reason for this behaviour?

logi-kal
  • 7,107
  • 6
  • 31
  • 43
Leif
  • 2,143
  • 2
  • 15
  • 26
  • To be honest, I don't think you're doing anything wrong. The query `SELECT * WHERE { wd:Q1733 wdt:P31 ?o }` should return all types, but it looks like something goes wrong. – UninformedUser Nov 03 '17 at 16:24
  • Well, it looks like for statements with no references only one is returned. For example, the query to get the country `SELECT * WHERE { wd:Q1733 wdt:P17 ?o }` also returns just one value. On the other hand, if you look at statements for `capital of` with `SELECT * WHERE { wd:Q1733 wdt:P1376 ?o }` it returns multiple values. – UninformedUser Nov 03 '17 at 16:31

1 Answers1

6

These missing statements are not truthy:

SELECT ?statement ?valueLabel ?rank ?best
WHERE {
  wd:Q1733 p:P31 ?statement.
  ?statement ps:P31 ?value .
  ?statement wikibase:rank ?rank .
  OPTIONAL { ?statement a ?best . }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Try it!

They are normal-rank statements, but there is a preferred-rank statement.

Truthy statements represent statements that have the best non-deprecated rank for given property. Namely, if there is a preferred statement for property P2, then only preferred statements for P2 will be considered truthy. Otherwise, all normal-rank statements for P2 are considered truthy.

Update

I have decreased the rank of the preferred statement just now. Please test your query again.

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
  • 1
    Interesting. I didn't know this also holds for `instance of` statements. To be honest, I don't understand why those statements are not considered to be true. I mean, Munich a city? – UninformedUser Nov 03 '17 at 17:02
  • 1
    @AKSW, I have updated my answer. In short, all non-deprecated statements are truthy, but preferred statements are even more truthy.. – Stanislav Kralin Nov 03 '17 at 17:34
  • 3
    In fact, it was an act of (occasional) vandalism: https://www.wikidata.org/w/index.php?title=Q1733&diff=prev&oldid=572814192 – Stanislav Kralin Nov 03 '17 at 21:57
  • 1
    +1, accepted, it works, thanks. Although I did not know about ranks, that was one theoretical possibility, I pondered. However, it does not make much sense in this case. The statement "Magdeburg is a city" should be true in a knowledge base. However, it is only true on the wikidata page, but not in the SPARQL query. Oh boy, this is a potential source for a lot of trouble. – Leif Nov 03 '17 at 22:20