0

How should I find the correct property for a query?

Say I want to find all the kings in wikidata.

My first attempt was this:

SELECT ?king ?kingLabel
WHERE
{
   #all result where occupation is king
  ?king wdt:P106 wd:Q12097.

  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }

}

It returned total 515 hit. Which I think is very small number for all the kings.

Second attempt:

SELECT ?king ?kingLabel
WHERE
{
   # all result where position held is king
  ?king wdt:P39 wd:Q12097.

  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }

}

Which returned 817 hits.

So you can see I used different properties: P106 vs P39. They returned different result set. And those are only two properties, maybe it exist another 10-12 properties which I haven't discovered yet and would be better for my query.

edit: And on the top of that the usage of given property doesn't seem to be consequent. For property of P39 (position held) some wiki pages has the value of Q12097 (king) others has Q6412254 (king of Hungary). So as you can see it is impossible to fetch all the kings in wikidata with one query. Or should I fetch bunch of properties and parse their values for the word king? It would be a nightmare but right now couldn't find a better way.

Right now the usage of properties seems ad hoc to me unfortunately and because of this I am using a trial and error method for discovering properties .

So my question is (and it isn't related to the 'king' problem only):

If I want to formulate a query how can I decide which is the best property?

TallTed
  • 9,069
  • 2
  • 22
  • 37
beatrice
  • 3,684
  • 5
  • 22
  • 49
  • 1
    there is no best practice nor a best property, at least not for Wikidata or DBpedia. Exploration like you did is the only way to go unless there is some documentation and a very homogeneous schema. And even then, data quality and data completeness aren't guaranteed, e.g. if you look at [Elisabeth I](https://www.wikidata.org/wiki/Q7207) being a king in Wikidata ... – UninformedUser Nov 02 '19 at 10:43
  • 1
    by the way, using the hierarchy in Wikidata: `SELECT DISTINCT ?king ?kingLabel WHERE { # all result where position held is king ?king wdt:P39/wdt:P279* wd:Q12097. SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } order by ?kingLabel` - i.e. where the position is some subclass of king. – UninformedUser Nov 02 '19 at 10:51
  • Oh thanks! This is much better. And instead of 'position' I should search all sublclass of king get the 'instance of' from them and rerun the search on that. – beatrice Nov 02 '19 at 11:01
  • @AKSW this is somewhat offtopic, but Elisabeth I being king might actually be correct. Not sure about the UK, but in the Dutch constitution for example, the title of king is reserved for the head of state, so queen Beatrix of the Netherlands, for example, was in fact king. The fact that she is a woman is immaterial - she gets addressed as queen of course but legally she was king. – Jeen Broekstra Nov 02 '19 at 13:27
  • Well, that's what I was thinking but couldn't find a reference, at least not in the English Wikipedia page. But clearly, I'm not used to all this royalty stuff - the references in the Wikidata entry are confusing, the "noble title" property stems from Albanian Wikipedia and the "position held" from Alemannic Wikipedia - looks like this refers to the position in Ireland though. Anyways, all the stuff is confusing, but yes, I'm probably wrong. – UninformedUser Nov 02 '19 at 14:13

0 Answers0