基于Apache Jena的SPARQL递归路径遍历查询需求及问题解决
SPARQL递归路径查询问题解决
场景与RDF数据
使用Apache Jena 5.1,基于以下Turtle格式的RDF数据:
ex:thing1 ex:connectsTo ex:thing2 . ex:thing2 ex:connectsTo ex:thing3, ex:thing4 . ex:thing3 ex:connectsTo ex:thing5 . ex:thing7 ex:whatever "not in this film" . ex:thing8 ex:connectsTo ex:thing5 .
查询需求
需要编写SPARQL语句,实现从绑定变量components(可包含0或多个ex:thingN实体)出发的递归路径遍历,输出完整的依赖链或独立的从-到对:
- 当
components为ex:thing1时,需返回对应的两条递归路径 - 当
components为(ex:thing1, ex:thing8)时,需返回三条路径
问题与解决
用户最初编写的SPARQL查询返回了无关的ex:thing7,移除语句中的FILTER EXISTS后,得到了正确的从-到结果集。
内容的提问来源于stack exchange,提问作者Buzz Moschetti
相关产品推荐
相关产品推荐

