/** * @param newBranch * @return a new DependencySet object with a new _branch number where the IntSet is openllet.shared.hash (changing one will change the other). */ public DependencySet copy(final int newBranch) { return new DependencySet(newBranch, _depends, _explain); }
public CachedEdge(final Role role, final ATermAppl neighbor, final DependencySet ds) { _role = role; _neighbor = neighbor; _depends = ds.cache(); }
protected void resetTypes() { final Iterator<DependencySet> i = _depends.values().iterator(); while (i.hasNext()) { final DependencySet d = i.next(); if (d.getBranch() != DependencySet.NO_BRANCH) i.remove(); } }
/** * Remove explanation sets which contain references to a syntactic assertion * * @param assertion */ public void removeExplain(final ATermAppl assertion) { if (getExplain().contains(assertion)) { setExplain(new HashSet<ATermAppl>()); DependencyIndex._logger.fine(" Explain: removed "); } }
private void updateBranchesOfABox(final AddBranchDependency branch, final ABox abox) { final List<Branch> branches = abox.getBranches(); // decrease branch id for each branch after the branch we're removing // also need to change the dependency set for each label for (int i = branch.getBranch().getBranchIndexInABox(); i < branches.size(); i++) { final Branch br = branches.get(i); // cast for ease DependencySet termDepends = br.getTermDepends(); // update the term depends in the branch if (termDepends.getBranch() > branch.getBranch().getBranchIndexInABox()) termDepends = termDepends.copy(termDepends.getBranch() - 1); for (int j = branch.getBranch().getBranchIndexInABox(); j < _kb.getABox().getBranches().size(); j++) if (termDepends.contains(j)) { termDepends.remove(j); termDepends.add(j - 1); break; } br.setTermDepends(termDepends); } branches.remove(branch.getBranch()); // remove the actual branch }
ds = ds.union(_prevDS[m], _abox.doExplanation()); ds.setExplain(getTermDepends().getExplain()); else ds.remove(getBranchIndexInABox()); ds = getTermDepends().union(new DependencySet(getBranchIndexInABox()), _abox.doExplanation()); else ds = new DependencySet(getBranchIndexInABox()); if (_tryNext < _tryCount - 1 && clashDepends.contains(getBranchIndexInABox())) _abox.setClash(Clash.unexplained(null, clashDepends.union(ds, _abox.doExplanation())));
_logger.fine("MAX : (" + (getTryNext() + 1) + "/" + _mergePairs.size() + ") at _branch (" + getBranchIndexInABox() + ") to " + _ind + " for prop " + _r + " _qualification " + _qualification + " merge " + y + " -> " + z + " " + ds); ds = ds.union(new DependencySet(getBranchIndexInABox()), _abox.doExplanation()); ds = ds.union(edge.getDepends(), _abox.doExplanation()); yEdge = true; if (neighbor.equals(z)) ds = ds.union(edge.getDepends(), _abox.doExplanation()); zEdge = true; ds = ds.union(y.getDepends(_qualification), _abox.doExplanation()); ds = ds.union(z.getDepends(_qualification), _abox.doExplanation()); ds.add(prevBranch.getBranchIndexInABox()); else break; if (clashDepends.contains(getBranchIndexInABox())) ds.remove(getBranchIndexInABox());
ds = ds.union(obj.getMergeDependency(true), true); ds = ds.copy(ds.max() + 1); obj = obj.getSame(); subj.addOutEdge(edge); else if (!existingEdge.getDepends().isIndependent()) ds = ds.union(subj.getMergeDependency(true), true); ds = ds.copy(ds.max() + 1); subj = subj.getSame(); edge = new DefaultEdge(role, subj, obj, ds); obj.addInEdge(edge); else if (!existingEdge.getDepends().isIndependent())
public boolean setDifferent(final Node node, final DependencySet dsParam) { DependencySet ds = dsParam; // add to effected list if (_abox.getBranchIndex() >= 0 && OpenlletOptions.TRACK_BRANCH_EFFECTS) _abox.getBranchEffectTracker().add(_abox.getBranchIndex(), node.getName()); if (isDifferent(node)) return false; if (isSame(node)) { ds = ds.union(getMergeDependency(true), _abox.doExplanation()); ds = ds.union(node.getMergeDependency(true), _abox.doExplanation()); _abox.setClash(Clash.nominal(this, ds, node.getName())); if (!ds.isIndependent()) return false; } ds = ds.copy(_abox.getBranchIndex()); _differents.put(node, ds); node.setDifferent(this, ds); _abox.setChanged(true); return true; }
/** * Restore a clash dependency * * @param assertion * @param clash */ private void restoreClash(final ATermAppl assertion, final ClashDependency clash) { DependencyIndex._logger.fine(() -> " Restoring clash dependency clash: " + clash.getClash()); clash.getClash().getDepends().removeExplain(assertion); // remove the dependency if (clash.getClash().getDepends().getExplain().isEmpty() && clash.getClash().getDepends().isIndependent()) // undo clash if empty and is independent { DependencyIndex._logger.fine(() -> " Actually removing clash!"); _kb.getABox().setClash(null); } }
ds.removeExplain(assertion); // remove the dependency if (ds.getExplain().isEmpty()) // undo merge if empty throw new InternalReasonerException(" Restore merge error: " + ind + " not pruned"); ind.unprune(ind.getPruned().getBranch()); // unprune to prune _branch
public boolean setSame(final Node node, final DependencySet ds) { if (isSame(node)) return false; if (isDifferent(node)) { //CHW - added for incremental reasoning support - this is needed as we will need to backjump if possible if (OpenlletOptions.USE_INCREMENTAL_CONSISTENCY) _abox.setClash(Clash.nominal(this, ds.union(_mergeDepends, _abox.doExplanation()).union(node._mergeDepends, _abox.doExplanation()), node.getName())); else _abox.setClash(Clash.nominal(this, ds, node.getName())); return false; } _mergedTo = node; _mergeDepends = ds.copy(_abox.getBranchIndex()); node.addMerged(this); return true; }
/** * Return a dummy representation of this DependencySet such that <code>this.isIndependent() == this.copyForCache().isIndependent()</code> The returned copy * will not be accurate w.r.t. any other function call, e.g. <code>contains(int)</code> for the copy will return different results for the copy. This * function does not create a new DependencySet object so will not require additional memory. Caching this copy is more appropriate so we don't waste space * for storing the actual dependency set or the explanation which are not used in caches anyway. * * @return the dummy dependency set, the cache */ public DependencySet cache() { return isIndependent() ? DependencySet.INDEPENDENT : DependencySet.DUMMY; } }
@Override public boolean removeDomain(final ATermAppl a, final DependencySet ds) { final DependencySet existing = _domains.get(a); if (existing != null) if (ds.getExplain().equals(existing.getExplain())) { _domains.remove(a); return true; } return false; }
public int getBranch() { return _ds.max(); } }
protected WME createEdge(final Edge edge, final EdgeDirection dir) { if (_doExplanation) { final DependencySet ds = dir == EdgeDirection.FORWARD ? _role.getExplainSub(edge.getRole().getName()) : _role.getInverse().getExplainSub(edge.getRole().getName()); if (!ds.getExplain().isEmpty()) return WME.createEdge(new DefaultEdge(edge.getRole(), edge.getFrom(), edge.getTo(), edge.getDepends().union(ds, _doExplanation)), dir); } return WME.createEdge(edge, dir); }
protected DependencySet forceAddType(final ATermAppl c, final DependencySet ds) { // add to effected list if (OpenlletOptions.TRACK_BRANCH_EFFECTS && _abox.getBranchIndex() >= 0) _abox.getBranchEffectTracker().add(_abox.getBranchIndex(), getName()); // if we are checking entailment using a precompleted ABox, _abox.branch // is set to -1. however, since applyAllValues is done automatically // and the edge used in applyAllValues may depend on a _branch we want // this type to be deleted when that edge goes away, i.e. we backtrack // to a position before the max dependency of this type int b = _abox.getBranchIndex(); final int max = ds.max(); if (b == -1 && max != 0) b = max + 1; final DependencySet out = ds.copy(b); _depends.put(c, out); _abox.setChanged(true); return out; }
/** * @param name * @param nodeParam */ public CachedConceptNode(final ATermAppl name, final Individual nodeParam) { _name = name; Individual node = nodeParam; // if the _node is merged, get the representative _node and check // also if the merge depends on a _branch _isIndependent = node.getMergeDependency(true).isIndependent(); node = node.getSame(); _outEdges = copyEdgeList(node, true); _inEdges = copyEdgeList(node, false); // collect all transitive property values if (node.getABox().getKB().getExpressivity().hasNominal()) collectComplexPropertyValues(node); _types = CollectionUtils.makeIdentityMap(node.getDepends()); for (final Map.Entry<ATermAppl, DependencySet> e : _types.entrySet()) e.setValue(e.getValue().cache()); }
@Override public void setClash(final Clash clash) { if (clash != null) { if (_logger.isLoggable(Level.FINER)) { _logger.finer("CLSH: " + clash); if (clash.getDepends().max() > _branchIndex && _branchIndex != -1) _logger.severe("Invalid _clash dependency " + clash + " > " + _branchIndex); } if (_branchIndex == DependencySet.NO_BRANCH && clash.getDepends().getBranch() == DependencySet.NO_BRANCH) _assertedClashes.add(clash); if (_clash != null) { _logger.finer(() -> "Clash was already set \nExisting: " + _clash + "\nNew : " + clash); if (_clash.getDepends().max() < clash.getDepends().max()) return; } } _clash = clash; // CHW - added for incremental deletions if (OpenlletOptions.USE_INCREMENTAL_DELETION) _kb.getDependencyIndex().setClashDependencies(_clash); }