按空白节点分组 [英] Grouping by blank nodes

查看:116
本文介绍了按空白节点分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下数据:

@prefix f: <http://example.org#> .

_:a f:trait "Rude"@en .
_:a f:name "John" .
_:a f:surname "Roy" .
_:b f:trait "Crude"@en .
_:b f:name "Mary" .
_:b f:surname "Lestern" .

但是,如果我在 Blazegraph 中执行以下查询:

However, if I execute the following query in Blazegraph:

PREFIX f: <http://example.org#>

SELECT ?s ?o
WHERE
{
    ?s f:trait ?o .
}

我得到六个结果:

s   o
t32 Crude
t37 Crude
t39 Crude
t31 Rude
t36 Rude
t38 Rude

如果空白节点_:a_:b是不同的节点,我应该如何编写SPARQL查询以仅返回两个不同的结果?我已经尝试过SELECT DISTINCT,但是它仍然返回六个结果.我曾尝试按?o进行分组,但是 Blazegraph 返回错误,并指出这是错误的汇总.为什么会出现这种重复元组的输出?以及如何避免呢?

If blank nodes _:a and _:b are distinct nodes, how should I write a SPARQL query to return only two distinct results? I have tried SELECT DISTINCT, but it still returns six results. I have tried grouping by ?o, but Blazegraph returns an error, saying it's a bad aggregate. Why does this kind of output of repeating tuples happen? And how to avoid it?

推荐答案

问题是您多次插入了包含空白节点的数据.此操作不是幂等的.

The problem is that you have inserted data containing blank nodes several times. This operation is not idempotent.

有用的报价

来自 RDF 1.1概念和摘要语法:

空白节点标识符是在某些具体的RDF语法或RDF存储实现中使用的本地标识符.它们始终是本地范围内的文件或RDF存储,而不是空白节点的持久或可移植标识符.

Blank node identifiers are local identifiers that are used in some concrete RDF syntaxes or RDF store implementations. They are always locally scoped to the file or RDF store, and are not persistent or portable identifiers for blank nodes.

来自 RDF 1.1语义:

RDF图可以看作是一阶逻辑中简单原子语句的结合,其中空白节点是自由变量,被认为是存在的.然后,将两个图进行并集就类似于此语法中的语法合取. RDF语法没有显式的变量绑定量词,因此任何RDF图的真实条件都将该图中的自由变量视为该图中存在的量化值.对具有空白节点的图进行并集会更改隐含的量词范围.

RDF graphs can be viewed as conjunctions of simple atomic sentences in first-order logic, where blank nodes are free variables which are understood to be existential. Taking the union of two graphs is then analogous to syntactic conjunction in this syntax. RDF syntax has no explicit variable-binding quantifiers, so the truth conditions for any RDF graph treat the free variables in that graph as existentially quantified in that graph. Taking the union of graphs which share a blank node changes the implied quantifier scopes.

来自 SPARQL 1.1查询语言:

空白节点标签的作用域是结果集.

Blank node labels are scoped to a result set.

结果集中的标签_:a与具有相同标签的数据图中的空白节点之间不必存在任何关系.

There need not be any relation between a label _:a in the result set and a blank node in the data graph with the same label.

应用程序编写者不应期望查询中的空白节点标签引用数据中的特定空白节点.

An application writer should not expect blank node labels in a query to refer to a particular blank node in the data.

来自 SPARQL 1.1更新:

空白节点...假定与图形存储区中的空白节点不相交,即将插入新鲜"标记.空白节点.

Blank nodes... are assumed to be disjoint from the blank nodes in the Graph Store, i.e., will be inserted with "fresh" blank nodes.

一些讨论

  • Problems of the RDF Model: Blank Nodes
  • Blank nodes considered harmful

不同的三重存储为解决问题"提供了解决方案.描述.例如,Jena 允许使用伪URI,例如<_:b1>

Different triplestores provides solutions for the "problems" described. E.g., Jena allows to use pseudo-URIs like <_:b1> etc.

这篇关于按空白节点分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