Question

I'm playing with deriving instance type from its value information using value restrictions:

:SpaceMission rdf:type owl:Class .

:shuttleUsed rdf:type owl:ObjectProperty ;         
             rdfs:domain :SpaceMission .

:Apollo11 rdf:type owl:NamedIndividual .

:Mission11 rdf:type :SpaceMission , owl:NamedIndividual ;           
           :shuttleUsed :Apollo11 .

:ApolloMission rdf:type owl:Class ;               
               owl:equivalentClass [ rdf:type owl:Class ;
                                     owl:intersectionOf ( :SpaceMission
                                                          [ rdf:type owl:Restriction ;
                                                            owl:onProperty :shuttleUsed ;
                                                            owl:hasValue :Apollo11
                                                          ]
                                                        )
                                   ] .

The single value restriction owl:hasValue works fine and the SPARQL for type of :Mission11 returns :SpaceMission and :ApolloMission as expected. Then I add the second value restriction for definition of the class :ApolloMission:

:Apollo13 rdf:type owl:NamedIndividual .

:ApolloMission rdf:type owl:Class ;
               owl:equivalentClass [ rdf:type owl:Class ;
                                     owl:intersectionOf ( :SpaceMission
                                                          [ rdf:type owl:Restriction ;
                                                            owl:onProperty :shuttleUsed ;
                                                            owl:someValuesFrom [ rdf:type owl:Class ;
                                                                                 owl:oneOf ( :Apollo11
                                                                                             :Apollo13
                                                                                           )
                                                                               ]
                                                          ]
                                                        )
                                   ] .

(The restriction type has automatically changed from owl:hasValue to owl:someValuesFrom). In this case the expected inference of type :ApolloMission for the individual :Mission11 is not returned, but only the :SpaceMission. Do I have something wrong? Or the the type inference is only possible with value restriction of type owl:hasValue?

I'm using Jena's OWLMicroReasoner and running the SPARQL query for {<:Mission11> a ?type}. Maybe it is not able to infer from owl:someValuesFrom restriction. As I said the owl:hasValue restriction did work with Jena's micro reasoner. Does Jena's built-in reasoner support the owl:someValuesFrom restriction?

Was it helpful?

Solution

It's generally more helpful if you can provide an entire ontology that we can work with for testing. This one isn't too big, so it wasn't too hard to recreate. At any rate, I've reproduced it, and it's included at the end of this answer.

The inference is valid in OWL

The inference you're looking for is valid in OWL, and we can see that by using a logically complete OWL reasoner, e.g., Pellet. We'll see this in Protégé (but you could have used Pellet with Jena, too.) Here's what the ontology, recreated in Protégé look like:

important class axiom in Protege

important object property axiom in Protege

Then, when we enable the Pellet reasoner and ask for instances of ApolloMission, we get Mission11, as expected:

ApolloMission has Mission11 as an instance

Since you said you were asking for the types of Mission11, perhaps you used a query like asking for superclass of {Mission11}. This produces the expected classes, too:

Mission11 has the expected types

Reproduced Ontology

@prefix :      <http://stackoverflow.com/q/21223545/1281433/space.owl#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl:   <http://www.w3.org/2002/07/owl#> .
@prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix space: <http://stackoverflow.com/q/21223545/1281433/space.owl#> .

<http://stackoverflow.com/q/21223545/1281433/space.owl>
        a       owl:Ontology .

space:Mission11  a         owl:NamedIndividual , space:SpaceMission ;
        space:shuttleUsed  space:Apollo11 .

space:shuttleUsed  a  owl:ObjectProperty ;
        rdfs:domain  space:SpaceMission .

space:Apollo13  a  owl:Thing , owl:NamedIndividual .

space:ApolloMission  a       owl:Class ;
        owl:equivalentClass  [ a                   owl:Class ;
                               owl:intersectionOf  ( space:SpaceMission [ a                   owl:Restriction ;
                                                                          owl:onProperty      space:shuttleUsed ;
                                                                          owl:someValuesFrom  [ a          owl:Class ;
                                                                                                owl:oneOf  ( space:Apollo13 space:Apollo11 )
                                                                                              ]
                                                                        ] )
                             ] .

space:SpaceMission  a  owl:Class .

space:Apollo11  a  owl:Thing , owl:NamedIndividual .

Why you don't get some results with Jena's reasoners

Jena's reasoners are not complete. That doesn't mean that they're not finished; complete is a technical term in formal reasoning describing a reasoner (or algorithm, etc.) that means that there are correct inferences according to the semantics of the language that the reasoner won't produce. The reason that Jena's reasoners are incomplete has to do with the implementation strategy (using a rule-based reasoner), and with efficiency considerations (we can accept a trade-off between speed and the inferences that we can get).

For more about Jena's reasoners, you should look at Reasoners and rule engines: Jena inference support from the documentation. It's not entirely up to date though, as it says, for instance:

The critical constructs which go beyond OWL/lite and are not supported in the Jena OWL reasoner are complementOf and oneOf. As noted above the support for unionOf is partial (due to limitations of the rule based approach) but is useful for traversing class hierarchies.

but as the following code shows, there is, in fact, support for owl:oneOf in some of the reasoners, and so some of the reasoners can make the ApolloMission inference that you want.

