簡體   English   中英

sparql查詢中三元組的順序是否會影響結果?

[英]Does the order of the triples in a sparql query affect the result?

我正在使用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_

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

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

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

但是,您正在使用具有嵌入式推理器的SPARQL引擎的Pellet(盡管您沒有說哪個版本)。 這意味着如果SPARQL引擎可以通過推理器派生它們,則可以合法地返回其他結果(請參閱規范中的擴展SPARQL基本圖形模式匹配 )。

事實上,一個版本的查詢導致推理器啟動而另一個版本沒有,這有點奇怪,你應該向Pellet開發人員詢問。

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

你的查詢有什么不尋常之處,就是在屬性位置使用?rel

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM