在SPARQL 1.1中过滤属性路径

时间:2016-05-10 15:54:30

标签: sparql rdf semantic-web triplestore propertypath

有没有办法过滤像

这样的查询
select ?x ?y  where {?x <http://relationship.com/wasRevisionOf>+ ?y }";

对于提供的数据集具有以下输出:

http://article.com/2-3 http://article.com/2-2
http://article.com/2-3 http://article.com/2-1
http://article.com/2-4 http://article.com/2-3
http://article.com/2-4 http://article.com/2-2
http://article.com/2-4 http://article.com/2-1
http://article.com/2-2 http://article.com/2-1
http://article.com/1-3 http://article.com/1-2
http://article.com/1-3 http://article.com/1-1
http://article.com/1-2 http://article.com/1-1

我们如何过滤查询,以便我们删除所有结果,其中?x值等于另一个结果中的?y值。通过这个,我们将得到

http://article.com/2-4 http://article.com/2-3
http://article.com/2-4 http://article.com/2-2
http://article.com/2-4 http://article.com/2-1

因为所有其他结果的?x值在另一个结果中作为?y值出现。

这是数据集:

<http://article.com/1-3> <http://relationship.com/wasGeneratedBy> <http://edit.com/comment1-2> .
<http://article.com/1-3> <http://relationship.com/wasRevisionOf> <http://article.com/1-2> .
<http://edit.com/comment1-2> <http://relationship.com/used> <http://article.com/1-2> .
<http://edit.com/comment1-2> <http://relationship.com/wasAssociatedWith> <http://editor.com/user1-1> .

<http://article.com/1-2> <http://relationship.com/wasGeneratedBy> <http://edit.com/comment1-1> .
<http://article.com/1-2> <http://relationship.com/wasRevisionOf> <http://article.com/1-1> .
<http://edit.com/comment1-1> <http://relationship.com/used> <http://article.com/1-1> .
<http://edit.com/comment1-1> <http://relationship.com/wasAssociatedWith> <http://editor.com/user1-1> .

<http://article.com/2-4> <http://relationship.com/wasGeneratedBy> <http://edit.com/comment2-3> .
<http://article.com/2-4> <http://relationship.com/wasRevisionOf> <http://article.com/2-3> .
<http://edit.com/comment2-3> <http://relationship.com/used> <http://article.com/2-3> .
<http://edit.com/comment2-3> <http://relationship.com/wasAssociatedWith> <http://editor.com/user2-3> .

<http://article.com/2-3> <http://relationship.com/wasGeneratedBy> <http://edit.com/comment2-2> .
<http://article.com/2-3> <http://relationship.com/wasRevisionOf> <http://article.com/2-2> .
<http://edit.com/comment2-2> <http://relationship.com/used> <http://article.com/2-2> .
<http://edit.com/comment2-2> <http://relationship.com/wasAssociatedWith> <http://editor.com/user2-2> .

<http://article.com/2-2> <http://relationship.com/wasGeneratedBy> <http://edit.com/comment2-1> .
<http://article.com/2-2> <http://relationship.com/wasRevisionOf> <http://article.com/2-1> .
<http://edit.com/comment2-1> <http://relationship.com/used> <http://article.com/2-1> .
<http://edit.com/comment2-1> <http://relationship.com/wasAssociatedWith> <http://editor.com/user2-1> .

1 个答案:

答案 0 :(得分:3)

select ?x ?y  where {?x <http://relationship.com/wasRevisionOf>+ ?y }
     

我们如何过滤查询,以便我们删除所有结果   a?x值等于另一个结果中的?y值。

如果一行中的?x值是另一行中的?y值,则表示?x是 wasRevisionOf 属性中某个三元组的对象。你可以简单地过滤掉那些:

select ?x ?y  where {
  ?x <http://relationship.com/wasRevisionOf>+ ?y
  filter not exists {
    ?something <http://relationship.com/wasRevisionOf> ?x
  }
}

这确保了?x的每个值都是链的“开头”。