private void addCycles(HashSet<Set<T>> forCycles) { for (Set<T> entity : forCycles) { DefaultNode<T> node = createNode(entity); for (T cls : entity) { cycles.put(cls, node); Set<T> rawSupers = new HashSet<T>(rawHierarchyProvider.getParents(cls)); rawSupers.removeAll(node.getEntities()); if (rawSupers.isEmpty()) { roots.add(cls); } } } roots.remove(topEntity); }
public Set<T> getEntitiesInSignature(Set<OWLAxiom> axioms) { Set<T> result = new HashSet<T>(); for(OWLAxiom ax : axioms) { result.addAll(getEntitiesInSignature(ax)); } return result; }
public NodeSet<T> getNodeHierarchyParents(T child, boolean direct, DefaultNodeSet<T> ns) { if(child.equals(topEntity)) { return ns; } Collection<T> parents = getParentsInternal(child, null); for (Iterator<T> parIt = parents.iterator(); parIt.hasNext();) { T par = parIt.next(); Node<T> cycleNode = cycles.get(par); if (cycleNode != null) { ns.addNode(cycleNode); parIt.remove(); } else { ns.addEntity(par); } if (!direct) { getNodeHierarchyParents(par, direct, ns); } } return ns; }
tarjan(superEntity, index, stack, indexMap, lowlinkMap, result, processed, stackEntities, cache, childrenOfTop, parentsOfBottom); lowlinkMap.put(entity, Math.min(lowlinkMap.get(entity), lowlinkMap.get(superEntity)));
if (!processed.contains(entity)) { pm.reasonerTaskProgressChanged(processed.size(), signature.size()); tarjan(entity, 0, new Stack<T>(), new HashMap<T, Integer>(), new HashMap<T, Integer>(), cyclesResult, processed, new HashSet<T>(), cache, equivTopOrChildrenOfTop, equivBottomOrParentsOfBottom); throwExceptionIfInterrupted();
stackEntities.add(entity); Collection<T> parents = getParentsInternal(entity, cache); if (parents.isEmpty()) { roots.add(entity); tarjan(superEntity, index, stack, indexMap, lowlinkMap, result, processed, stackEntities, cache); lowlinkMap.put(entity, Math.min(lowlinkMap.get(entity), lowlinkMap.get(superEntity)));
public NodeSet<T> getNodeHierarchyParents(T child, boolean direct, DefaultNodeSet<T> ns) { Node<T> node = nodeCache.getNode(child); if (node.isTopNode()) { return ns; } Set<T> directParents = new HashSet<T>(); for (T equiv : node) { directParents.addAll(rawParentChildProvider.getParents(equiv)); if(directChildrenOfTopNode.contains(equiv)) { ns.addNode(nodeCache.getTopNode()); } } directParents.removeAll(node.getEntities()); if (node.isBottomNode()) { // Special treatment directParents.addAll(directParentsOfBottomNode); } for (Node<T> parentNode : nodeCache.getNodes(directParents)) { ns.addNode(parentNode); } if (!direct) { for(T parent : directParents) { getNodeHierarchyParents(parent, direct, ns); } } return ns; }
public NodeSet<T> getNodeHierarchyChildren(T parent, boolean direct, DefaultNodeSet<T> ns) { Node<T> node = nodeCache.getNode(parent); if (node.isBottomNode()) { return ns; } Set<T> directChildren = new HashSet<T>(); for (T equiv : node) { directChildren.addAll(rawParentChildProvider.getChildren(equiv)); if(directParentsOfBottomNode.contains(equiv)) { ns.addNode(nodeCache.getBottomNode()); } } directChildren.removeAll(node.getEntities()); if (node.isTopNode()) { // Special treatment directChildren.addAll(directChildrenOfTopNode); } for (Node<T> childNode : nodeCache.getNodes(directChildren)) { ns.addNode(childNode); } if (!direct) { for (T child : directChildren) { getNodeHierarchyChildren(child, direct, ns); } } return ns; }
/** * Processes the specified signature that represents the signature of potential changes * @param signature The signature */ @Override public void processChanges(Set<OWLObjectPropertyExpression> signature, Set<OWLAxiom> added, Set<OWLAxiom> removed) { boolean rebuild = false; for (OWLAxiom ax : added) { if(ax instanceof OWLObjectPropertyAxiom) { rebuild = true; break; } } if(!rebuild) { for(OWLAxiom ax : removed) { if(ax instanceof OWLObjectPropertyAxiom) { rebuild = true; break; } } } if(rebuild) { ((RawObjectPropertyHierarchyProvider) getRawParentChildProvider()).rebuild(); } super.processChanges(signature, added, removed); } }
public NodeSet<T> getNodeHierarchyChildren(T parent, boolean direct, DefaultNodeSet<T> ns) { if(parent.equals(bottomEntity)) { return ns; } Collection<T> children = getChildrenInternal(parent); for (Iterator<T> childIt = children.iterator(); childIt.hasNext();) { T child = childIt.next(); Node<T> cycleNode = cycles.get(child); if (cycleNode != null) { if (!cycleNode.contains(parent)) { ns.addNode(cycleNode); } childIt.remove(); } else { ns.addEntity(child); } if (!direct) { getNodeHierarchyChildren(child, direct, ns); } } return ns; }
public void prepare() { pm.reasonerTaskStarted("Computing " + name + " hierarchy"); pm.reasonerTaskBusy(); cycles.clear(); Map<T, Collection<T>> cache = new HashMap<T, Collection<T>>(); Set<T> processed = new HashSet<T>(); HashSet<Set<T>> result = new HashSet<Set<T>>(); Set<T> entities = new HashSet<T>(); for (OWLOntology ont : getRootOntology().getImportsClosure()) { entities.addAll(getEntities(ont)); } classificationSize = entities.size(); pm.reasonerTaskProgressChanged(0, classificationSize); computeCyclesForSignature(entities, cache, processed, result); addCycles(result); pm.reasonerTaskStopped(); }
public void addNode(Set<T> elements) { addNode(hierarchyInfo.createNode(elements)); }
public void computeHierarchy() { pm.reasonerTaskStarted("Computing " + name + " hierarchy"); pm.reasonerTaskBusy(); nodeCache.clear(); Map<T, Collection<T>> cache = new HashMap<T, Collection<T>>(); Set<T> entities = new HashSet<T>(); for (OWLOntology ont : getRootOntology().getImportsClosure()) { entities.addAll(getEntities(ont)); } classificationSize = entities.size(); pm.reasonerTaskProgressChanged(0, classificationSize); updateForSignature(entities, cache); pm.reasonerTaskStopped(); }
private <T extends OWLObject> void handleChanges(Set<OWLAxiom> added, Set<OWLAxiom> removed, HierarchyInfo<T> hierarchyInfo) { Set<T> sig = hierarchyInfo.getEntitiesInSignature(added); sig.addAll(hierarchyInfo.getEntitiesInSignature(removed)); hierarchyInfo.processChanges(sig, added, removed); }
public Set<Set<T>> computeCycleForEntites(Set<T> entities) { Map<T, Collection<T>> cache = new HashMap<T, Collection<T>>(); Set<T> processed = new HashSet<T>(); HashSet<Set<T>> result = new HashSet<Set<T>>(); for (T entity : entities) { tarjan(entity, 0, new Stack<T>(), new HashMap<T, Integer>(), new HashMap<T, Integer>(), result, processed, new HashSet<T>(), cache); } return result; }
/** * Processes the specified signature that represents the signature of potential changes * @param signature The signature */ public void processChanges(Set<T> signature) { // Break existing cycles - they will be reformed if necessary removeCyclesForSignature(signature); // Compute new cycles HashSet<Set<T>> result = new HashSet<Set<T>>(); computeCyclesForSignature(signature, new HashMap<T, Collection<T>>(), new HashSet<T>(), result); // Add them addCycles(result); }
private <T extends OWLLogicalEntity> void handleChanges(Set<OWLAxiom> added, Set<OWLAxiom> removed, HierarchyInfo<T> hierarchyInfo) { Set<T> sig = hierarchyInfo.getEntitiesInSignature(added); sig.addAll(hierarchyInfo.getEntitiesInSignature(removed)); hierarchyInfo.processChanges(sig); }
private void computeCyclesForSignature(Set<T> signature, Map<T, Collection<T>> cache, Set<T> processed, HashSet<Set<T>> result) { for (T entity : signature) { if (!processed.contains(entity)) { pm.reasonerTaskProgressChanged(processed.size(), signature.size()); tarjan(entity, 0, new Stack<T>(), new HashMap<T, Integer>(), new HashMap<T, Integer>(), result, processed, new HashSet<T>(), cache); checkForInterrupt(); } } }
private Set<T> getEntitiesInSignature(Set<OWLAxiom> axioms) { Set<T> result = new HashSet<T>(); for (OWLAxiom ax : axioms) { result.addAll(getEntitiesInSignature(ax)); } return result; }
public Node<T> getEquivalents(T element) { Node<T> node = cycles.get(element); if (node == null) { DefaultNode<T> newNode = createNode(); newNode.add(element); node = newNode; } return node; } }