sparql - 使用花括号

emr*_*kan 3 rdf semantic-web sparql

你好,我有一个关于sparql查询的简单问题.大括号对where子句有什么影响吗?例如:两者之间是否存在差异

{
  ?s1 ab:wasBornIn "Berlin".
  ?s1 ?p1 ?o1
}
{
  ?s2 ab:someProperty "SomeLiteral".
  ?s2 ?p2 ?o2
}
Run Code Online (Sandbox Code Playgroud)

{
  ?s1 ab:wasBornIn "Berlin".
  ?s1 ?p1 ?o1.
  ?s2 ab:someProperty "SomeLiteral".
  ?s2 ?p2 ?o2.
}
Run Code Online (Sandbox Code Playgroud)

提前致谢

Jos*_*lor 7

在许多情况下,没有区别

在你给出的例子中,没有区别.这实际上是在规范中调用的:

5.2组图模式

在SPARQL查询字符串中,组图模式使用大括号分隔:{}.例如,此查询的查询模式是一个基本图形模式的组图模式.

PREFIX foaf:    <http://xmlns.com/foaf/0.1/>
SELECT ?name ?mbox
WHERE  {
          ?x foaf:name ?name .
          ?x foaf:mbox ?mbox .
       }
Run Code Online (Sandbox Code Playgroud)

从将三重模式分组为两个基本图形模式的查询中获得相同的解决方案.例如,下面的查询具有不同的结构,但会产生与上一个查询相同的解决方案:

PREFIX foaf:    <http://xmlns.com/foaf/0.1/>
SELECT ?name ?mbox
WHERE  { { ?x foaf:name ?name . }
         { ?x foaf:mbox ?mbox . }
       }
Run Code Online (Sandbox Code Playgroud)

但可能有过滤器

但是,如果有可能看到差异,则使用过滤器:

由关键字FILTER表示的约束是对出现过滤器的整个组的解决方案的限制.

我认为这意味着

{ ?s ?p ?o1 }
{ ?s ?q ?o2
  filter( !isIri(?o1) )
}
Run Code Online (Sandbox Code Playgroud)

不同于

{
  ?s ?p ?o1 .
  ?s ?q ?o2 .
  filter( !isIri(?o1) )
}
Run Code Online (Sandbox Code Playgroud)

空白节点标签

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

5.1.1空白节点标签

使用_:abc形式的空白节点时,空白节点的标签范围限定为基本图形模式.在任何查询中,标签只能用于单个基本图形模式.

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

select * where {
  { _:s ?p ?o }
  { _:s ?p ?o }
}
Run Code Online (Sandbox Code Playgroud)

语法错误:

Line 3, column 5: Blank node label reuse not allowed at this point: _:s
Run Code Online (Sandbox Code Playgroud)