/** * Very important initialization step that needs to be called once before a reasoner is created. This function will be called automatically when * GlassBoxExplanation is loaded by the class loader. This function simply calls the {@link GlassBoxExplanation#setup()} function. */ public static void setup() { GlassBoxExplanation.setup(); }
final boolean firstExplanation = isFirstExplanation(); result = getCachedExplanation(unsatClass); result = getReasonerExplanation(unsatClass); setAltReasonerEnabled(true); result = getReasonerExplanation(unsatClass); setAltReasonerEnabled(false);
@Override public void dispose() { getOntologyManager().removeOntologyChangeListener(getDefinitionTracker()); if (_altReasoner != null) _altReasoner.dispose(); }
private void setAltReasonerEnabled(final boolean enabled) { if (enabled) if (_altReasoner == null) { _logger.fine("Create alt reasoner"); _altReasoner = getReasonerFactory().createNonBufferingReasoner(getOntology()); } _altReasonerEnabled = enabled; }
private Set<OWLAxiom> getReasonerExplanation(final OWLClassExpression unsatClass) { final OpenlletReasoner reasoner = getReasoner(); reasoner.getKB().prepare(); // satisfiable if there is an undefined entity boolean sat = !getDefinitionTracker().isDefined(unsatClass); if (!sat) sat = isSatisfiable(reasoner, unsatClass, true); else _logger.fine(() -> "Undefined entity in " + unsatClass); if (sat) return Collections.emptySet(); else { final Set<OWLAxiom> explanation = convertExplanation(reasoner.getKB().getExplanationSet()); _logger.fine(() -> "Explanation " + explanation); final Set<OWLAxiom> prunedExplanation = pruneExplanation(unsatClass, explanation, true); final int prunedAxiomCount = explanation.size() - prunedExplanation.size(); if (_logger.isLoggable(Level.FINE) && prunedAxiomCount > 0) { _logger.fine("Pruned " + prunedAxiomCount + " axioms from the explanation: " + SetUtils.difference(explanation, prunedExplanation)); _logger.fine("New explanation " + prunedExplanation); } return prunedExplanation; } }
private Set<OWLAxiom> getCachedExplanation(final OWLClassExpression unsatClass) { final OpenlletReasoner pellet = getReasoner(); if (!pellet.getKB().isClassified()) return null; final Pair<OWLClass, OWLClass> pair = getSubClassAxiom(unsatClass); if (pair != null) { final Set<Set<ATermAppl>> exps = TaxonomyUtils.getSuperExplanations(pellet.getKB().getTaxonomy(), pellet.term(pair.first), pellet.term(pair.second)); if (exps != null) { final Set<OWLAxiom> result = convertExplanation(exps.iterator().next()); if (_logger.isLoggable(Level.FINE)) _logger.fine("Cached explanation: " + result); return result; } } return null; }
private TransactionAwareSingleExpGen getSingleExplanationGenerator() { if (_useBlackBox) { if (_options.getOption("inconsistent") != null) { if (!_options.getOption("inconsistent").getValueAsBoolean()) { return new BlackBoxExplanation(_reasoner.getRootOntology(), OpenlletReasonerFactory.getInstance(), _reasoner); } else { output("WARNING: black method cannot be used to explain inconsistency. Switching to glass."); return new GlassBoxExplanation(_reasoner); } } else { return new BlackBoxExplanation(_reasoner.getRootOntology(), OpenlletReasonerFactory.getInstance(), _reasoner); } } else { return new GlassBoxExplanation(_reasoner); } }
private Pair<OWLClass, OWLClass> getSubClassAxiom(final OWLClassExpression desc) { if (!(desc instanceof OWLObjectIntersectionOf)) return null; final OWLObjectIntersectionOf conj = (OWLObjectIntersectionOf) desc; if (conj.operands().count() != 2) return null; final Iterator<OWLClassExpression> conjuncts = conj.operands().iterator(); final OWLClassExpression c1 = conjuncts.next(); final OWLClassExpression c2 = conjuncts.next(); OWLClass sub = null; OWLClass sup = null; if (!c1.isAnonymous()) { sub = (OWLClass) c1; sup = getNegation(c2); } else if (!c2.isAnonymous()) { sub = (OWLClass) c2; sup = getNegation(c2); } if (sup == null) return null; return new Pair<>(sub, sup); }
private Set<OWLAxiom> getReasonerExplanation(final OWLClassExpression unsatClass) { final OpenlletReasoner reasoner = getReasoner(); reasoner.getKB().prepare(); // satisfiable if there is an undefined entity boolean sat = !getDefinitionTracker().isDefined(unsatClass); if (!sat) sat = isSatisfiable(reasoner, unsatClass, true); else _logger.fine(() -> "Undefined entity in " + unsatClass); if (sat) return Collections.emptySet(); else { final Set<OWLAxiom> explanation = convertExplanation(reasoner.getKB().getExplanationSet()); _logger.fine(() -> "Explanation " + explanation); final Set<OWLAxiom> prunedExplanation = pruneExplanation(unsatClass, explanation, true); final int prunedAxiomCount = explanation.size() - prunedExplanation.size(); if (_logger.isLoggable(Level.FINE) && prunedAxiomCount > 0) { _logger.fine("Pruned " + prunedAxiomCount + " axioms from the explanation: " + SetUtils.difference(explanation, prunedExplanation)); _logger.fine("New explanation " + prunedExplanation); } return prunedExplanation; } }
private Set<OWLAxiom> getCachedExplanation(final OWLClassExpression unsatClass) { final OpenlletReasoner pellet = getReasoner(); if (!pellet.getKB().isClassified()) return null; final Pair<OWLClass, OWLClass> pair = getSubClassAxiom(unsatClass); if (pair != null) { final Set<Set<ATermAppl>> exps = TaxonomyUtils.getSuperExplanations(pellet.getKB().getTaxonomy(), pellet.term(pair.first), pellet.term(pair.second)); if (exps != null) { final Set<OWLAxiom> result = convertExplanation(exps.iterator().next()); if (_logger.isLoggable(Level.FINE)) _logger.fine("Cached explanation: " + result); return result; } } return null; }
private PelletExplanation(final OpenlletReasoner reasoner, final boolean useGlassBox) { // Get the _factory object _factory = reasoner.getManager().getOWLDataFactory(); // Create a single explanation generator final TransactionAwareSingleExpGen singleExp = useGlassBox ? new GlassBoxExplanation(reasoner) : new BlackBoxExplanation(reasoner.getRootOntology(), new OpenlletReasonerFactory(), reasoner); // Create multiple explanation generator _expGen = new HSTExplanationGenerator(singleExp); // Create the converter that will translate axioms into class expressions _converter = new SatisfiabilityConverter(_factory); }
private void setAltReasonerEnabled(final boolean enabled) { if (enabled) if (_altReasoner == null) { _logger.fine("Create alt reasoner"); _altReasoner = getReasonerFactory().createNonBufferingReasoner(getOntology()); } _altReasonerEnabled = enabled; }
private Pair<OWLClass, OWLClass> getSubClassAxiom(final OWLClassExpression desc) { if (!(desc instanceof OWLObjectIntersectionOf)) return null; final OWLObjectIntersectionOf conj = (OWLObjectIntersectionOf) desc; if (conj.operands().count() != 2) return null; final Iterator<OWLClassExpression> conjuncts = conj.operands().iterator(); final OWLClassExpression c1 = conjuncts.next(); final OWLClassExpression c2 = conjuncts.next(); OWLClass sub = null; OWLClass sup = null; if (!c1.isAnonymous()) { sub = (OWLClass) c1; sup = getNegation(c2); } else if (!c2.isAnonymous()) { sub = (OWLClass) c2; sup = getNegation(c2); } if (sup == null) return null; return new Pair<>(sub, sup); }
private Set<OWLAxiom> getReasonerExplanation(final OWLClassExpression unsatClass) { final OpenlletReasoner reasoner = getReasoner(); reasoner.getKB().prepare(); // satisfiable if there is an undefined entity boolean sat = !getDefinitionTracker().isDefined(unsatClass); if (!sat) sat = isSatisfiable(reasoner, unsatClass, true); else _logger.fine(() -> "Undefined entity in " + unsatClass); if (sat) return Collections.emptySet(); else { final Set<OWLAxiom> explanation = convertExplanation(reasoner.getKB().getExplanationSet()); _logger.fine(() -> "Explanation " + explanation); final Set<OWLAxiom> prunedExplanation = pruneExplanation(unsatClass, explanation, true); final int prunedAxiomCount = explanation.size() - prunedExplanation.size(); if (_logger.isLoggable(Level.FINE) && prunedAxiomCount > 0) { _logger.fine("Pruned " + prunedAxiomCount + " axioms from the explanation: " + SetUtils.difference(explanation, prunedExplanation)); _logger.fine("New explanation " + prunedExplanation); } return prunedExplanation; } }
final boolean firstExplanation = isFirstExplanation(); result = getCachedExplanation(unsatClass); result = getReasonerExplanation(unsatClass); setAltReasonerEnabled(true); result = getReasonerExplanation(unsatClass); setAltReasonerEnabled(false);
private Set<OWLAxiom> getCachedExplanation(final OWLClassExpression unsatClass) { final OpenlletReasoner pellet = getReasoner(); if (!pellet.getKB().isClassified()) return null; final Pair<OWLClass, OWLClass> pair = getSubClassAxiom(unsatClass); if (pair != null) { final Set<Set<ATermAppl>> exps = TaxonomyUtils.getSuperExplanations(pellet.getKB().getTaxonomy(), pellet.term(pair.first), pellet.term(pair.second)); if (exps != null) { final Set<OWLAxiom> result = convertExplanation(exps.iterator().next()); if (_logger.isLoggable(Level.FINE)) _logger.fine("Cached explanation: " + result); return result; } } return null; }
private PelletExplanation(final OpenlletReasoner reasoner, final boolean useGlassBox) { // Get the _factory object _factory = reasoner.getManager().getOWLDataFactory(); // Create a single explanation generator final TransactionAwareSingleExpGen singleExp = useGlassBox ? new GlassBoxExplanation(reasoner) : new BlackBoxExplanation(reasoner.getRootOntology(), new OpenlletReasonerFactory(), reasoner); // Create multiple explanation generator _expGen = new HSTExplanationGenerator(singleExp); // Create the converter that will translate axioms into class expressions _converter = new SatisfiabilityConverter(_factory); }
/** * Very important initialization step that needs to be called once before a reasoner is created. This function will be called automatically when * GlassBoxExplanation is loaded by the class loader. This function simply calls the {@link GlassBoxExplanation#setup()} function. */ public static void setup() { GlassBoxExplanation.setup(); }
private void setAltReasonerEnabled(final boolean enabled) { if (enabled) if (_altReasoner == null) { _logger.fine("Create alt reasoner"); _altReasoner = getReasonerFactory().createNonBufferingReasoner(getOntology()); } _altReasonerEnabled = enabled; }
@Override public void dispose() { getOntologyManager().removeOntologyChangeListener(getDefinitionTracker()); if (_altReasoner != null) _altReasoner.dispose(); }