SPARQL: Dividing a BGP into multiple Groups

2020-05-09 17:06发布

In a previous question, a comment suggests that

 select ?x  ?y where {
      {?x rdf:type ex:someType}        
      {?x ex:someProperty ?y}
    }

is like (not identical) to:

select ?x  ?y where {
  ?x rdf:type ex:someType.
  ?x ex:someProperty ?y.
}

Same triple patterns are used. However, the first query contains two BGPs (each one in a group pattern), while the second contains one BGP (no group patterns). The algebra for the first query is a JOIN between two BGPs while the algebra of the second is only a BGP.

First query algebra (Apache Jena)

(project (?x ?y)
  (join
    (bgp (triple ?x <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.com/someType>))
    (bgp (triple ?x <http://www.example.com/someProperty> ?y))))

Second query algebra (Apache Jena):

(project (?x ?y)
  (bgp
    (triple ?x <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.com/someType>)
    (triple ?x <http://www.example.com/someProperty> ?y)
  ))

In the original question, the answer suggest that they are not identical and argues

  1. If the SPARQL entailment is supported, then the separate {} are evaluated for entailment separately.
  2. if you use labels bnodes in queries there restrictions cross {}
  3. if you add FILTERS, then they do not apply outside the {} they are written in.
  4. its a different abstract syntax tree. All minor points but which may come into play later.

Now let's put the blank nodes (2) and the different syntax trees aside (4), and ask the following: Would the two queries, in any case, yield different results because of filter (3) or entailment(1)? I do not see any possibility for that. Well, those who have a different opinion, may you, please show with some example?

标签: sparql
1条回答
ゆ 、 Hurt°
2楼-- · 2020-05-09 17:37

Scope of FILTER is affected.

In:

   select ?x  ?y where {
        {?x rdf:type ex:someType FILTER (?y > 0 ) }        
        {?x ex:someProperty ?y}
   }

The FILTER is false always because ?y is unbound so the expression is error and the FILTER is false regardless of the ?x ex:someProperty ?y.

(3) and (4) are related.

查看更多
登录 后发表回答