按空白节点分组

Grouping by blank nodes

我有以下数据:

@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 中执行以下查询:

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 查询以 return 只有两个不同的结果?我已经尝试 SELECT DISTINCT,但它仍然是 return 六个结果。我试过按 ?o 分组,但是 Blazegraph return 是一个错误,说这是一个错误的聚合。为什么会出现这种重复元组的输出呢?以及如何避免?

问题是您多次插入包含空白节点的数据。这个操作不是幂等的。

有用的名言

来自RDF 1.1 Concepts and Abstract Syntax

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 Semantics

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 Query Language

Blank node labels are scoped to a result set.

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 Update

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

一些讨论

不同的三元组为描述的“问题”提供了解决方案。例如,Jena allows 使用伪 URI,如 <_:b1>