Assuming two types of classes, one (A) "isManagedBy" by the other (B). The following owl snipped illustrates this scenario. There are multiple classes of type A (which are "managed by" other classes) and multiple classes of B. In fact, there is also a hierarchy between between classes bot of type A and B.
<owl:ObjectProperty rdf:about="#isManagedBy"/>
<owl:Class rdf:about="#FunctionManagement">
<rdfs:subClassOf rdf:resource="..."/>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#isManagedBy"/>
<owl:someValuesFrom rdf:resource="#SymposiumPlanner2013"/>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
<owl:Class rdf:about="#SymposiumPlanner2013"/>
...
Problem: Get all classes of type B given an arbitrary class A.
Idea: Iterate over all classes of type B. For each class B, check whether a given A has an ObjectProperty "isManagedBy" (directly or inherited) to class B by using a Reasoner's isSatisfiable() method.
OWLObjectProperty objProp = df.getOWLObjectProperty(IRI.create("#isManagedBy"));
OWLClassExpression expression;
for (OWLClass B : SetOfAllBs) {
expression = df.getOWLObjectIntersectionOf(A, df.getOWLObjectSomeValuesFrom(objProp, B));
if (reasoner.isSatisfiable(expression)) {
// do something
}
}
Unfortunately, the reasoner returns satisfiable for all classes of type B.
Question: How to solve this problem?
You don't want to check for satisfiability here, as it only tells you if you would be able to have an instance of that class. What you are after are actual instances of it. As there might be a hierarchy of classes, you want to use:
which will give you direct and indirect instances.
Edit: from comments, looks like you are after subclasses of A that are in the domain of isManagedBy, or for which restrictions over isManagedBy have subclasses of B as range.
Something like
reasoner.getSubClasses(expression, false)
might be closer to what you expect to see.I can suggest two solutions to your problem:
Go through all Bs, but instead check satisfiability of
A and (isManagedBy only (not B))
. If this expression is unsatisfiable for some B, then such B has to be connected with a given A viaisManagedBy
.If you are using FaCT++ for reasoning, you can use the
OWLKnowledgeExplorerReasoner
interface to explore the models produced during the satisfiability check of a class A. The idea is that if such B present in the model, then it has to be connected to A. There are some limitations (it might not work for Bs defined via EquivalentClasses(B,...), it is not always true for non-deterministic labels (see flag true in the getObjectLabel() call), but here is an idea. The code might looks like: