6

I want to retrieve the members of the Wikimedia Category American rock singers. I must use Wikidata and it tells me to use P31 with Q4167836 . The query below only returns information about the Category page and not about its members.

Is there any other way to retrieve the members of the Wikimedia Category? I also tried using the term dcterms:subject, which I use successfully with DBpedia, but in Wikidata the query returns empty results.

prefix wdt: <http://www.wikidata.org/prop/direct/>
prefix wd: <http://www.wikidata.org/entity/>
prefix wikibase: <http://wikiba.se/ontology#>
prefix bd: <http://www.bigdata.com/rdf#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
SELECT DISTINCT ?subject ?predicate ?object ?objectLabel WHERE {
     ?subject ?predicate ?object ; wdt:P31 wd:Q4167836 ; 
     rdfs:label "Category:American rock singers"@en 
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" .}
}

Try here

grajkowski
  • 349
  • 1
  • 3
  • 14

1 Answers1

5

Try this query on Wikidata:

SELECT ?subjectLabel WHERE {
    ?subject wdt:P27 wd:Q30;
             wdt:P136 wd:Q11399 .
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en" .}
}

Or try this query on DBpedia (as Mark Miller linked to):

SELECT str(?label) WHERE {
  ?subject dct:subject dbc:American_rock_singers ;
           rdfs:label ?label .
  FILTER (lang(?label) = "en")
}

Or if you must use Wikidata, try this federated query on Wikidata:

PREFIX dbc: <http://dbpedia.org/resource/Category:>
PREFIX dct: <http://purl.org/dc/terms/>
SELECT ?wsubjectLabel WHERE {
    SERVICE <http://dbpedia.org/sparql> {
         ?subject dct:subject dbc:American_rock_singers .
         ?subject owl:sameAs ?wsubject .
         FILTER (STRSTARTS(STR(?wsubject), "http://www.wikidata.org"))
    }
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
  • 1
    So basically there is no chance to retrieve members from Categories in Wikidata like in DBpedia by using ``dcterms`` or something similar? – grajkowski Jun 06 '17 at 11:14
  • @becom, as far as I know, basically — not. Probably, one can use federated queries. – Stanislav Kralin Jun 06 '17 at 11:28
  • 1
    Thank you, works for me. Why does Wikidata not support ``dcterms`` though? – grajkowski Jun 06 '17 at 12:27
  • 1
    @becorn, _IMHO_, Wikidata has more powerfull facilities for classification and taxonomisation than Wikipedia "categories" and support of these categories is rather a legacy, whereas DBpedia depends on Wikipedia in a greater degree. – Stanislav Kralin Jun 06 '17 at 15:46
  • @becorn, and please excuse me for mistypes in your nickname. – Stanislav Kralin Jun 06 '17 at 15:47
  • Mistypes are not a big deal for me. Do you have any scientific sources/links for your statement? I am really interested on that part, because it would explain my chosen functions in the documentary on my program. – grajkowski Jun 07 '17 at 12:34
  • No, I have not. But I suppose this statement is a consequense of the fact that DBpedia content is automatically extracted from Dbpedia, while Wikidata content is not. – Stanislav Kralin Jun 07 '17 at 12:41