2016-05-14 64 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,然后再继续。我认为你会发现这条道路开始时比提高零散性问题的效率更高。