Jena provides a number of reasoners, and the easiest way to get an OntModel that is connected to them is by using the static OntModelSpecs that are declared in OntModelSpec. The following Java code shows that with the final ontology that you provided, the different reasoners provide different results. (The reflective code for getting the different OntModelSpecs is a bit hackish, but for a quick example, it's fine.) The code constructs an OntModel for each of the declared specs starting with "OWL_", and runs the query against them.

import java.lang.reflect.Field;

import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;

public class JenaReasonersSpaceExample {
    private final static String QUERY =
            "PREFIX : <http://stackoverflow.com/q/21223545/1281433/space.owl#>\n" +
            "select ?type where {\n" +
            "  :Mission11 a ?type .\n" + 
            "}\n";

    private final static Model base =
            ModelFactory.createDefaultModel()
            .read( "file:///home/taylorj/tmp/ontologies/space/space.owl" );

    public static void main(final String[] args) throws IllegalArgumentException, IllegalAccessException {
        // Iterate through the fields of OntModelSpec and for each one whose name
        // begins with "OWL_", assume that it's a static field (so that getField
        // can accept null), and that its value is an OntModelSpec (so that we 
        // can cast and create an OntModel with it and the base model).
        // that begin with "OWL_", and assume t
        for ( final Field field : OntModelSpec.class.getFields() ) {
            if ( field.getName().startsWith("OWL_") ) {
                final OntModelSpec spec = (OntModelSpec) field.get(null);
                final OntModel model = ModelFactory.createOntologyModel( spec, base );

                // Run the query against the model (that will use the specified reasoner)
                // and show the field that we used and the results that we get.
                System.out.println( "\n=== "+field.getName()+" ===" );
                ResultSetFormatter.out(QueryExecutionFactory.create(QUERY, model).execSelect());
            }
        }
    }
}

The output follows. Some of the reasoners can infer that Mission11 is an ApolloMission. These are the ones used by the specs: OWL_MEM_RULE_INF, OWL_MEM_MINI_RULE_INF, OWL_DL_MEM_RULE_INF, and OWL_LITE_MEM_RULES_INF. It looks like you might want to stick to reasoners that have RULE in the name.

=== OWL_MEM ===
------------------------------------------------------------------------
| type                                                                 |
========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission> |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                      |
------------------------------------------------------------------------

=== OWL_MEM_RDFS_INF ===
------------------------------------------------------------------------
| type                                                                 |
========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission> |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                      |
| <http://www.w3.org/2000/01/rdf-schema#Resource>                      |
------------------------------------------------------------------------

=== OWL_MEM_TRANS_INF ===
------------------------------------------------------------------------
| type                                                                 |
========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission> |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                      |
------------------------------------------------------------------------

=== OWL_MEM_RULE_INF ===
-------------------------------------------------------------------------
| type                                                                  |
=========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission>  |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                       |
| <http://www.w3.org/2002/07/owl#Thing>                                 |
| _:b0                                                                  |
| <http://www.w3.org/2000/01/rdf-schema#Resource>                       |
| _:b1                                                                  |
| <http://stackoverflow.com/q/21223545/1281433/space.owl#ApolloMission> |
-------------------------------------------------------------------------

=== OWL_MEM_MICRO_RULE_INF ===
------------------------------------------------------------------------
| type                                                                 |
========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission> |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                      |
| <http://www.w3.org/2002/07/owl#Thing>                                |
| <http://www.w3.org/2000/01/rdf-schema#Resource>                      |
------------------------------------------------------------------------

=== OWL_MEM_MINI_RULE_INF ===
-------------------------------------------------------------------------
| type                                                                  |
=========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission>  |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                       |
| <http://www.w3.org/2002/07/owl#Thing>                                 |
| _:b0                                                                  |
| <http://www.w3.org/2000/01/rdf-schema#Resource>                       |
| _:b1                                                                  |
| <http://stackoverflow.com/q/21223545/1281433/space.owl#ApolloMission> |
-------------------------------------------------------------------------

=== OWL_DL_MEM ===
------------------------------------------------------------------------
| type                                                                 |
========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission> |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                      |
------------------------------------------------------------------------

=== OWL_DL_MEM_RDFS_INF ===
------------------------------------------------------------------------
| type                                                                 |
========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission> |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                      |
| <http://www.w3.org/2000/01/rdf-schema#Resource>                      |
------------------------------------------------------------------------

=== OWL_DL_MEM_TRANS_INF ===
------------------------------------------------------------------------
| type                                                                 |
========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission> |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                      |
------------------------------------------------------------------------

=== OWL_DL_MEM_RULE_INF ===
-------------------------------------------------------------------------
| type                                                                  |
=========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission>  |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                       |
| <http://www.w3.org/2002/07/owl#Thing>                                 |
| _:b0                                                                  |
| <http://www.w3.org/2000/01/rdf-schema#Resource>                       |
| <http://stackoverflow.com/q/21223545/1281433/space.owl#ApolloMission> |
| _:b1                                                                  |
-------------------------------------------------------------------------

=== OWL_LITE_MEM ===
------------------------------------------------------------------------
| type                                                                 |
========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission> |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                      |
------------------------------------------------------------------------

=== OWL_LITE_MEM_TRANS_INF ===
------------------------------------------------------------------------
| type                                                                 |
========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission> |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                      |
------------------------------------------------------------------------

=== OWL_LITE_MEM_RDFS_INF ===
------------------------------------------------------------------------
| type                                                                 |
========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission> |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                      |
| <http://www.w3.org/2000/01/rdf-schema#Resource>                      |
------------------------------------------------------------------------

=== OWL_LITE_MEM_RULES_INF ===
-------------------------------------------------------------------------
| type                                                                  |
=========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission>  |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                       |
| <http://www.w3.org/2002/07/owl#Thing>                                 |
| _:b0                                                                  |
| <http://www.w3.org/2000/01/rdf-schema#Resource>                       |
| <http://stackoverflow.com/q/21223545/1281433/space.owl#ApolloMission> |
| _:b1                                                                  |
-------------------------------------------------------------------------
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top