Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SPARQL recursive ancestor query

Tags:

sparql

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)

like image 600
user_4685247 Avatar asked Dec 14 '22 01:12

user_4685247


1 Answers

See SPARQL property paths and operator +.

SELECT *
{ <a> <hasParent>+ ?ancestor }
like image 118
AndyS Avatar answered Jan 03 '23 04:01

AndyS