SPARQL recursive ancestor query

2019-05-06 06:00发布

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)

标签: sparql
1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-05-06 06:21

See SPARQL property paths and operator +.

SELECT *
{ <a> <hasParent>+ ?ancestor }
查看更多
登录 后发表回答