@Override public Iterator<WME> getInnerIterator(final Individual ind) { return toWMEs(ind.getOutEdges().getEdges(_role), EdgeDirection.FORWARD); } };
@Override public Iterator<WME> getInnerIterator(final Individual ind) { return toWMEs(ind.getOutEdges().getEdges(_role), EdgeDirection.FORWARD); } };
@Override public EdgeList getOutEdges(final ATerm x) { final Node node = getNode(x); if (node instanceof Literal) return new EdgeList(); return ((Individual) node).getOutEdges(); }
@Override public EdgeList getOutEdges(final ATerm x) { final Node node = getNode(x); if (node instanceof Literal) return new EdgeList(); return ((Individual) node).getOutEdges(); }
public static void printCounts(final ABox abox) { if (abox == null) { System.out.println("NO ABOX"); return; } int typeCount = 0; int edgeCount = 0; int literalCount = 0; for (final Node node : abox.getNodes().values()) if (node.isLiteral()) literalCount++; else { edgeCount += ((Individual) node).getOutEdges().size(); typeCount += node.getTypes().size(); } final int individualCount = abox.getNodes().size() - literalCount; System.out.println("Individuals : " + individualCount); System.out.println("Literals : " + literalCount); System.out.println("Types : " + typeCount); System.out.println("Edges : " + edgeCount); System.out.println(); }
@Override public Iterator<WME> getMatches() { final Individual subject = initNode(); return toWMEs(subject.getOutEdges().getEdges(_role), EdgeDirection.FORWARD); }
@Override public Iterator<WME> getMatches() { final Individual subject = initNode(); return toWMEs(subject.getOutEdges().getEdges(_role), EdgeDirection.FORWARD); }
private void getDescendants(final Individual ind, final List<Individual> descendants) { descendants.add(ind); for (final Edge edge : ind.getOutEdges()) if (edge.getTo().isIndividual() && !edge.getTo().equals(ind)) getDescendants((Individual) edge.getTo(), descendants); }
private void getDescendants(final Individual ind, final List<Individual> descendants) { descendants.add(ind); for (final Edge edge : ind.getOutEdges()) if (edge.getTo().isIndividual() && !edge.getTo().equals(ind)) getDescendants((Individual) edge.getTo(), descendants); }
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 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 void restoreLocal(final Individual ind, final int branch, final Map<Node, Boolean> visited) { final boolean restored = ind.restore(branch); visited.put(ind, restored); if (restored) { for (final Edge edge : ind.getOutEdges()) { final Node succ = edge.getTo(); if (visited.containsKey(succ)) continue; if (succ.isLiteral()) { visited.put(succ, Boolean.FALSE); succ.restore(branch); } else restoreLocal((Individual) succ, branch, visited); } for (final Edge edge : ind.getInEdges()) { final Individual pred = edge.getFrom(); if (visited.containsKey(pred)) continue; restoreLocal(pred, branch, visited); } } }
private void restoreLocal(final Individual ind, final int branch, final Map<Node, Boolean> visited) { final boolean restored = ind.restore(branch); visited.put(ind, restored); if (restored) { for (final Edge edge : ind.getOutEdges()) { final Node succ = edge.getTo(); if (visited.containsKey(succ)) continue; if (succ.isLiteral()) { visited.put(succ, Boolean.FALSE); succ.restore(branch); } else restoreLocal((Individual) succ, branch, visited); } for (final Edge edge : ind.getInEdges()) { final Individual pred = edge.getFrom(); if (visited.containsKey(pred)) continue; restoreLocal(pred, branch, visited); } } }
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; }
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; }
protected Iterator<WME> getMatches(final Individual s, @SuppressWarnings("unused") final Role r, final Node o) { Iterator<WME> i1 = IteratorUtils.emptyIterator(); Iterator<WME> i2 = IteratorUtils.emptyIterator(); final Role invRole = _role.getInverse(); if (s != null) { i1 = toWMEs(getEdges(s.getOutEdges(), _role, o), EdgeDirection.FORWARD); if (invRole != null) i2 = toWMEs(getEdges(s.getInEdges(), invRole, o), EdgeDirection.BACKWARD); } else { assert s == null; i1 = toWMEs(getEdges(o.getInEdges(), _role, null), EdgeDirection.FORWARD); if (invRole != null) i2 = toWMEs(getEdges(((Individual) o).getOutEdges(), invRole, null), EdgeDirection.BACKWARD); } return !i1.hasNext() ? i2 : !i2.hasNext() ? i1 : IteratorUtils.concat(i1, i2); }
protected Iterator<WME> getMatches(final Individual s, @SuppressWarnings("unused") final Role r, final Node o) { Iterator<WME> i1 = IteratorUtils.emptyIterator(); Iterator<WME> i2 = IteratorUtils.emptyIterator(); final Role invRole = _role.getInverse(); if (s != null) { i1 = toWMEs(getEdges(s.getOutEdges(), _role, o), EdgeDirection.FORWARD); if (invRole != null) i2 = toWMEs(getEdges(s.getInEdges(), invRole, o), EdgeDirection.BACKWARD); } else { assert s == null; i1 = toWMEs(getEdges(o.getInEdges(), _role, null), EdgeDirection.FORWARD); if (invRole != null) i2 = toWMEs(getEdges(((Individual) o).getOutEdges(), invRole, null), EdgeDirection.BACKWARD); } return !i1.hasNext() ? i2 : !i2.hasNext() ? i1 : IteratorUtils.concat(i1, i2); }
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; }
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; }
/** * Test case for #404 */ @Test public void addPropertyValueAfterConsistency() { objectProperties(_p); individuals(_a, _c, _d); // either p(a, c) or p(a, d) holds _kb.addType(_a, or(hasValue(_p, _c), hasValue(_p, _d))); assertTrue(_kb.isConsistent()); // check which non-deterministic choice was made final ATermAppl succ = _kb.getABox().getIndividual(_a).getOutEdges().edgeAt(0).getToName(); final ATermAppl nonSucc = succ.equals(_c) ? _d : _c; // no entailment can be made yet assertFalse(_kb.hasPropertyValue(_a, _p, nonSucc)); assertFalse(_kb.hasPropertyValue(_a, _p, succ)); // assert the property value in non-deterministic choice _kb.addPropertyValue(_p, _a, succ); assertTrue(_kb.isConsistent()); // this entailment still does not hold assertFalse(_kb.hasPropertyValue(_a, _p, nonSucc)); // this entailment should now hold assertTrue(_kb.hasPropertyValue(_a, _p, succ)); }