SPARQL查询失败

时间:2014-09-06 12:13:57

标签: rdf sparql owl linked-data

ontology包含classes这个triples的数量。为了完整起见,这里是triples

此查询按预期工作:

 PREFIX pizza: <http://www.ncl.ac.uk/pizza#>
 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
 SELECT ?p
 FROM <http://homepages.cs.ncl.ac.uk/phillip.lord/scratch/pizza.rdf>
 WHERE {
  ?p rdfs:subClassOf pizza:PizzaTopping
 }

如图所示here

但是,此查询不会产生预期结果:

 PREFIX pizza: <http://www.ncl.ac.uk/pizza#>
 PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX owl: <http://www.w3.org/2002/07/owl#>
 SELECT DISTINCT *
 FROM <http://homepages.cs.ncl.ac.uk/phillip.lord/scratch/pizza.rdf>
 WHERE { 
 ?Name ?Relation pizza:MushroomTopping .
 ?Relation owl:inverseOf pizza:isToppingOf .
 OPTIONAL { 
  ?Name2 ?Relation2 pizza:HamTopping .
  ?Relations2 owl:inverseOf pizza:isToppingOf . 
 }
 FILTER(?Name2 = ?PizzaName)
 }

简化版也失败了:

 PREFIX pizza: <http://www.ncl.ac.uk/pizza#>
 PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX owl: <http://www.w3.org/2002/07/owl#>
 SELECT *
 FROM <http://homepages.cs.ncl.ac.uk/phillip.lord/scratch/pizza.rdf>
 WHERE { 
 ?Name ?Relation pizza:NonVegetarianPizza .
 }

这些期望的查询可能共享相同的错误:

 PREFIX pizza: <http://www.ncl.ac.uk/pizza#>
 PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 SELECT *
 FROM <http://homepages.cs.ncl.ac.uk/phillip.lord/scratch/pizza.rdf>
 WHERE { ?p rdf:type pizza:Pizza;
            pizza:hasTopping ?t.
         ?t rdf:type pizza:TomatoTopping
       }

 PREFIX pizza: <http://www.ncl.ac.uk/pizza#>
 PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
 PREFIX owl: <http://www.w3.org/2002/07/owl#>
 SELECT *
 FROM <http://homepages.cs.ncl.ac.uk/phillip.lord/scratch/pizza.rdf>
 WHERE
 {
  ?pizza rdfs:subClassof [
  owl:onProperty pizza:hasTopping;
  owl:someValuesFrom pizza:MushroomTopping ] .
 }

 PREFIX pizza: <http://www.ncl.ac.uk/pizza#>
 PREFIX owl:<http://www.w3.org/2002/07/owl#>
 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
 SELECT *
 FROM <http://homepages.cs.ncl.ac.uk/phillip.lord/scratch/pizza.rdf>
 WHERE
 {
  ?pizza rdfs:subClassOf [
    owl:onProperty pizza:hasTopping;
    owl:someValuesFrom pizza:MozzarellaTopping ] .
  ?pizza rdfs:subClassof [
    owl:onProperty pizza:hasTopping;
    owl:someValuesFrom pizza:PeperonSausageTopping ] .
  ?pizza rdfs:subClassof [
    owl:onProperty pizza:hasTopping;
    owl:someValuesFrom pizza:TomatoTopping ] .
 }

我做错了什么?

1 个答案:

答案 0 :(得分:1)

您的简化查询:

PREFIX pizza: <http://www.ncl.ac.uk/pizza#>
 PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX owl: <http://www.w3.org/2002/07/owl#>
 SELECT *
 FROM <http://homepages.cs.ncl.ac.uk/phillip.lord/scratch/pizza.rdf>
 WHERE { 
 ?Name ?Relation pizza:NonVegetarianPizza .
 }

不应该退货。在您链接到的数据中,pizza:NonVegetarianPizza仅作为主题显示,而不是作为对象显示。您是否有理由期望此查询返回一些结果?