Reputation: 39
Imagine I would like to query all descendants of Otto Bismarck until generation 3. How could I write the sparql code with regex? In this tutorial it says that we can use regex but I don't know how.
I tried to use "{3}":
SELECT ?descendant ?descendantLabel
WHERE
{
wd:Q8442 wdt:P40{3} ?descendant.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
However, this does not work. The output should be this: try here
Upvotes: 1
Views: 121
Reputation: 1966
It's not possible to write queries with REGEX, but the REGEX syntax can look similar to property paths, hence why you might have been confused.
As for writing paths of length of up to 3, the syntax you are using did not actually make it in the standard, even though it does appear in a few documents.
I'd use something like:
SELECT DISTINCT ?descendant ?descendantLabel
WHERE
{
wd:Q8442 wdt:P40/wdt:P40?/wdt:P40? ?descendant.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
This will give us the paths of length 1, 2, and 3. ?
means 'zero or one instances' of the property.
This trick can work with relatively short paths.
Upvotes: 2