OwlapiAdapter { boolean containsAxiom(Axiom<?> axiom, URI context) { startTransactionIfNotActive(); final Collection<OWLAxiom> owlAxiom = asOwlAxioms(axiom); boolean contains; for (OWLAxiom ax : owlAxiom) { if (axiom.getAssertion().isInferred()) { contains = reasoner().isEntailed(ax); } else { contains = ontology().containsAxiom(ax); } if (contains) { return true; } } return false; } OwlapiAdapter(Connector connector); void addTransactionalChanges(Collection<OWLOntologyChange> changes); ListHandler<SimpleListDescriptor, SimpleListValueDescriptor> getSimpleListHandler(); ListHandler<ReferencedListDescriptor, ReferencedListValueDescriptor> getReferencedListHandler(); OwlapiStatement createStatement(OwlapiConnection connection); OwlapiPreparedStatement prepareStatement(String statement, OwlapiConnection connection); T unwrap(Class<T> cls);  }
@Test void testContainsUnknownContext() { final Axiom<?> axiom = initAxiomForContains(Assertion.AssertionType.CLASS, false); final URI context = URI.create("http: boolean res = adapter.containsAxiom(axiom, context); assertFalse(res); }
@Test void testContainsClassAssertionAxiomNoContext() { final Axiom<?> axiom = initAxiomForContains(Assertion.AssertionType.CLASS, false); addAxiomToOntology(axiom); boolean res = adapter.containsAxiom(axiom, null); assertTrue(res); final ArgumentCaptor<OWLAxiom> captor = ArgumentCaptor.forClass(OWLAxiom.class); verify(ontology).containsAxiom(captor.capture()); final OWLAxiom ax = captor.getValue(); assertTrue(ax.isOfType(AxiomType.CLASS_ASSERTION)); final Set<OWLClass> types = ax.classesInSignature().collect(Collectors.toSet()); assertEquals(1, types.size()); final OWLClass cls = types.iterator().next(); assertEquals(axiom.getValue().getValue(), cls.getIRI().toURI()); }
@Test void testContainsObjectPropertyAssertionInferred() { final Axiom<?> axiom = initAxiomForContains(Assertion.AssertionType.OBJECT_PROPERTY, true); final URI ctx = getOntologyUri(); when(reasonerMock.isEntailed(any(OWLAxiom.class))).thenReturn(Boolean.TRUE); boolean res = adapter.containsAxiom(axiom, ctx); assertTrue(res); final ArgumentCaptor<OWLAxiom> captor = ArgumentCaptor.forClass(OWLAxiom.class); verify(reasonerMock).isEntailed(captor.capture()); final OWLAxiom ax = captor.getValue(); assertTrue(ax.isOfType(AxiomType.OBJECT_PROPERTY_ASSERTION)); final Set<OWLNamedIndividual> individuals = ax.individualsInSignature().collect(Collectors.toSet()); assertEquals(2, individuals.size()); assertTrue(individuals.contains(factory.getOWLNamedIndividual(IRI.create(axiom.getSubject().toString())))); assertTrue(individuals.contains(factory.getOWLNamedIndividual(IRI.create(axiom.getValue().stringValue())))); final Set<OWLObjectProperty> objProperties = ax.objectPropertiesInSignature().collect(Collectors.toSet()); assertEquals(1, objProperties.size()); assertEquals(axiom.getAssertion().getIdentifier(), objProperties.iterator().next().getIRI().toURI()); }
@Test void testContainsDataProperty() { final Axiom<?> axiom = initAxiomForContains(Assertion.AssertionType.DATA_PROPERTY, false); addAxiomToOntology(axiom); boolean res = adapter.containsAxiom(axiom, null); assertTrue(res); final ArgumentCaptor<OWLAxiom> captor = ArgumentCaptor.forClass(OWLAxiom.class); verify(ontology).containsAxiom(captor.capture()); final OWLAxiom ax = captor.getValue(); assertTrue(ax.isOfType(AxiomType.DATA_PROPERTY_ASSERTION)); final Set<OWLDataProperty> dataProperties = ax.dataPropertiesInSignature().collect(Collectors.toSet()); assertEquals(1, dataProperties.size()); assertEquals(axiom.getAssertion().getIdentifier(), dataProperties.iterator().next().getIRI().toURI()); final Set<OWLNamedIndividual> individuals = ax.individualsInSignature().collect(Collectors.toSet()); assertEquals(1, individuals.size()); assertEquals(axiom.getSubject().getIdentifier(), individuals.iterator().next().getIRI().toURI()); assertTrue(ax instanceof OWLDataPropertyAssertionAxiom); assertEquals(axiom.getValue().stringValue(), ((OWLDataPropertyAssertionAxiom) ax).getObject().getLiteral()); }
@Test void testContainsAnnotationPropertyInferred() { final Axiom<?> axiom = initAxiomForContains(Assertion.AssertionType.ANNOTATION_PROPERTY, true); when(reasonerMock.isEntailed(any(OWLAxiom.class))).thenReturn(Boolean.TRUE); boolean res = adapter.containsAxiom(axiom, null); assertTrue(res); final ArgumentCaptor<OWLAxiom> captor = ArgumentCaptor.forClass(OWLAxiom.class); verify(reasonerMock).isEntailed(captor.capture()); final OWLAxiom ax = captor.getValue(); assertTrue(ax.isOfType(AxiomType.ANNOTATION_ASSERTION)); final Set<OWLAnnotationProperty> annotationProperties = ax.annotationPropertiesInSignature().collect(Collectors.toSet()); assertEquals(1, annotationProperties.size()); assertEquals(axiom.getAssertion().getIdentifier(), annotationProperties.iterator().next().getIRI().toURI()); assertTrue(ax instanceof OWLAnnotationAssertionAxiom); final OWLAnnotationAssertionAxiom assertionAxiom = (OWLAnnotationAssertionAxiom) ax; assertEquals(axiom.getValue().stringValue(), assertionAxiom.getAnnotation().getValue().asLiteral().get().getLiteral()); }