如何在维基数据 SPARQL 查询中将变量用作 属性 ID

How to use a variable as a property ID in a Wikidata SPARQL query

此查询可以 return 属性 的 ID (?ID) 和项目 ID,但我似乎无法使用 属性 ID (?ID) 三元组。

SPARQL 对我来说是一门黑暗的艺术。感谢您的帮助。


SELECT ?item ?itemLabel ?superpower ?property ?label ?ID ?superpowerLabel
WHERE
{
  
  ?property a wikibase:Property ;
        schema:description ?label . 
  
  filter contains(?label,"super") 
  filter contains(?label,"abilities") 
  
  ?item rdfs:label "Wolverine"@en .
  # Get the ID
  BIND(REPLACE(STR(?property), "http://www.wikidata.org/entity/", "wdt:") AS ?ID)
  ?item ?ID ?superpower   . # This part works with "wdt:P2563" instead of ?ID.
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

LIMIT 10
</pre>
	

更新:Stanislav Kralin 在评论中提出的解决方案

w.wiki/4yY5 оr w.wiki/4yY7, see m.mediawiki.org/wiki/Wikibase/Indexing/RDF_Dump_Format – Stanislav Kralin

WHERE
{
  
  ?property a wikibase:Property ;
        schema:description ?label . 
  
  filter contains(?label,"super") 
  filter contains(?label,"abilities") 
  
  ?item rdfs:label "Wolverine"@en .
  # Get the ID
  BIND(URI(REPLACE(STR(?property), STR(wd:), STR(wdt:))) AS ?ID)
  ?item ?ID ?superpower   . # This part works with "wdt:P2563" instead of ?ID
  hint:Prior hint:runLast true .
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

LIMIT 10