2

With the following snippet from the pizza ontology:

<owl:Class rdf:about="http://www.co-ode.org/ontologies/pizza/pizza.owl#Pizza">
   <rdfs:subClassOf rdf:resource="http://www.co-ode.org/ontologies/pizza/pizza.owl#Food"/>
        <rdfs:subClassOf>
            <owl:Restriction>
                <owl:onProperty rdf:resource="http://www.co-ode.org/ontologies/pizza/pizza.owl#hasBase"/>
                <owl:someValuesFrom rdf:resource="http://www.co-ode.org/ontologies/pizza/pizza.owl#PizzaBase"/>
            </owl:Restriction>
        </rdfs:subClassOf>
        <rdfs:label xml:lang="en">Pizza</rdfs:label>
        <rdfs:seeAlso rdf:resource="https://en.wikipedia.org/wiki/Pizza"/>
        <skos:prefLabel xml:lang="en">Pizza</skos:prefLabel>
    </owl:Class>

I see from this that the following triple exists: <Pizza, hasBase, PizzaBase> representing <subject, predicate, object>

How do I write SPARQL to extract the the PizzaBase object or any object from a triplet when the entity and relation are known?

Note: I am equating subject as entity and predicate as relation

Update: Let me simplify my question. Based on the given RDF above and the following RDF graph:

enter image description here

What would be the SPARQL to extract the PizzaBase entity given the Pizza entity and the hasBase relation?

gedman
  • 63
  • 5
  • 1
    nope, there is no triple `` - that's a misunderstanding. There is a path, but this is resolved via several connected RDF triples: `Pizza, subClassOf, restriction. restriction onProperty hasBase . restriction someValuesFrom PizzaBase .` - this is what you have to translate to SPARQL triple patterns. So what did you try so far? – UninformedUser Nov 08 '21 at 07:17
  • See update above – gedman Nov 08 '21 at 15:14
  • you RDF graph is just wrong or at least misleading - there is no direct edge which indicates a single RDF triple between Pizza and class. `Pizza` is a class and so is `PizzaBase` - and the connection is expressed via OWL not RDF. Many OWL constructs are represented by multiple RDF triples. – UninformedUser Nov 09 '21 at 06:42
  • Also, what SPARQL query did you try so far? I mean, are you able to write any SPARQL query? Otherwise it will be hard to understand or even adapt a query – UninformedUser Nov 09 '21 at 06:43
  • 1
    Anyways, and good luck: `PREFIX owl: SELECT ?cls WHERE { rdfs:subClassOf [ owl:onProperty ; owl:someValuesFrom ?cls ] .}` – UninformedUser Nov 09 '21 at 06:46

1 Answers1

0

Enclose known subjects in <> tags. It's also possible to use SPARQL BIND to bind the URI to a variable. For predicates just be sure to prefix them, shown below.

Assuming that you know the identifier of the Pizza node, it should be...

PREFIX pizza: <http://www.co-ode.org/ontologies/pizza/pizza.owl#>
SELECT ?pizzaBase WHERE { 
   <pizza> pizza:hasBase ?pizzaBase .
}

To get all pizza bases from pizzas, you can do...

PREFIX pizza: <http://www.co-ode.org/ontologies/pizza/pizza.owl#>
SELECT ?pizza ?pizzaBase WHERE { 
   ?pizza pizza:hasBase ?pizzaBase .
}
Thomas
  • 720
  • 9
  • 22
  • I tried the first SPARQL query and it doesn't work. – gedman Nov 08 '21 at 22:36
  • What did you try? When I load your RDF snippet into Protoge I don't see any named individuals. So there's of course is no URI. Instead you have a CLASS defined. All you can really ask are things about the class like "Give me all the nodes of type Pizza" or "Give me the pizza base of all nodes of type Pizza". When you have individuals defined, place the URI in brackets and it should work. – Thomas Nov 08 '21 at 22:46
  • 1
    guys, according to my comment below the question, that does not work ... pizzas are classes, the base is connected via a property restriction, thus you have to query the subclassof axioms. Again ,the RTDF triples are like that: `Pizza, subClassOf, restriction. restriction onProperty hasBase . restriction someValuesFrom PizzaBase .` - just translate it to triple patterns and you're done. – UninformedUser Nov 09 '21 at 06:39
  • Thanks for your responses. UniformedUser has it right. I never mentioned anything about named individuals, I wasn't interested in that. – gedman Nov 09 '21 at 20:30