owl:TransitiveProperty in query

对着背影说爱祢 提交于 2019-12-11 10:33:42

问题


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


回答1:


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/.



来源:https://stackoverflow.com/questions/8645778/owltransitiveproperty-in-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!