public boolean activateIndividual(final Individual ind) { // only named non-pruned individuals final boolean changed = false; if (!ind.isRootNominal() || ind.isPruned()) return false; final List<ATermAppl> types = ind.getTypes(Node.ATOM); for (int i = 0; i < types.size(); i++) { final ATermAppl type = types.get(i); activateType(ind, type, ind.getDepends(type)); } activateDifferents(ind); for (final Edge edge : new ArrayList<>(ind.getOutEdges())) if (edge.getTo().isRootNominal()) activateEdge(edge); return changed; }
@Override public void addType(final ATermAppl x, final ATermAppl cParam, final DependencySet dsParam) { ATermAppl c = cParam; DependencySet ds = dsParam; c = ATermUtils.normalize(c); // when a type is being added to // an ABox that has already been completed, the _branch // of the dependency set will automatically be set to // the _current _branch. We need to set it to the initial // _branch number to make sure that this type assertion // will not be removed during backtracking final int remember = _branchIndex; setBranchIndex(DependencySet.NO_BRANCH); Individual node = getIndividual(x); node.addType(c, ds, false); while (node.isMerged()) { ds = ds.union(node.getMergeDependency(false), _doExplanation); node = (Individual) node.getMergedTo(); node.addType(c, ds, !node.isMerged()); } setBranchIndex(remember); }
@Override public Iterator<WME> getMatches(final int argIndex, final Node arg) { final EdgeList edges = ((Individual) arg).getRNeighborEdges(_role, arg); return toWMEs(edges, EdgeDirection.FORWARD); }
/** * Readd conjunction labels * * @param ind */ private void readdConjunctions(final Individual ind) { ind.types()// .filter(conj -> ATermUtils.isAnd(conj) && ind.hasType(conj))// .forEach(conj -> addType(ind, conj, ind.getDepends(conj))); }
@Override public void apply(final Individual x) { if (!x.canApply(Node.SOME)) return; final List<ATermAppl> types = x.getTypes(Node.SOME); final int size = types.size(); for (int j = x._applyNext[Node.SOME]; j < size; j++) { final ATermAppl sv = types.get(j); applySomeValuesRule(x, sv); if (_strategy.getABox().isClosed() || x.isPruned()) return; } x._applyNext[Node.SOME] = size; }
final boolean printOnlyName = node.isNominal() && !printed.isEmpty(); return; if (node.isMerged()) stream.println(" -> " + node.getMergedTo() + " " + node.getMergeDependency(false)); return; if (node.isPruned()) throw new InternalReasonerException("Pruned node: " + node); for (final ATermAppl c : node.getTypes(i)) stream.println(node.getDifferents()); final Iterator<Edge> i = node.getOutEdges().iterator(); while (i.hasNext()) final EdgeList edges = node.getEdgesTo(succ);
final Individual ind = edge.getFrom(); if (ind.isNominal() && (head == null || ind.getNominalLevel() < head.getNominalLevel())) final Individual next = edge.getFrom(); if (next.isPruned()) continue; if (head.isSame(next)) continue; if (next.isDifferent(head)) ds = ds.union(next.getDifferenceDependency(head), _abox.doExplanation()); if (r.isFunctional()) _abox.setClash(Clash.functionalCardinality(x, ds, r.getName())); return; if (head.isPruned()) ds = ds.union(head.getMergeDependency(true), _abox.doExplanation()); head = head.getSame();
if (z.isMerged()) ds = ds.union(z.getMergeDependency(true), _strategy.getABox().doExplanation()); z = z.getSame(); if (y.isSame(z)) return; if (y.isDifferent(z)) ds = ds.union(y.getDifferenceDependency(z), _strategy.getABox().doExplanation()); if (_strategy.getABox().doExplanation()) _strategy.getABox().setClash(Clash.nominal(y, ds, z.getName())); else _strategy.getABox().setClash(Clash.nominal(y, ds));
Node obj = getNode(o); if (subj.isMerged() && obj.isMerged()) return null; final Edge existingEdge = subj.getOutEdges().getExactEdge(subj, role, obj); if (existingEdge == null) subj.addOutEdge(edge); else if (!existingEdge.getDepends().isIndependent()) subj.removeEdge(existingEdge); subj.addOutEdge(edge); if (subj.isMerged()) ds = ds.union(subj.getMergeDependency(true), true); ds = ds.copy(ds.max() + 1); subj = subj.getSame(); edge = new DefaultEdge(role, subj, obj, ds); if (subj.getOutEdges().hasEdge(edge)) return null; subj.addOutEdge(edge); obj.addInEdge(edge);
_abox.getBranchEffectTracker().add(_abox.getBranchIndex(), getName()); _abox.getBranchEffectTracker().add(_abox.getBranchIndex(), x.getName()); if (hasRSuccessor(r, x) || r.isTop()) _logger.fine("EDGE: " + this + " -> " + r + " -> " + x + ": " + ds + " " + getRNeighborEdges(r).getEdgesTo(x)); return null; if (isPruned()) throw new InternalReasonerException("Adding edge to a pruned _node " + this + " " + r + " " + x + "\t" + _pruned); else if (isMerged()) return null; setChanged(ALL); setChanged(MAX); _applyNext[MAX] = 0;
protected boolean isDirectlyBlockedByDescendant(final BlockingContext cxt) { if (cxt._blocked.getParent().equals(cxt._blocker)) return false; if (!cxt._blocker.isRoot() && isDirectlyBlockedBy(cxt)) { cxt._blocked.setBlocked(true); _logger.finer(() -> cxt._blocked + " _blocked by " + cxt._blocker); return true; } final Individual blocker = cxt._blocker; for (final Edge e : blocker.getOutEdges()) { final Node child = e.getTo(); if (cxt.moveBlockerDown(child)) { if (isDirectlyBlockedByDescendant(cxt) || cxt._blocker.isRoot()) return true; cxt.moveBlockerUp(); } } return false; }
public Edge addEdge(final Individual subj, final Role pred, final Node obj, final DependencySet ds) final Edge edge = subj.addEdge(pred, obj, ds); _abox.getBranchEffectTracker().add(_abox.getBranchIndex(), subj.getName()); _abox.getBranchEffectTracker().add(_abox.getBranchIndex(), obj.getName()); if (subj.isBlockable() && obj.isNominal() && !obj.isLiteral() && pred.isInverseFunctional()) if (!o.hasDistinctRNeighborsForMin(pred.getInverse(), max, ATermUtils.TOP, true)) int guessMin = o.getMinCard(pred.getInverse(), ATermUtils.TOP); if (guessMin == 0) guessMin = 1; return edge; if (subj.isPruned()) return edge;
public void checkReflexivitySymmetry(final Individual subj, final Role pred, final Individual obj, final DependencySet dsParam) { DependencySet ds = dsParam; if (pred.isAsymmetric() && obj.hasRSuccessor(pred, subj)) { final EdgeList edges = obj.getEdgesTo(subj, pred); ds = ds.union(edges.get(0).getDepends(), _abox.doExplanation()); if (OpenlletOptions.USE_TRACING) ds = ds.union(pred.getExplainAsymmetric(), _abox.doExplanation()); _abox.setClash(Clash.unexplained(subj, ds, "Antisymmetric property " + pred)); } else if (subj.equals(obj)) if (pred.isIrreflexive()) _abox.setClash(Clash.unexplained(subj, ds.union(pred.getExplainIrreflexive(), _abox.doExplanation()), "Irreflexive property " + pred)); else { final ATerm notSelfP = ATermUtils.makeNot(ATermUtils.makeSelf(pred.getName())); if (subj.hasType(notSelfP)) _abox.setClash(Clash.unexplained(subj, ds.union(subj.getDepends(notSelfP), _abox.doExplanation()), "Local irreflexive property " + pred)); } }
private static boolean block4(final BlockingContext cxt, final ATermAppl term) { final Role t = cxt._blocked.getABox().getRole(term.getArgument(0)); final int m; final ATermAppl c; if (ATermUtils.isMin(term)) { c = (ATermAppl) term.getArgument(2); m = ((ATermInt) term.getArgument(1)).getInt(); } else { c = ATermUtils.negate((ATermAppl) term.getArgument(1)); m = 1; } if (t.isDatatypeRole()) return true; if (cxt.isRSuccessor(t.getInverse()) && cxt._blocked.getParent().hasType(c)) return true; return cxt._blocker.getRSuccessors(t, c).size() >= m; } }
return; if (tg.isFinal(st) && subj.isRootNominal()) getSames(subj, knowns, unknowns); else knowns.add(subj.getName()); getSames(subj, unknowns, unknowns); else unknowns.add(subj.getName()); _logger.fine(subj.toString()); final EdgeList edges = subj.getRNeighborEdges(r); for (int i = 0; i < edges.size(); i++)
return; final EdgeList edges = subj.getRNeighborEdges(prop); for (int i = 0; i < edges.size(); i++) final DependencySet ds = edge.getDepends(); final Individual value = (Individual) edge.getNeighbor(subj); final Role edgeRole = edge.getFrom().equals(subj) ? edge.getRole() : edge.getRole().getInverse(); if (value.isRootNominal()) if (isIndependent && ds.isIndependent()) getSames(value, knowns, unknowns); else knowns.add(value.getName()); getSames(value, unknowns, unknowns); else unknowns.add(value.getName());
@Override public EdgeList getOutEdges(final ATerm x) { final Node node = getNode(x); if (node instanceof Literal) return new EdgeList(); return ((Individual) node).getOutEdges(); }
private void collectComplexPropertyValues(final Individual subj) { final Set<Role> collected = new HashSet<>(); for (final Edge edge : subj.getOutEdges()) { final Role role = edge.getRole(); // only collect non-simple, i.e. complex, roles // TODO we might not need to collect all non-simple roles // collecting only the base ones, i.e. minimal w.r.t. role // ordering, would be enough if (role.isSimple() || !collected.add(role)) continue; collected.add(role); collectComplexPropertyValues(subj, role); } for (final Edge edge : subj.getInEdges()) { final Role role = edge.getRole().getInverse(); if (role.isSimple() || !collected.add(role)) continue; collectComplexPropertyValues(subj, role); } }
private Individual addIndividual(final ATermAppl x, final Individual parent, final DependencySet ds) { if (_nodes.containsKey(x)) throw new InternalReasonerException("adding a _node twice " + x); setChanged(true); final Individual n = new Individual(x, this, parent); _nodes.put(x, n); _nodeList.add(x); if (n.getDepth() > _stats._treeDepth) { _stats._treeDepth = n.getDepth(); if (_logger.isLoggable(Level.FINER)) _logger.finer("Depth: " + _stats._treeDepth + " Size: " + size()); } //this must be performed after the _nodeList is updated as this call will update the completion queues n.addType(ATermUtils.TOP, ds); if (getBranchIndex() > 0 && OpenlletOptions.TRACK_BRANCH_EFFECTS) _branchEffects.add(getBranchIndex(), n.getName()); return n; }