0

This query can return both the ID (?ID) for the property and the item ID, but I can't seem to get it to use the property ID (?ID) in a triplet.

SPARQL is a dark art to me. Thank you for your help.


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
Andrew Mayne
  • 1
  • 1
  • 4

1 Answers1

0

UPDATE: Solution by Stanislav Kralin in the comments

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 

Andrew Mayne
  • 1
  • 1
  • 4
  • I'd suggest to use the second solution suggested by Stanislav, i.e. the direct mapping between the properties namespace, i.e. `?property a wikibase:Property ; schema:description ?label ; wikibase:directClaim ?ID` - but indeed just a matter of taste – UninformedUser Mar 22 '22 at 15:01
  • if you don't mind, you can accept your own answer such that it will basically be marked as "done" – UninformedUser Mar 22 '22 at 15:01
  • Thank you. I have to wait 24 hours before accepting my answer. BTW: Is there a thread somewhere where I can post other SPARQL/Wikidata questions like this? – Andrew Mayne Mar 22 '22 at 17:05