public class QueryingClassSatisfiability {
public static void main(String[] args) throws OWLOntologyCreationException {
OWLOntologyManager man = OWLManager.createOWLOntologyManager();
OWLDataFactory dataFactory = man.getOWLDataFactory();
// Load your ontology.
OWLOntology ont = man.loadOntologyFromOntologyDocument(new File(
"/path/to/pizza.owl"));
// Create an ELK reasoner.
OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
OWLReasoner reasoner = reasonerFactory.createReasoner(ont);
// Create your desired query class expression. In this example we
// will query ObjectIntersectionOf(A ObjectComplementOf(ObjectSomeValuesFrom(R B))).
PrefixManager pm = new DefaultPrefixManager(
"http://www.co-ode.org/ontologies/pizza/pizza.owl#");
OWLClass A = dataFactory.getOWLClass(":American", pm);
OWLObjectProperty R = dataFactory.getOWLObjectProperty(":hasTopping",
pm);
OWLClass B = dataFactory.getOWLClass(":MeatTopping", pm);
OWLClassExpression query = dataFactory.getOWLObjectIntersectionOf(A,
dataFactory.getOWLObjectComplementOf(dataFactory
.getOWLObjectSomeValuesFrom(R, B)));
System.out.println("isSatisfiable(" + query + ") = "
+ reasoner.isSatisfiable(query));
reasoner.dispose();
}
}
Here is the output:
isSatisfiable(ObjectIntersectionOf(<http://www.co-ode.org/ontologies/pizza/pizza.owl#American> ObjectComplementOf(ObjectSomeValuesFrom(<http://www.co-ode.org/ontologies/pizza/pizza.owl#hasTopping> <http://www.co-ode.org/ontologies/pizza/pizza.owl#MeatTopping>)))) = false
If I change
OWLClass A = dataFactory.getOWLClass(":American", pm);
to
OWLClass A = dataFactory.getOWLClass(":Margherita", pm);
the output is:
isSatisfiable(ObjectIntersectionOf(<http://www.co-ode.org/ontologies/pizza/pizza.owl#Margherita> ObjectComplementOf(ObjectSomeValuesFrom(<http://www.co-ode.org/ontologies/pizza/pizza.owl#hasTopping> <http://www.co-ode.org/ontologies/pizza/pizza.owl#MeatTopping>)))) = true
as expected.
Can you test this code if it works for you?
Best regards,
Yevgeny