Refine search
@Override public Collection<OWLClass> getOwlClasses() { if (allClasses == null) { allClasses = new HashSet<OWLClass>(ontology.getClassesInSignature()); allClasses.removeAll(reasoner.getUnsatisfiableClasses().getEntities()); allClasses.removeAll(reasoner.getEquivalentClasses(factory.getOWLThing()).getEntities()); } return allClasses; }
@Override public boolean containsEntity(E e) { for (Node<E> node : nodes) { if (node.contains(e)) { return true; } } return false; }
private TreeSet<OWLDataProperty> getFirstDatatypeProperties(NodeSet<OWLDataProperty> nodeSet) { TreeSet<OWLDataProperty> roles = new TreeSet<>(); for (Node<OWLDataProperty> node : nodeSet) { if (node.isBottomNode() || node.isTopNode()) { continue; } if(node.getSize() == 0){ logger.warn("Reasoner returned empty property node. Could be a bug."); continue; } OWLDataProperty property = node.getRepresentativeElement(); roles.add(property); } // we ignore top and bottom properties roles.remove(df.getOWLTopDataProperty()); roles.remove(df.getOWLBottomDataProperty()); return roles; }
private Set<OWLClass> getFirstClassesNoTopBottom(NodeSet<OWLClass> nodeSet) { Set<OWLClass> concepts = new HashSet<>(); for (Node<OWLClass> node : nodeSet) { if(!node.isBottomNode() && !node.isTopNode()){ concepts.add(node.getRepresentativeElement()); } } return concepts; }
private TreeSet<OWLClassExpression> getFirstClasses(NodeSet<OWLClass> nodeSet) { TreeSet<OWLClassExpression> concepts = new TreeSet<>(); for (Node<OWLClass> node : nodeSet) { // take one element from the set and ignore the rest // (TODO: we need to make sure we always ignore the same concepts) if(node.getSize() != 0) { OWLClass concept = node.getRepresentativeElement(); concepts.add(concept); } else { logger.warn("Reasoner returned empty node. Seems to be a bug."); } } return concepts; }
@Override public NodeSet<OWLClass> getObjectPropertyDomains(OWLObjectPropertyExpression pe, boolean direct) { ensurePrepared(); DefaultNodeSet<OWLClass> result = new OWLClassNodeSet(); Consumer<? super OWLObjectPropertyDomainAxiom> domains = axiom -> { result.addNode(getEquivalentClasses(axiom.getDomain())); if (!direct) { result.addAllNodes(getSuperClasses(axiom.getDomain(), false).nodes()); } }; Consumer<? super OWLObjectPropertyRangeAxiom> inverseRanges = ax -> { result.addNode(getEquivalentClasses(ax.getRange())); if (!direct) { result.addAllNodes(getSuperClasses(ax.getRange(), false).nodes()); } }; getRootOntology().importsClosure().flatMap(o -> o.objectPropertyDomainAxioms(pe)) .forEach(domains); getRootOntology().importsClosure() .forEach(o -> getInverseObjectProperties(pe).entities().forEach(invPe -> o .objectPropertyRangeAxioms(invPe).forEach(inverseRanges))); return result; }
@Override public Set<OWLLiteral> getDataPropertyValues(OWLNamedIndividual ind, OWLDataProperty pe) { ensurePrepared(); Set<OWLLiteral> literals = new HashSet<>(); Set<OWLDataProperty> superProperties = asUnorderedSet( Stream.concat(getSuperDataProperties(pe, false) .entities(), getEquivalentDataProperties(pe).entities())); getRootOntology().importsClosure().flatMap(o -> o.dataPropertyAssertionAxioms(ind)) .forEach(ax -> { if (superProperties.contains(ax.getProperty().asOWLDataProperty())) { literals.add(ax.getObject()); } }); return literals; }
@SafeVarargs final protected static <E extends OWLObject> void assertEquals(final NodeSet<E> actual, final Set<E>... expected) { final Set<Set<E>> expectedSet = SetUtils.create(expected); final Iterable<Node<E>> it = actual.nodes()::iterator; for (final Node<E> node : it) { final Set<E> entities = node.entities().collect(Collectors.toSet()); assertTrue("Unexpected value: " + entities + "\tremaing:{" + expectedSet + "}", expectedSet.remove(entities)); } assertTrue("Missing values: " + expectedSet, expectedSet.isEmpty()); }
@Override protected void addAxioms(OWLClass entity, OWLReasoner reasoner, OWLDataFactory dataFactory, Set<OWLDisjointClassesAxiom> result) { reasoner.precomputeInferences(InferenceType.DISJOINT_CLASSES); reasoner.getDisjointClasses(entity).forEach(cls -> cls.entities() .forEach(c -> result.add(dataFactory.getOWLDisjointClassesAxiom(entity, c)))); }
public NodeSet<T> getNodeHierarchyChildren(T parent, boolean direct, DefaultNodeSet<T> ns) { Node<T> node = nodeCache.getNode(parent); if (node.isBottomNode()) { return ns; } Set<T> directChildren = new HashSet<>(); for (T equiv : node) { directChildren.addAll(rawParentChildProvider.getChildren(equiv)); if (directParentsOfBottomNode.contains(equiv)) { ns.addNode(nodeCache.getBottomNode()); } } node.entities().forEach(directChildren::remove); if (node.isTopNode()) { // Special treatment directChildren.addAll(directChildrenOfTopNode); } for (Node<T> childNode : nodeCache.getNodes(directChildren)) { ns.addNode(childNode); } if (!direct) { for (T child : directChildren) { getNodeHierarchyChildren(child, direct, ns); } } return ns; }
private void computeCandidateRoots() throws ExplanationException { List<OWLClass> unsatisfiableClasses = asList(reasoner.getUnsatisfiableClasses().entities()); SuperClassChecker checker = new SuperClassChecker(); for (OWLClass cls : unsatisfiableClasses) { checker.reset(); EntitySearcher.getSuperClasses(cls, reasoner.getRootOntology().importsClosure()).forEach(sup-> sup.accept(checker)); EntitySearcher.getEquivalentClasses(cls, reasoner.getRootOntology().importsClosure()).forEach(sup-> sup.accept(checker)); Set<OWLClass> dependencies = checker.getDependencies(); child2Parent.put(cls, new HashSet<>(dependencies)); if (dependencies.isEmpty()) { // Definite root? roots.add(cls); } } }
/** * Test for #447 */ @Test public void testGetUnsatClasses() { createReasoner(OWL.disjointClasses(_A, _B), OWL.equivalentClasses(_C, OWL.and(_A, _B))); assertStreamAsSetEquals(Stream.of(_C, OWL.Nothing), _reasoner.getUnsatisfiableClasses().entities()); assertStreamAsSetEquals(Stream.of(_C, OWL.Nothing), _reasoner.getEquivalentClasses(_C).entities()); }
@Test public void testObjectRangeWithEquivalents() { createReasoner(OWL.equivalentClasses(_C, some(inverse(_p), OWL.Thing)), OWL.range(_p, _D), OWL.subClassOf(_C, _E)); _reasoner.getKB().printClassTree(); assertTrue(_reasoner.isEntailed(OWL.range(_p, _C))); assertStreamAsSetEquals(Stream.of(_C), _reasoner.getEquivalentClasses(some(inverse(_p), OWL.Thing)).entities()); assertStreamAsSetEquals(Stream.of(_C), _reasoner.getObjectPropertyRanges(_p, true).entities()); assertStreamAsSetEquals(Stream.of(_C, _D, _E, OWL.Thing), _reasoner.getObjectPropertyRanges(_p, false).entities()); }
reasoner.precomputeInferences(); this.eqp.add(this.dataFactory.getOWLObjectProperty(IRI.create(property))); ExecutorService aliveKeeper = null; for (OWLClass c: this.ontology.getClassesInSignature(this.include_import_closure)) { if (!reasoner.isSatisfiable(c)) { continue; NodeSet<OWLClass> superClassNodeSet = reasoner.getSuperClasses(c, true); if (superClassNodeSet.isEmpty()) { if (superClassNode.isTopNode()) { for (OWLClass superClass: superClassNode.getEntitiesMinusBottom()) { superClassString = superClass.toString(); superClassUri = this.extractUri(superClassString); for (OWLSubClassOfAxiom axiom: this.ontology.getSubClassAxiomsForSubClass(c)) {
public void computeSampleExplanations(OWLOntology reference, int nrOfExplanations) throws IOException{ Set<Set<OWLAxiom>> sampleExplanations = new HashSet<>(); manager = reference.getOWLOntologyManager(); manager.removeAxioms(reference, getBlackList()); Set<OWLClass> unsatisfiableClasses = reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom(); logger.info("Unsatisfiable classes(" + unsatisfiableClasses.size() + "): " + unsatisfiableClasses); Set<OWLObjectProperty> unsatisfiableObjectProperties = getUnsatisfiableObjectProperties(reasoner); module = extractSampleModule(resource);module.getOWLOntologyManager().removeAxioms(module, module.getAxioms(AxiomType.DATA_PROPERTY_ASSERTION)); manager.addAxioms(reference, module.getABoxAxioms(Imports.INCLUDED)); manager.removeAxioms(reference, reference.getAxioms(AxiomType.DATA_PROPERTY_ASSERTION));
public NodeSet<OWLClass> getObjectPropertyDomains(OWLObjectPropertyExpression pe, boolean direct) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { DefaultNodeSet<OWLClass> result = new OWLClassNodeSet(); for (OWLOntology ontology : getRootOntology().getImportsClosure()) { for (OWLObjectPropertyDomainAxiom axiom : ontology.getObjectPropertyDomainAxioms(pe)) { result.addNode(getEquivalentClasses(axiom.getDomain())); if (!direct) { result.addAllNodes(getSuperClasses(axiom.getDomain(), false).getNodes()); } } for (OWLObjectPropertyExpression invPe : getInverseObjectProperties(pe).getEntities()) { for (OWLObjectPropertyRangeAxiom axiom : ontology.getObjectPropertyRangeAxioms(invPe)) { result.addNode(getEquivalentClasses(axiom.getRange())); if (!direct) { result.addAllNodes(getSuperClasses(axiom.getRange(), false).getNodes()); } } } } return result; }
@Override public boolean isSatisfiable(OWLClassExpression classExpression) { return !classExpression.isAnonymous() && !getEquivalentClasses(classExpression.asOWLClass()) .contains( getDataFactory().getOWLNothing()); }
@Override protected void addAxioms(OWLClass entity, OWLReasoner reasoner, OWLDataFactory dataFactory, Set<OWLEquivalentClassesAxiom> result) { Set<OWLClassExpression> equivalentClasses = asUnorderedSet( reasoner.getEquivalentClasses(entity).entities(), OWLClassExpression.class); equivalentClasses.add(entity); if (equivalentClasses.size() > 1) { result.add(dataFactory.getOWLEquivalentClassesAxiom(equivalentClasses)); } }
protected void addAxioms(OWLClass entity, OWLReasoner reasoner, OWLDataFactory dataFactory, Set<OWLEquivalentClassesAxiom> result) { Set<OWLClassExpression> equivalentClasses = new HashSet<OWLClassExpression>(reasoner.getEquivalentClasses(entity).getEntities()); equivalentClasses.add(entity); if (equivalentClasses.size() > 1) { result.add(dataFactory.getOWLEquivalentClassesAxiom(equivalentClasses)); } }