sparql查询中三元组的顺序是否会影响结果?

时间:2012-08-06 19:03:10

标签: rdf sparql pellet n-triples

我正在使用 pellet 进行sparql查询,并且根据查询中三元组的顺序得到不同的结果,这是正确的吗?

例如,给定以下N-Triples数据输入:

<http://example.com/thing1> <http://example.com/hasDefinition> <http://example.com/def_thing1> .
<http://example.com/thing1> <http://www.w3.org/2000/01/rdf-schema#label> "Thing 1" .
<http://example.com/def_thing1> <http://www.w3.org/2000/01/rdf-schema#comment> "thing 1 it's awesome".

<http://example.com/thing2> <http://example.com/hasDefinition> <http://example.com/def_thing2> .
<http://example.com/thing2> <http://www.w3.org/2000/01/rdf-schema#label> "Thing 2" .
<http://example.com/def_thing2> <http://www.w3.org/2000/01/rdf-schema#comment> "thing 1 it's cool".

<http://example.com/thing3> <http://example.com/hasDefinition> <http://example.com/def_thing3> .
<http://example.com/thing3> <http://www.w3.org/2000/01/rdf-schema#label> "Thing 3" .
<http://example.com/def_thing3> <http://www.w3.org/2000/01/rdf-schema#comment> "thing 3 it's fine".

<http://example.com/thing4> <http://example.com/hasDefinition> <http://example.com/def_thing4> .
<http://example.com/thing4> <http://www.w3.org/2000/01/rdf-schema#label> "Thing 4" .
<http://example.com/def_thing4> <http://www.w3.org/2000/01/rdf-schema#comment> "thing 4 it's exactly what i need".

以下查询:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX example: <http://example.com/>

SELECT * WHERE {
    ?thing ?rel "Thing 4".
    ?thing example:hasDefinition ?def.
    ?def rdfs:comment ?definition.
}

返回:

Query Results (1 answers): 
thing  | rel   | def        | definition                        
================================================================
thing4 | label | def_thing4 | "thing 4 it's exactly what i need"

但是以下查询(只是对前一个的更改):

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX example: <http://example.com/>

SELECT * WHERE {
    ?thing example:hasDefinition ?def.
    ?def rdfs:comment ?definition.
    ?thing ?rel "Thing 4".
}

我得到以下答案:

Query Results (5 answers): 
thing  | def        | definition                         | rel                
==============================================================================
thing4 | def_thing4 | "thing 4 it's exactly what i need" | _TOP_DATA_PROPERTY_
thing4 | def_thing4 | "thing 4 it's exactly what i need" | label              
thing1 | def_thing1 | "thing 1 it's awesome"             | _TOP_DATA_PROPERTY_
thing2 | def_thing2 | "thing 1 it's cool"                | _TOP_DATA_PROPERTY_
thing3 | def_thing3 | "thing 3 it's fine"                | _TOP_DATA_PROPERTY_

我没想到这种行为,我不知道它是否正确,我是那个做出错误查询的人。任何人都可以向我解释这个吗?

3 个答案:

答案 0 :(得分:4)

这两个查询肯定会得到相同的结果,改变三重模式的顺序应该没有区别。这可能是查询引擎中的错误。

答案 1 :(得分:3)

正如Jan所说,纯粹的SPARQL引擎不应该根据数据和查询给出不同的结果。

但是,您正在使用具有嵌入式推理器的SPARQL引擎的Pellet(尽管您没有说哪个版本)。这意味着如果SPARQL引擎可以通过推理器派生它们,则可以合法地返回其他结果(请参阅规范中的Extending SPARQL Basic Graph Pattern matching)。

事实上,一个版本的查询导致推理器启动而另一个版本没有,这有点奇怪,你应该向Pellet开发人员询问。

答案 2 :(得分:1)

三重模式的顺序不应改变结果。

您的查询有什么不寻常之处,就是在属性位置使用?rel

_TOP_DATA_PROPERTY_可能是Pellet引擎在内部抑制的东西 - 但如果?thing ?rel "Thing 4".是最后一个模式,则数据不会再次通过Pellet,只来自数据库。