2016-05-14 100 views
-2

我有兩個where子句。此查詢中的邏輯錯誤?

PREFIX tourister: <PREFIX_VALUE> 
SELECT ?a 
WHERE { 
    {?a tourister:hasRating ?b . 
    ?b ?c '5'@string } . 
    {?a tourister:hasFeature ?b . 
    ?b ?c 'Pool'@string } 
} 

它們工作得很好,當對自己執行,或者如果他們之間有一個UNION條款,但是,我要尋找交集。從我在線閱讀的內容中,我發現,'.'可用於交集。但是,使用.,我得到0個結果。不,語法錯誤,邏輯錯誤。

而且,請注意,上述查詢中的PREFIX_VALUE不是錯誤,我故意省略了它。

<!-- http://tourister.space/ontologies/tourism#TESTInd --> 
 

 
    <owl:NamedIndividual rdf:about="http://tourister.space/ontologies/tourism#TESTInd"> 
 
     <rdf:type rdf:resource="http://tourister.space/ontologies/tourism#Hotel"/> 
 
     <hasFeature rdf:resource="http://tourister.space/ontologies/tourism#TESTIndFeature"/> 
 
     <hasRating rdf:resource="http://tourister.space/ontologies/tourism#TESTIndRating"/> 
 
    </owl:NamedIndividual> 
 
    
 

 

 
    <!-- http://tourister.space/ontologies/tourism#TESTIndFeature --> 
 

 
    <owl:NamedIndividual rdf:about="http://tourister.space/ontologies/tourism#TESTIndFeature"> 
 
     <rdf:type rdf:resource="http://tourister.space/ontologies/tourism#Feature"/> 
 
     <hasName xml:lang="string">Pool</hasName> 
 
    </owl:NamedIndividual> 
 
    
 

 

 
    <!-- http://tourister.space/ontologies/tourism#TESTIndRating --> 
 

 
    <owl:NamedIndividual rdf:about="http://tourister.space/ontologies/tourism#TESTIndRating"> 
 
     <rdf:type rdf:resource="http://tourister.space/ontologies/tourism#Rating"/> 
 
     <hasStarRating xml:lang="string">5</hasStarRating> 
 
    </owl:NamedIndividual>

+0

我們需要更多的細節。請參閱http://stackoverflow.com/help/mcve – AndyS

+0

爲什麼不能使用更簡單的查詢並刪除內部大括號?我建議你爲語言值使用一些適當的語言標籤,而不是'字符串' – AKSW

+0

RDF也是不正確的。 'XML:LANG = 「字符串」'??我建議不要手寫RDF/XML。這根本不是人類可讀的。 – scotthenninger

回答

0

很多事情不清楚數據和查詢。下面是一個更具可讀性和SPARQL友好的Turtle文本序列化的替代方案。我也得到了簡化模型,因爲它是不明確所需要的RatingFeature類(他們可以,並且可以很容易地被加回):

@prefix tourister: <http://example.org/ex#> . 

tourister:TESTInd 
    rdf:type tourister:Hotel ; 
    tourister:hasFeature "Pool"^^xsd:string ; 
    tourister:hasStarRating 5 . 
tourister:Hotel 
    rdf:type owl:Class ; 
    rdfs:subClassOf owl:Thing . 
tourister:hasFeature 
    rdf:type owl:DatatypeProperty ; 
    rdfs:range xsd:string . 
tourister:hasStarRating 
    rdf:type owl:DatatypeProperty ; 
    rdfs:range xsd:integer . 

從這一點看來,SPARQL找到以星級的5和一個游泳池的酒店被認爲幾乎是直接從第一組三元組:

SELECT ?hotel 
WHERE { 
    ?hotel tourister:hasFeature "Pool"^^xsd:string ; 
      tourister:hasStarRating 5 . 
} 

這只是一個開始,我不會是第一個建議做一點功課上RDF和SPARQL,然後再繼續。我認爲你會發現這條道路開始時比提高零散性問題的效率更高。