Reputation: 11
I have done a family tree. I also defined transitive property: childOf. Now I want to make SPARQL Query which give me all descendants of one of members of family. How can I do it? Thanks
Upvotes: 1
Views: 326
Reputation: 739
If your triple store supports OWL reasoning and you've defined your childOf
property to be transitive (shouldn't it be called descendantOf
by the way!), then it should infer childOf
properties directly between all related nodes. So, it should be enough to query it like this (prefixes omitted for brevity):
SELECT DISTINCT * {
?x :childOf ?y
}
However, if your triple store doesn't do OWL reasoning, you can achieve the same result by using SPARQL 1.1 property paths to query for indirect relationships:
SELECT DISTINCT * {
?x :childOf+ ?y
}
Note the '+' after the childOf
, this means that the predicate may be matched 1 or more times. More details about SPARQL 1.1 property paths are at http://www.w3.org/TR/sparql11-property-paths/.
Upvotes: 1