sparql - 花括号的使用

sparql - use of curly braces

您好,我有一个关于 sparql 查询的简单问题。 花括号对 where 子句有什么影响吗? 例如:

有区别吗
{
  ?s1 ab:wasBornIn "Berlin".
  ?s1 ?p1 ?o1
}
{
  ?s2 ab:someProperty "SomeLiteral".
  ?s2 ?p2 ?o2
}

{
  ?s1 ab:wasBornIn "Berlin".
  ?s1 ?p1 ?o1.
  ?s2 ab:someProperty "SomeLiteral".
  ?s2 ?p2 ?o2.
}

提前致谢

在很多情况下,没有区别

在您提供的示例中,没有区别。规范中其实是这么叫的:

5.2 Group Graph Patterns

In a SPARQL query string, a group graph pattern is delimited with braces: {}. For example, this query's query pattern is a group graph pattern of one basic graph pattern.

PREFIX foaf:    <http://xmlns.com/foaf/0.1/>
SELECT ?name ?mbox
WHERE  {
          ?x foaf:name ?name .
          ?x foaf:mbox ?mbox .
       }

The same solutions would be obtained from a query that grouped the triple patterns into two basic graph patterns. For example, the query below has a different structure but would yield the same solutions as the previous query:

PREFIX foaf:    <http://xmlns.com/foaf/0.1/>
SELECT ?name ?mbox
WHERE  { { ?x foaf:name ?name . }
         { ?x foaf:mbox ?mbox . }
       }

但可能有滤镜

不过,可以看出差异的地方在于过滤器:

A constraint, expressed by the keyword FILTER, is a restriction on solutions over the whole group in which the filter appears.

我认为这意味着

{ ?s ?p ?o1 }
{ ?s ?q ?o2
  filter( !isIri(?o1) )
}

不同于

{
  ?s ?p ?o1 .
  ?s ?q ?o2 .
  filter( !isIri(?o1) )
}

空白节点标签

它可能发挥作用的另一个地方是空白节点标签:

5.1.1 Blank Node Labels

When using blank nodes of the form _:abc, labels for blank nodes are scoped to the basic graph pattern. A label can be used in only a single basic graph pattern in any query.

例如,sparql.org 处的验证器将报告语法错误:

select * where {
  { _:s ?p ?o }
  { _:s ?p ?o }
}

Syntax error:

Line 3, column 5: Blank node label reuse not allowed at this point: _:s