/** * Return the (direct or indirect) subclasses of the given * {@link ElkClassExpression} as specified by the parameter. The method * returns a set of {@link Node}s, each of which representing an equivalent * class of subclasses. Calling of this method may trigger the computation * of the taxonomy, if it has not been done yet. * * @param classExpression * the {@link ElkClassExpression} for which to return the * subclass {@link Node}s * @param direct * if {@code true}, only direct subclasses should be returned * @return the set of {@link Node}s for direct or indirect subclasses of the * given {@link ElkClassExpression} according to the specified * parameter * @throws ElkException * if the result cannot be computed */ public synchronized Set<? extends Node<ElkClass>> getSubClassesQuietly( final ElkClassExpression classExpression, final boolean direct) throws ElkException { try { return getSubClasses(classExpression, direct); } catch (final ElkInconsistentOntologyException e) { // All classes are equivalent to each other, so also to owl:Nothing. final TaxonomyNode<ElkClass> node = getTaxonomyQuietly() .getBottomNode(); return direct ? node.getDirectSubNodes() : node.getAllSubNodes(); } }
/** * Return the (direct or indirect) subclasses of the given * {@link ElkClassExpression} as specified by the parameter. The method * returns a set of {@link Node}s, each of which representing an equivalent * class of subclasses. Calling of this method may trigger the computation * of the taxonomy, if it has not been done yet. * * @param classExpression * the {@link ElkClassExpression} for which to return the * subclass {@link Node}s * @param direct * if {@code true}, only direct subclasses should be returned * @return the set of {@link Node}s for direct or indirect subclasses of the * given {@link ElkClassExpression} according to the specified * parameter * @throws ElkException * if the result cannot be computed */ public synchronized Set<? extends Node<ElkClass>> getSubClassesQuietly( final ElkClassExpression classExpression, final boolean direct) throws ElkException { try { return getSubClasses(classExpression, direct); } catch (final ElkInconsistentOntologyException e) { // All classes are equivalent to each other, so also to owl:Nothing. final TaxonomyNode<ElkClass> node = getTaxonomyQuietly() .getBottomNode(); return direct ? node.getDirectSubNodes() : node.getAllSubNodes(); } }
@Override public NodeSet<OWLClass> getSubClasses(OWLClassExpression ce, boolean direct) throws ReasonerInterruptedException, TimeOutException, FreshEntitiesException, InconsistentOntologyException, ClassExpressionNotInProfileException { LOGGER_.trace("getSubClasses(OWLClassExpression, boolean)"); checkInterrupted(); try { return elkConverter_.convertClassNodes( reasoner_.getSubClasses(owlConverter_.convert(ce), direct)); } catch (ElkUnsupportedReasoningTaskException e) { throw unsupportedOwlApiMethod( "getSubClasses(OWLClassExpression, boolean)", e.getMessage()); } catch (ElkException e) { throw elkConverter_.convert(e); } catch (ElkRuntimeException e) { throw elkConverter_.convert(e); } }
/** * Return the (direct or indirect) subclasses of the given * {@link ElkClassExpression} as specified by the parameter. The method * returns a set of {@link Node}s, each of which representing an equivalent * class of subclasses. Calling of this method may trigger the computation * of the taxonomy, if it has not been done yet. * * @param classExpression * the {@link ElkClassExpression} for which to return the * subclass {@link Node}s * @param direct * if {@code true}, only direct subclasses should be returned * @return the set of {@link Node}s for direct or indirect subclasses of the * given {@link ElkClassExpression} according to the specified * parameter * @throws ElkException * if the result cannot be computed */ public synchronized Set<? extends Node<ElkClass>> getSubClassesQuietly( final ElkClassExpression classExpression, final boolean direct) throws ElkException { try { return getSubClasses(classExpression, direct); } catch (final ElkInconsistentOntologyException e) { // All classes are equivalent to each other, so also to owl:Nothing. final TaxonomyNode<ElkClass> node = getTaxonomyQuietly() .getBottomNode(); return direct ? node.getDirectSubNodes() : node.getAllSubNodes(); } }
@Override public NodeSet<OWLClass> getSubClasses(OWLClassExpression ce, boolean direct) throws ReasonerInterruptedException, TimeOutException, FreshEntitiesException, InconsistentOntologyException, ClassExpressionNotInProfileException { LOGGER_.trace("getSubClasses(OWLClassExpression, boolean)"); checkInterrupted(); try { return elkConverter_.convertClassNodes( reasoner_.getSubClasses(owlConverter_.convert(ce), direct)); } catch (ElkUnsupportedReasoningTaskException e) { throw unsupportedOwlApiMethod( "getSubClasses(OWLClassExpression, boolean)", e.getMessage()); } catch (ElkException e) { throw elkConverter_.convert(e); } catch (ElkRuntimeException e) { throw elkConverter_.convert(e); } }
@Override public NodeSet<OWLClass> getSubClasses(OWLClassExpression ce, boolean direct) throws ReasonerInterruptedException, TimeOutException, FreshEntitiesException, InconsistentOntologyException, ClassExpressionNotInProfileException { LOGGER_.trace("getSubClasses(OWLClassExpression, boolean)"); checkInterrupted(); try { return elkConverter_.convertClassNodes( reasoner_.getSubClasses(owlConverter_.convert(ce), direct)); } catch (ElkUnsupportedReasoningTaskException e) { throw unsupportedOwlApiMethod( "getSubClasses(OWLClassExpression, boolean)", e.getMessage()); } catch (ElkException e) { throw elkConverter_.convert(e); } catch (ElkRuntimeException e) { throw elkConverter_.convert(e); } }
@Test public void testSupSubClassConjunction() throws ElkException { TestLoader loader = new TestLoader(); Reasoner reasoner = TestReasonerUtils.createTestReasoner(loader); ElkClass A = objectFactory.getClass(new ElkFullIri(":A")); ElkClass B = objectFactory.getClass(new ElkFullIri(":B")); ElkClass C = objectFactory.getClass(new ElkFullIri(":C")); loader.add(objectFactory.getSubClassOfAxiom(A, B)).add( (objectFactory.getSubClassOfAxiom(B, C))); Set<? extends Node<ElkClass>> superClasses = reasoner.getSuperClasses( objectFactory.getObjectIntersectionOf(B, C), true); assertEquals(1, superClasses.size()); for (Node<ElkClass> node : superClasses) { assertTrue(node.contains(C)); } Set<? extends Node<ElkClass>> subClasses = reasoner.getSubClasses( objectFactory.getObjectIntersectionOf(B, C), true); assertEquals(1, subClasses.size()); for (Node<ElkClass> node : subClasses) { assertTrue(node.contains(A)); } }
/** * This test is supposed to reproduce error where a partially supported * complex class was considered to be equivalent to {@code owl:Thing} by * transitive reduction, because the class and its subsumer * {@code owl:Thing} had the same number of subsumers. * * @throws ElkException */ @Test public void testPartiallySupportedExpression() throws ElkException { TestLoader loader = new TestLoader(); Reasoner reasoner = TestReasonerUtils.createTestReasoner(loader); final ElkClass A = objectFactory.getClass(new ElkFullIri(":A")); final ElkClass B = objectFactory.getClass(new ElkFullIri(":B")); final ElkClass C = objectFactory.getClass(new ElkFullIri(":C")); final ElkClass D = objectFactory.getClass(new ElkFullIri(":D")); final ElkClass top = objectFactory.getOwlThing(); final ElkClassExpression query = objectFactory.getObjectUnionOf(A, B); loader.add(objectFactory.getSubClassOfAxiom(A, C)); loader.add(objectFactory.getSubClassOfAxiom(B, C)); // negative occurrence of top, so that it is added to composed subsumers loader.add(objectFactory.getSubClassOfAxiom(top, D)); final Set<? extends Node<ElkClass>> subClasses = reasoner .getSubClasses(query, true); assertEquals(2, subClasses.size()); for (final Node<ElkClass> node : subClasses) { assertEquals(1, node.size()); assertTrue(node.contains(A) != node.contains(B)); } }