Some cities aren't instances of city or big city? Odd behaviour of Wikidata
Asked Answered
H

1

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?

Haleigh answered 3/11, 2017 at 16:10 Comment(2)
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.Octamerous
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.Octamerous
B
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.

Baier answered 3/11, 2017 at 16:58 Comment(4)
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?Octamerous
@AKSW, I have updated my answer. In short, all non-deprecated statements are truthy, but preferred statements are even more truthy..Baier
In fact, it was an act of (occasional) vandalism: wikidata.org/w/…Baier
+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.Haleigh

© 2022 - 2024 — McMap. All rights reserved.