1

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?

logi-kal
  • 7,107
  • 6
  • 31
  • 43
maxx
  • 163
  • 5
  • https://stackoverflow.com/q/51103215/7879193 ? – Stanislav Kralin Sep 06 '19 at 14:45
  • 1
    Thank you Stanislav, but as far as I understand it I am not able to find a connection like `Q146 --P31--> a --P279--> b --P279--> end` – maxx Sep 06 '19 at 15:09
  • If you need to output paths, I'd suggest to extract a subgraph via `CONSTUCT`, then load triples into Stardog, then use Stardog [`PATHS`](https://www.stardog.com/docs#_path_queries_2) queries. – Stanislav Kralin Sep 06 '19 at 15:30
  • 1
    you can't find arbitrary paths with standard SPARQL as @StanislavKralin already said. Either use some extension like the Stardog triple store provides, or use some graph database. In any case, you'd have to extract the outgoing subgraph of depth `d` – UninformedUser Sep 06 '19 at 16:14
  • Subgraph: https://w.wiki/7ys – Stanislav Kralin Sep 06 '19 at 17:10
  • 1
    Or do you need just https://w.wiki/7zD? – Stanislav Kralin Sep 06 '19 at 19:55
  • Hey @Stanislav, https://w.wiki/7zD provides the answer I had with my question. But I think you are right that `CONSTRUCT` could be the way to go for me. If you write an answer based on https://w.wiki/7zD I will happily accept it. Thank you so much for your help – maxx Sep 08 '19 at 09:23
  • Possible duplicate of [Find which direct property applied in a SPARQL query](https://stackoverflow.com/questions/51103215/find-which-direct-property-applied-in-a-sparql-query) – Stanislav Kralin Sep 08 '19 at 10:48

1 Answers1

1

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

Karima Rafes
  • 1,016
  • 10
  • 19