}
}
public NodeSet<OWLNamedIndividual> getInstances(OWLClassExpression classExpression,boolean direct) {
checkPreConditions(classExpression);
if (!m_isConsistent) {
Node<OWLNamedIndividual> node=new OWLNamedIndividualNode(getAllNamedIndividuals());
return new OWLNamedIndividualNodeSet(Collections.singleton(node));
}
realise();
Set<Individual> result=new HashSet<Individual>();
if (classExpression instanceof OWLClass) {
AtomicConcept concept=H((OWLClass)classExpression);
Set<Individual> directInstances=m_realization.get(concept);
if (directInstances!=null)
for (Individual instance : directInstances)
if (isResultRelevantIndividual(instance))
result.add(instance);
if (!direct) {
HierarchyNode<AtomicConcept> node=m_atomicConceptHierarchy.getNodeForElement(concept);
if (node!=null)
for (HierarchyNode<AtomicConcept> descendantNode : node.getDescendantNodes())
loadIndividualsOfNode(descendantNode,result);
}
}
else {
HierarchyNode<AtomicConcept> hierarchyNode=getHierarchyNode(classExpression);
loadIndividualsOfNode(hierarchyNode,result);
if (!direct)
for (HierarchyNode<AtomicConcept> descendantNode : hierarchyNode.getDescendantNodes())
loadIndividualsOfNode(descendantNode,result);
OWLDataFactory factory=getDataFactory();
OWLClass queryClass=factory.getOWLClass(IRI.create("internal:query-concept"));
OWLAxiom queryClassDefinition=factory.getOWLSubClassOfAxiom(queryClass,classExpression.getObjectComplementOf());
Tableau tableau=getTableau(queryClassDefinition);
AtomicConcept queryConcept=AtomicConcept.create("internal:query-concept");
Set<HierarchyNode<AtomicConcept>> visitedNodes=new HashSet<HierarchyNode<AtomicConcept>>(hierarchyNode.getChildNodes());
List<HierarchyNode<AtomicConcept>> toVisit=new ArrayList<HierarchyNode<AtomicConcept>>(hierarchyNode.getParentNodes());
while (!toVisit.isEmpty()) {
HierarchyNode<AtomicConcept> node=toVisit.remove(toVisit.size()-1);
if (visitedNodes.add(node)) {
AtomicConcept nodeAtomicConcept=node.getRepresentative();
Set<Individual> realizationForNodeConcept=m_realization.get(nodeAtomicConcept);
if (realizationForNodeConcept!=null)
for (Individual individual : realizationForNodeConcept)
if (isResultRelevantIndividual(individual))
if (!tableau.isSatisfiable(true,true,Collections.singleton(Atom.create(queryConcept,individual)),null,null,null,null,ReasoningTaskDescription.isInstanceOf(individual,classExpression)))
result.add(individual);
toVisit.addAll(node.getChildNodes());
}
}
}
return sortBySameAsIfNecessary(result);
}