@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof Explanation)) { return false; } Explanation<?> other = (Explanation<?>) obj; return other.getEntailment().equals(entailment) && other.getAxioms().equals(justification); }
@Override public int compare(OWLAxiom o1, OWLAxiom o2) { if(o1.equals(o2)) { return 0; } int count1 = 0; int count2 = 0; for(Explanation<E> expl : hittingSetTree.getExplanations()) { if(expl.contains(o1)) { count1++; } if(expl.contains(o2)) { count2++; } } if(count1 > count2) { return -1; } else if(count2 > count1) { return 1; } else { return 0; } } }
public Explanation<OWLAxiom> getLaconicJustification(Explanation<OWLAxiom> explanation) { Set<Explanation<OWLAxiom>> explanations = getLaconicExplanations(explanation, 1); if(explanations.isEmpty()) { return Explanation.getEmptyExplanation(explanation.getEntailment()); } else { return explanations.iterator().next(); } }
@Override public int compare(Explanation<E> o1, Explanation<E> o2) { if(o1.equals(o2)) { return 0; } int size1 = o1.getAxioms().size(); int size2 = o1.getAxioms().size(); // We want the smallest one to come first int sizeDifference = size2 - size1; if(sizeDifference != 0) { return sizeDifference; } // Same size // Now we would prefer ones that contained return -1; } }
@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; }
for(OWLAxiom explAx : expl.getAxioms()) { if(explAx instanceof OWLSubClassOfAxiom) { OWLSubClassOfAxiom sca = (OWLSubClassOfAxiom) explAx; Set<OWLAxiom> sameSourceAxioms = oPlusGenerator.getSameSourceAxioms(sca, expl.getAxioms()); if(!sameSourceAxioms.isEmpty()) { Set<OWLClassExpression> superClassConjuncts = new HashSet<>(); if(reconstitutedAxiomSourcesWithMultipleSources.isEmpty()) { return Collections.singleton(new Explanation<>(expl.getEntailment(), pool)); return expGen.getExplanations(expl.getEntailment());
public boolean isLaconic(Explanation<OWLAxiom> expl) { if(expl.isJustificationEntailment()) { return true; Set<OWLAxiom> flattened = getFlattenedAxioms(expl.getAxioms()); transmitter.recordMeasurement(info, "justification size", expl.getSize()); transmitter.recordMeasurement(info, "delta axioms size", flattened.size()); EntailmentChecker<OWLAxiom> checker = entailmentCheckerFactory.createEntailementChecker(expl.getEntailment());
List<OWLAxiom> orderedJustification = getOrderedJustifications(new ArrayList<>(justification.getAxioms()), allJustifications); Explanation<E> newJustification = null; for (Explanation<E> foundJustification : allJustifications) { Set<OWLAxiom> foundMUPSCopy = new HashSet<>(foundJustification.getAxioms()); foundMUPSCopy.retainAll(currentPathContents); if (foundMUPSCopy.isEmpty()) { if (axiom.isLogicalAxiom() && newJustification.contains(axiom)) { if (!newJustification.isEmpty()) {
public void put(Explanation<OWLAxiom> explanation) { Set<Explanation<OWLAxiom>> expls = cache.get(explanation.getEntailment()); if(expls == null) { expls = new HashSet<>(); cache.put(explanation.getEntailment(), expls); } expls.add(explanation); }
transmitter.beginTransmission(findOneInfo); Explanation<E> result = Explanation.getEmptyExplanation(entailment); result = new Explanation<>(entailment, Collections.singleton((OWLAxiom) entailment)); result = new Explanation<>(entailment, justificationAxioms); transmitter.recordMeasurement(findOneInfo, "input size", module.size()); transmitter.recordMeasurement(findOneInfo, "entailed", entailed); transmitter.recordMeasurement(findOneInfo, "self justification", result.isJustificationEntailment()); transmitter.recordMeasurement(findOneInfo, "justification size", result.getSize()); transmitter.recordTiming(findOneInfo, "time", justificationTimer); recordJustification(entailment, findOneInfo, result);
@Override protected Color getItemBackgroundColor(MListItem item) { if(item instanceof JustificationFrameSectionRow) { JustificationFrameSectionRow row = (JustificationFrameSectionRow) item; OWLAxiom axiom = row.getAxiom(); int rowIndex = row.getFrameSection().getRowIndex(row) + 1; if(!isSelectedIndex(rowIndex)) { if(axiomSelectionModel.getSelectedAxioms().contains(axiom)) { return Color.YELLOW; } else { boolean inAll = true; for(Explanation<?> expl : workbenchManager.getJustifications(getRootObject().getEntailment())) { if(!expl.contains(axiom)) { inAll = false; break; } } if(inAll) { return new Color(245, 255 , 235); } } } } return super.getItemBackgroundColor(item); }
for(Explanation<OWLAxiom> expl : expls) { DeltaTransformationUnfolder unfolder = new DeltaTransformationUnfolder(dataFactory); Set<OWLAxiom> unfoldedAxioms = unfolder.getUnfolded(expl.getAxioms(), signature); Explanation<OWLAxiom> unfoldedExpl = new Explanation<>(entailment, unfoldedAxioms); if(checker.isLaconic(unfoldedExpl)) { boolean added = laconicExplanations.add(unfoldedExpl);
/** * Loads a previously stored explanation from the specified input stream * @param is The input stream from where to read the explanation * @return The explanation that was read * @throws IllegalStateException if the input stream does not appear to contain a serialisation of an explanation. */ public static Explanation<OWLAxiom> load(InputStream is, Supplier<OWLOntologyManager> m) { try { OWLOntology ontology = m.get().loadOntologyFromOntologyDocument(new BufferedInputStream(is)); OWLDataFactory df = ontology.getOWLOntologyManager().getOWLDataFactory(); OWLAnnotationProperty entailmentMarkerAnnotationProperty = df.getOWLAnnotationProperty(ENTAILMENT_MARKER_IRI); Set<OWLAxiom> justificationAxioms = asSet(ontology.axioms().filter(ax -> isNotEntailment(entailmentMarkerAnnotationProperty, ax))); // Expected one and only one entailment axiom OWLAxiom entailment = ontology.axioms().filter(ax->isEntailment(entailmentMarkerAnnotationProperty, ax)).findAny() .orElseThrow(() -> new IllegalStateException("Not a serialisation of an Explanation")); return new Explanation<>(entailment, justificationAxioms); } catch (OWLOntologyCreationException e) { throw new RuntimeException(e); } }
return Explanation.getEmptyExplanation(entailment); return Explanation.getEmptyExplanation(entailment); return Explanation.getEmptyExplanation(entailment); Explanation<E> expl = new Explanation<>(entailment, justification);
public int compare(Explanation<OWLAxiom> o1, Explanation<OWLAxiom> o2) { int diff = getAxiomTypes(o1).size() - getAxiomTypes(o2).size(); if (diff != 0) { return diff; } diff = getClassExpressionTypes(o1).size() - getClassExpressionTypes(o2).size(); if (diff != 0) { return diff; } return o1.getSize() - o2.getSize(); } });
public static <E> Explanation<E> getEmptyExplanation(E entailment) { Set<OWLAxiom> emptySet = Collections.emptySet(); return new Explanation<>(entailment, emptySet); }
@Override public void foundExplanation(ExplanationGenerator<OWLAxiom> owlAxiomExplanationGenerator, Explanation<OWLAxiom> owlAxiomExplanation, Set<Explanation<OWLAxiom>> allFoundExplanations) { if (owlAxiomExplanation.equals(laconicExpl)) { preferredLaconicExplanations.add(laconicExpl); cancelled = true; } }
for (OWLAxiom ax : exp.getAxioms()) { if (ont.containsAxiom(ax)) { sourceAxioms2OPlus.put(ax, computeOPlus(Collections.singleton(ax))); for (OWLAxiom laconicAx : laconicExp.getAxioms()) { if (laconicAx instanceof OWLSubClassOfAxiom) { OWLSubClassOfAxiom sca = (OWLSubClassOfAxiom) laconicAx; Explanation<E> explanation = new Explanation<>(laconicExp.getEntailment(), reconstituedAxioms); reconstituedExplanations.add(explanation);
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); } }