2012-08-06 109 views
3

我正在做一個sparql查詢使用顆粒和我得到不同的結果,根據查詢中的三元組的順序,這是正確的?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_ 

我沒想到這個行爲,我不知道這是否是正確的,我是一個做出錯誤的查詢。任何人都可以向我解釋這個嗎?

回答

4

你應該得到與這兩個查詢相同的結果,改變三重模式的順序應該沒有什麼區別。這可能是查詢引擎中的一個錯誤。

3

正如Jan所建議的,純粹的SPARQL引擎不應因數據和查詢而給出不同的結果。

但是,您正在使用帶有嵌入式推理程序的SPARQL引擎的Pellet(儘管您不會說哪個版本)。這意味着如果SPARQL引擎可以通過推理器派生出它們,則它可以合法返回其他結果(請參見規範中的Extending SPARQL Basic Graph Pattern matching)。

事實上,查詢的一個版本會導致推理者進入而另一個版本不會有點奇怪,您應該向Pellet開發人員詢問一些事情。

+0

顆粒版本是2.3 – j0hn 2012-08-07 20:18:32

1

三重模式的順序不應改變結果。

什麼是您的查詢不尋常的,是在財產狀況中使用?rel

_TOP_DATA_PROPERTY_是可能的,Pellet引擎會在內部壓制 - 但如果?thing ?rel "Thing 4".是最後一個模式,數據不會再次通過Pellet,只是來自數據庫。

相關問題