2

I'm working with an OWL Ontology in Protégé 5.1.0 (plus HermiT 1.3.8.413 Reasoner) that I later want to use with OWLAPI 4.1.0 and maybe DL-Query or SPARQL. My task at hand is to get all Individuals of a class that have a certain Object Property unfulfilled. Because of the open-world assumption, an unfulfilled Object Property doesn't usually show up as a problem, but I need the information and would like to avoid writing my own code to check the whole ontology.

I prepared I small example, as readable text and Turtle-code:

Classes: Pizza, Topping

Object Property: has

Assertion: Pizza has some Topping

Individuals: Pizza1, Pizza2, Topping1, Topping2 (of respective Classes)

Assertion: Pizza1 has Topping1

Code:

@prefix : <http://www.semanticweb.org/user/ontologies/2017/0/untitled-ontology-23#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@base <http://www.semanticweb.org/user/ontologies/2017/0/untitled-ontology-23> .

<http://www.semanticweb.org/user/ontologies/2017/0/untitled-ontology-23> rdf:type owl:Ontology .

#################################################################
#    Object Properties
#################################################################

###  http://www.semanticweb.org/user/ontologies/2017/0/untitled-ontology-23#has
:has rdf:type owl:ObjectProperty ;
     owl:inverseOf :isOn .


###  http://www.semanticweb.org/user/ontologies/2017/0/untitled-ontology-23#isOn
:isOn rdf:type owl:ObjectProperty ,
               owl:FunctionalProperty .


#################################################################
#    Classes
#################################################################

###  http://www.semanticweb.org/user/ontologies/2017/0/untitled-ontology-23#Pizza
:Pizza rdf:type owl:Class ;
       rdfs:subClassOf [ rdf:type owl:Restriction ;
                         owl:onProperty :has ;
                         owl:someValuesFrom :Topping
                       ] .


###  http://www.semanticweb.org/user/ontologies/2017/0/untitled-ontology-23#Topping
:Topping rdf:type owl:Class .


#################################################################
#    Individuals
#################################################################

###  http://www.semanticweb.org/user/ontologies/2017/0/untitled-ontology-23#Pizza1
:Pizza1 rdf:type owl:NamedIndividual ,
                 :Pizza ;
        :has :Topping1 .


###  http://www.semanticweb.org/user/ontologies/2017/0/untitled-ontology-23#Pizza2
:Pizza2 rdf:type owl:NamedIndividual ,
                 :Pizza .


###  http://www.semanticweb.org/user/ontologies/2017/0/untitled-ontology-23#Topping1
:Topping1 rdf:type owl:NamedIndividual ,
                   :Topping ;
          :isOn :Pizza1 .


###  http://www.semanticweb.org/user/ontologies/2017/0/untitled-ontology-23#Topping2
:Topping2 rdf:type owl:NamedIndividual ,
                   :Topping .


#################################################################
#    General axioms
#################################################################

[ rdf:type owl:AllDifferent ;
  owl:distinctMembers ( :Pizza1
                        :Pizza2
                      )
] .


[ rdf:type owl:AllDifferent ;
  owl:distinctMembers ( :Topping1
                        :Topping2
                      )
] .


###  Generated by the OWL API (version 4.2.6.20160910-2108) https://github.com/owlcs/owlapi

In this case, I would like to query the ontology and get the information that Pizza2 currently doesn't have any Topping, i.e. its Object Property is not asserted or inferred. Also, if Topping1 is changed to be of a different class, I now want to see Pizza1 show up in the query as well because "Pizza has some Topping" is unsatisfied.

Is there an elegant way to do this either directly in OWLAPI or using DL-Query/SPARQL?

everdream
  • 100
  • 9
  • 1
    It's easier to use OWL API to look into the axioms for the necessary object properties `p_i` and then use SPARQL to query for individuals that do not have the data in the current ontology `SELECT ?ind WHERE {?ind a :the_class . FILTER NOT EXISTS {?ind :the_property ?o }}` – UninformedUser Jan 07 '17 at 18:40
  • By the way, in OWL terminology `Pizza has some Topping` is not an assertion – UninformedUser Jan 07 '17 at 18:41
  • 1
    On `SELECT ?p WHERE { ?p a :Pizza . FILTER NOT EXISTS {?p :has :Topping }}` I also get Pizza1 for some reason. Replacing `:Topping` with `?o` doesn't consider the class of the connected thing, however. Also, when I have various classes connected by this object property (e.g. topping, dough, and sauce), I would have to do this three times and then manually merge the results, correct? – everdream Jan 07 '17 at 19:36
  • Ah, sorry. We're talking about class restrictions: `SELECT ?p WHERE { ?p a :Pizza . FILTER NOT EXISTS {?p :has ?o . ?o rdf:type/rdfs:subClassOf* :Topping }}` – UninformedUser Jan 08 '17 at 12:28
  • You could use SPARQL 1.1 `VALUES` which is more a less a compact shortcut of `UNION`. – UninformedUser Jan 08 '17 at 12:30

0 Answers0