0

I have a list of wikidata items I wish to extract the "instance of" property from. For example, looking up Q1339 I can see that it has a single instance type (P:31) labelled "human" (Q5). I have tried to write a simple query that would extract that but I am not getting any records returned. I am v. new to SPARQL so it's very likely I'm missing something obvious.

SELECT ?item ?itemLabel
WHERE
{
  ?item wdt:P31 wd:Q1339.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
} 
cookie1986
  • 865
  • 12
  • 27
  • 1
    With this query, you are asking for an instance of `wd:Q1339` , JS Bach. `wd:Q1339` is an instance of human. So in all cases, the object of a triple pattern needs to be a (de facto) class of things like human, person, place, work etc. Yet have in mind that Wikdata there is no clear difference between instance and class, they are both just items. – Ivo Velitchkov Feb 18 '22 at 15:20
  • 2
    if you look up `Q1339` and see "instance of" relations this means it is the subject of the triple. Just switch subject and object in your query. Yes, in RDF direction matters – UninformedUser Feb 18 '22 at 15:34
  • Thanks @UninformedUser - that did the trick. – cookie1986 Feb 18 '22 at 15:41

0 Answers0