maxx
maxx

Reputation: 163

SPARQL: Find out which property is used for link

So I have the following query I would like to extend:

SELECT ?item ?itemLabel ?p ?superItem ?superItemLabel
WHERE { 
  wd:Q146 (wdt:P279 | wdt:P31 | wdt:P361 )+ ?item.
  ?item   ( wdt:P279 | wdt:P31 | wdt:P361) ?superItem.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

If you run it in the Wikidata Query Service you can see an empty column. There I would like to have the Property responsible for that specific link. So either wdt:P279 or wdt:P31 or wdt:P361.

Is this somehow possible? And if yes how?

Upvotes: 1

Views: 162

Answers (1)

Karima Rafes
Karima Rafes

Reputation: 1108

It is possible to print property is used in a triple with the keyword VALUES.

PREFIX bd: <http://www.bigdata.com/rdf#> 
PREFIX wd: <http://www.wikidata.org/entity/> 
PREFIX wdt: <http://www.wikidata.org/prop/direct/> 
PREFIX wikibase: <http://wikiba.se/ontology#> 

SELECT ?item ?itemLabel ?p ?superItem ?superItemLabel
WHERE { 
  wd:Q146 (wdt:P279 | wdt:P31 | wdt:P361 )+ ?item.

  VALUES ?p { wdt:P279  wdt:P31  wdt:P361 }
  ?item  ?p ?superItem.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
LIMIT 50

Demo: http://linkedwiki.com/query/Find_out_which_property_is_used_for_link

Doc: https://www.w3.org/TR/sparql11-query/#inline-data

Upvotes: 1

Related Questions