public void addExplanation(Explanation<E> explanation) { if (!explanation.isEmpty() && allFoundExplanations.add(explanation)) { explanations.add(explanation); Collections.sort(explanations, explanationComparator); progressMonitor.foundExplanation(null, explanation, allFoundExplanations); } }
@Override public Explanation<E> generateExplanation(E entailment) { for (Explanation<E> expl : cache) { if (expl.getEntailment().equals(entailment) && module.containsAll(expl.getAxioms())) { cacheHitCounter++; return expl; } } Explanation<E> expl = computeExplanation(entailment); if (!expl.isEmpty()) { cache.add(expl); } return expl; }
private void recordJustification(E entailment, TelemetryInfo findOneInfo, Explanation<E> result) { TelemetryTransmitter transmitter = TelemetryTransmitter.getTransmitter(); if (!result.isEmpty() && entailment instanceof OWLAxiom) { @SuppressWarnings("unchecked") Explanation<OWLAxiom> result2 = (Explanation<OWLAxiom>) result; ExplanationTelemetryWrapper telemetryObject = new ExplanationTelemetryWrapper(result2, m); transmitter.recordObject(findOneInfo, "justification", ".owl.xml", telemetryObject); } }
@Override public Set<Explanation<E>> getExplanations(E entailment, int limit) throws ExplanationException { try { module = extractModule(workingAxioms, checkerFactory.createEntailementChecker(entailment)); prunningDifferences.clear(); Set<Explanation<E>> explanations = new HashSet<>(); Explanation<E> expl = computeExplanation(entailment); explanations.add(expl); progressMonitor.foundExplanation(this, expl, Collections.unmodifiableSet(explanations)); if (progressMonitor.isCancelled()) { return Collections.singleton(expl); } if (expl.isEmpty()) { return Collections.emptySet(); } if (limit > 1) { constructHittingSetTree(entailment, expl, explanations, new HashSet<Set<OWLAxiom>>(), new HashSet<OWLAxiom>(), limit); } if (explanations.isEmpty()) { throw new NotEntailedException(entailment); } return explanations; } catch (OWLException e) { throw new ExplanationException(e); } }
if (!newJustification.isEmpty()) {
public void buildHittingSetTree(HittingSetTree<E> hittingSetTree, int limit, ExplanationGeneratorMediator<E> handler, HittingSetTreeNode<E> currentNode) { for (OWLAxiom ax : currentNode.getExplanation().getAxioms()) { handler.removeAxiom(ax); Set<OWLAxiom> pathContents = new HashSet<>(currentNode.getPathToRoot()); pathContents.add(ax); if (hittingSetTree.addExploredPath(pathContents)) { // Look to reuse a justification Explanation<E> expl = getNonIntersectingExplanation(hittingSetTree, pathContents); boolean reuse = true; if (expl == null) { reuse = false; expl = handler.generateExplanation(currentNode.getExplanation().getEntailment()); hittingSetTree.addExplanation(expl); if(hittingSetTree.getExplanations().size() == limit) { return; } } if (!expl.isEmpty()) { HittingSetTreeNode<E> hittingSetTreeNode = new HittingSetTreeNode<>(ax, currentNode, expl, reuse); currentNode.addChild(ax, hittingSetTreeNode); buildHittingSetTree(hittingSetTree, limit, handler, hittingSetTreeNode); } else { hittingSetTree.addClosedPath(new HashSet<>(pathContents)); } } handler.addAxiom(ax); } }
if (!expl.isEmpty()) { HittingSetTreeNode<E> hittingSetTreeNode = new HittingSetTreeNode<>(ax, currentNode, expl, reuse); currentNode.addChild(ax, hittingSetTreeNode);