Search code examples
sparqlsemanticssemantic-webprotege4

Protege Equivalent to query


Please help to list all Mealcourse from the wine Ontology or happy to receive useful links like this one :Sparql query on restriction list (Equivalent To) in protégé

MealCourse and (hasFood value Pizza) and(hasDrink value Wine)

Thank you


Solution

  • This is a bit complicated, but if you look into the ontology everything that is defined as a :MealCourse is an owl:equivalentClass, so you need to first find all owl:equivalentClass and then if you look into the result you will see that they are made of owl:intersectionOf parts. Then you need to break this intersection and filter so that you will only get objects that have :MealCourse as part of the intersection.

    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    PREFIX owl: <http://www.w3.org/2002/07/owl#>
    PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    PREFIX : <http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#>
    SELECT distinct *
        WHERE { ?subject owl:equivalentClass ?object. 
        ?object (owl:intersectionOf | owl:unionOf) ?node.
        ?node rdf:rest*/rdf:first ?eq.
        Filter ( ?eq in (:MealCourse ) )
    }
    orderBy ?subject