Path queries in Wikidata endpoint?

476 views Asked by At

Consider the following snippet

ASK WHERE { wd:Q734774 wdt:P31 wd:Q3918. }

This works fine in Wikidata. I want to use some of the path syntax in the this snippet. Specifically I want to limit the number of the times "wdt:P31" used in the path. According to the guidelines this should be the right syntax:

ASK WHERE { wd:Q734774 wdt:P31{,3} wd:Q3918. }

But it's giving me weird error messages. Any ideas?

1

There are 1 answers

2
TallTed On

The final version of SPARQL 1.1 Property Paths lets you do this with the following query --

ASK WHERE 
  { wd:Q734774 
       wdt:P31? / wdt:P31? / wdt:P31? 
          wd:Q3918 
  }

For clarity, I've put the full Property Path Predicate (wdt:P31? / wdt:P31? / wdt:P31?) on a separate line between Subject (wd:Q734774) and Object (wd:Q3918). The trailing ? asks for one-or-zero instances of the wdt:P31 predicate, and the / asks for a sequence, so this full path asks for a sequence of zero-or-one-or-two-or-three instances.