SPARQL recursive ancestor query
Asked Answered
P

1

6

I'm stuck with a recursive query in SPARQL, I cant wrap my head around it. I want to get all ancestors of an instance "a" (a hasParent b, b hasParent c, c hasParent d) so the result would be "b, c ,and d" if instance is "a".

Any ideas how to construct the linked part where parent has a parent which has another parent? (The depth of the recursion is not known)

Puente answered 10/1, 2017 at 16:43 Comment(0)
P
13

See SPARQL property paths and operator +.

SELECT *
{ <a> <hasParent>+ ?ancestor }
Patty answered 10/1, 2017 at 18:41 Comment(2)
Is the order of the result defined in any way? Is it guaranteed to be always exactly b, c, d ?Immunochemistry
The order is not defined.Patty

© 2022 - 2024 — McMap. All rights reserved.