private void insertChildren(@Nullable OWLEntity entity, ExplanationTree tree) { if (entity == null) { return; } Set<OWLAxiom> currentPath = new HashSet<>(tree.getUserObjectPathToRoot()); getAxioms(entity).filter(ax -> !passTypes.contains(ax.getAxiomType())).forEach(ax -> { Set<OWLAxiom> mapped = getIndexedSet(entity, mappedAxioms, true); if (!consumedAxioms.contains(ax) && !mapped.contains(ax) && !currentPath.contains(ax)) { mapped.add(ax); consumedAxioms.add(ax); ExplanationTree child = new ExplanationTree(ax); tree.addChild(child); getRHSEntitiesSorted(ax).forEach(ent -> insertChildren(ent, child)); } }); sortChildrenAxioms(tree); }
@Override public void visit(OWLEquivalentDataPropertiesAxiom axiom) { axiom.properties().forEach(prop -> { getAxiomsForLHS(prop.asOWLDataProperty()).add(axiom); indexAxiomsByRHSEntities(prop, axiom); }); }
private Stream<OWLEntity> getRHSEntitiesSorted(OWLAxiom ax) { return getRHSEntities(ax).stream().sorted(PROPERTIESFIRST); }
@Override public ExplanationTree getOrderedExplanation(OWLAxiom entailment, Set<OWLAxiom> current) { currentExplanation = new HashSet<>(current); buildIndices(); ExplanationTree root = new EntailedAxiomTree(entailment); insertChildren(seedExtractor.getSource(entailment), root); OWLEntity currentTarget = seedExtractor.getTarget(entailment); Set<OWLAxiom> axs = root.getUserObjectClosure(); List<OWLAxiom> rootAxioms = new ArrayList<>(); for (OWLAxiom ax : current) { if (!axs.contains(ax)) { rootAxioms.add(ax); } } Set<OWLAxiom> targetAxioms = getTargetAxioms(currentTarget); Collections.sort(rootAxioms, (o1, o2) -> { if (targetAxioms.contains(o1)) { return 1; } if (targetAxioms.contains(o2)) { return -1; } return 0; }); rootAxioms.forEach(ax -> root.addChild(new ExplanationTree(ax))); return root; }
/** * Gets axioms that have a LHS corresponding to the specified entity. * * @param lhs The entity that occurs on the left hand side of the axiom. * @return A set of axioms that have the specified entity as their left hand side. */ protected Set<OWLAxiom> getAxiomsForLHS(OWLEntity lhs) { return getIndexedSet(lhs, lhs2AxiomMap, true); }
@Override public void visit(OWLAsymmetricObjectPropertyAxiom axiom) { if (!axiom.getProperty().isAnonymous()) { getAxiomsForLHS(axiom.getProperty().asOWLObjectProperty()).add(axiom); } }
private void buildIndices() { reset(); AxiomMapBuilder builder = new AxiomMapBuilder(); currentExplanation.forEach(ax -> ax.accept(builder)); currentExplanation.forEach( ax -> ax.signature().forEach(c -> axioms.computeIfAbsent(c, x -> new HashSet<>()))); }
protected Stream<? extends OWLAxiom> getAxioms(OWLEntity entity) { return getTargetAxioms(entity).stream(); }
@Override public void visit(OWLHasKeyAxiom axiom) { if (!axiom.getClassExpression().isAnonymous()) { indexAxiomsByRHSEntities(axiom.getClassExpression().asOWLClass(), axiom); } } }
@Override public ExplanationTree getOrderedExplanation(OWLAxiom entailment, Set<OWLAxiom> current) { currentExplanation = new HashSet<>(current); buildIndices(); ExplanationTree root = new EntailedAxiomTree(entailment); insertChildren(seedExtractor.getSource(entailment), root); OWLEntity currentTarget = seedExtractor.getTarget(entailment); Set<OWLAxiom> axs = root.getUserObjectClosure(); List<OWLAxiom> rootAxioms = new ArrayList<>(); for (OWLAxiom ax : current) { if (!axs.contains(ax)) { rootAxioms.add(ax); } } Set<OWLAxiom> targetAxioms = getTargetAxioms(currentTarget); Collections.sort(rootAxioms, (o1, o2) -> { if (targetAxioms.contains(o1)) { return 1; } if (targetAxioms.contains(o2)) { return -1; } return 0; }); rootAxioms.forEach(ax -> root.addChild(new ExplanationTree(ax))); return root; }
/** * Gets the rHS entities. * * @param axiom the axiom * @return the rHS entities */ private Collection<OWLEntity> getRHSEntities(OWLAxiom axiom) { return getIndexedSet(axiom, entitiesByAxiomRHS, true); }
@Override public void visit(OWLSymmetricObjectPropertyAxiom axiom) { if (!axiom.getProperty().isAnonymous()) { getAxiomsForLHS(axiom.getProperty().asOWLObjectProperty()).add(axiom); } }
private void buildIndices() { reset(); AxiomMapBuilder builder = new AxiomMapBuilder(); currentExplanation.forEach(ax -> ax.accept(builder)); currentExplanation.forEach( ax -> ax.signature().forEach(c -> axioms.computeIfAbsent(c, x -> new HashSet<>()))); }
protected Stream<? extends OWLAxiom> getAxioms(OWLEntity entity) { return getTargetAxioms(entity).stream(); }
@Override public void visit(OWLDisjointDataPropertiesAxiom axiom) { axiom.properties().forEach(prop -> { getAxiomsForLHS(prop.asOWLDataProperty()).add(axiom); indexAxiomsByRHSEntities(prop, axiom); }); }
private void insertChildren(@Nullable OWLEntity entity, ExplanationTree tree) { if (entity == null) { return; } Set<OWLAxiom> currentPath = new HashSet<>(tree.getUserObjectPathToRoot()); getAxioms(entity).filter(ax -> !passTypes.contains(ax.getAxiomType())).forEach(ax -> { Set<OWLAxiom> mapped = getIndexedSet(entity, mappedAxioms, true); if (!consumedAxioms.contains(ax) && !mapped.contains(ax) && !currentPath.contains(ax)) { mapped.add(ax); consumedAxioms.add(ax); ExplanationTree child = new ExplanationTree(ax); tree.addChild(child); getRHSEntitiesSorted(ax).forEach(ent -> insertChildren(ent, child)); } }); sortChildrenAxioms(tree); }
@Override public ExplanationTree getOrderedExplanation(OWLAxiom entailment, Set<OWLAxiom> current) { currentExplanation = new HashSet<>(current); buildIndices(); ExplanationTree root = new EntailedAxiomTree(entailment); insertChildren(seedExtractor.getSource(entailment), root); OWLEntity currentTarget = seedExtractor.getTarget(entailment); Set<OWLAxiom> axs = root.getUserObjectClosure(); List<OWLAxiom> rootAxioms = new ArrayList<>(); for (OWLAxiom ax : current) { if (!axs.contains(ax)) { rootAxioms.add(ax); } } Set<OWLAxiom> targetAxioms = getTargetAxioms(currentTarget); Collections.sort(rootAxioms, (o1, o2) -> { if (targetAxioms.contains(o1)) { return 1; } if (targetAxioms.contains(o2)) { return -1; } return 0; }); rootAxioms.forEach(ax -> root.addChild(new ExplanationTree(ax))); return root; }
/** * Gets the rHS entities. * * @param axiom the axiom * @return the rHS entities */ private Collection<OWLEntity> getRHSEntities(OWLAxiom axiom) { return getIndexedSet(axiom, entitiesByAxiomRHS, true); }
@Override public void visit(OWLTransitiveObjectPropertyAxiom axiom) { if (!axiom.getProperty().isAnonymous()) { getAxiomsForLHS(axiom.getProperty().asOWLObjectProperty()).add(axiom); } }
private void buildIndices() { reset(); AxiomMapBuilder builder = new AxiomMapBuilder(); currentExplanation.forEach(ax -> ax.accept(builder)); currentExplanation.forEach( ax -> ax.signature().forEach(c -> axioms.computeIfAbsent(c, x -> new HashSet<>()))); }