4

我想检索 Wikimedia Category 的成员American rock singers。我必须使用 Wikidata,它告诉我使用P31with Q4167836。下面的查询仅返回有关类别页面的信息,而不是有关其成员的信息。

有没有其他方法可以检索维基媒体类别的成员?我也尝试使用术语dcterms:subject,我在 DBpedia 中成功使用了它,但在 Wikidata 中,查询返回空结果。

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" .}
}

在这里试试

4

1 回答 1

5

在 Wikidata 上尝试此查询:

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

或者在 DBpedia 上尝试这个查询(正如 Mark Miller 所链接的那样):

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

或者,如果您必须使用 Wikidata,请在 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" }
}
于 2017-06-06T11:09:17.327 回答