-1

This ontology has these classes and this number of triples. For completeness, here are the triples.

This query works as expected:

 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
 }

as shown here.

However, this query does not produce the expected results:

 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)
 }

A simplified version also fails:

 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 .
 }

These desired queries probably share the same fault:

 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
       }

and

 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 ] .
 }

and

 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 ] .
 }

What am I doing wrong?

Jay Gray
  • 1,706
  • 2
  • 20
  • 36

1 Answers1

1

Your simplified query:

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 .
 }

shouldn't return anything. In the data you linked to, pizza:NonVegetarianPizza only appears as an subject, never as an object. Did you have some reason to expect this query to return some results?

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • My goal was to identify the topping related to NonVegetarianPizza. The other queries have a similar goal. How should I re-write to produce those results? – Jay Gray Sep 06 '14 at 16:55
  • You'll need first to make precise what you mean by ‘related to'. – Joshua Taylor Sep 06 '14 at 16:57
  • I'll look at this again and be back to you: http://rhizomik.net/redefer-services/render?rdf=http://homepages.cs.ncl.ac.uk/phillip.lord/scratch/pizza.rdf&format=RDF/XML&mode=svg&rules=http://rhizomik.net:8080/html/redefer/rdf2svg/showclasshierarchy.jrule – Jay Gray Sep 06 '14 at 17:12
  • I looked at the graph and believe there is a solution for this: pizza with SweetPepperTopping and ParmesanTopping. How to compose that query (a variation of the last listed failed example) – Jay Gray Sep 06 '14 at 17:20
  • 1
    What do you mean that you believe that there's a solution for that? A pizza with SweetPepperTopping and ParmesanTopping isn't necessarily a NonVegetarianPizza or a non NonVegetarianPizza; it would depend on what else could be on the pizza. To get results about those sorts of things, you'll need to do OWL reasoning anyhow. You can do some limited kinds of OWL reasoning with a SPARQL query, but not arbitrary OWL reasoning. – Joshua Taylor Sep 06 '14 at 19:29
  • 2
    Note that (from the close reasons): "Questions seeking debugging help ("why isn't this code working?") must include the **desired behavior**, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers." I think you need to pin down some specific results you *expect* to get. Only then can we help to explain why you're not getting them and what you could do to get them. – Joshua Taylor Sep 06 '14 at 19:31