EpistemicAxiomRemover { void remove(AxiomDescriptor descriptor) { final List<OWLOntologyChange> changes = new ArrayList<>(); final OWLNamedIndividual individual = OwlapiUtils.getIndividual(descriptor.getSubject(), dataFactory); for (Assertion a : descriptor.getAssertions()) { switch (a.getType()) { case CLASS: changes.addAll(removeClassAssertionAxioms(individual)); break; case DATA_PROPERTY: changes.addAll(removeDataPropertyAssertions(individual, a)); break; case OBJECT_PROPERTY: changes.addAll(removeObjectPropertyAssertions(individual, a)); break; case ANNOTATION_PROPERTY: changes.addAll(removeAnnotationAssertions(individual, a)); break; default: break; } } if (!changes.isEmpty()) { owlapiAdapter.addTransactionalChanges(snapshot.applyChanges(changes)); } } EpistemicAxiomRemover(OwlapiAdapter adapter, OntologySnapshot snapshot);   }
@Test void removeDoesNothingWhenNoMatchingValuesAreFound() { final Assertion clsAssertion = Assertion.createClassAssertion(false); descriptor.addAssertion(clsAssertion); axiomRemover.remove(descriptor); verify(adapterMock, never()).addTransactionalChanges(anyList()); }
@Test void removeAxiomsByDescriptorWithClassAssertions() { final Assertion clsAssertion = Assertion.createClassAssertion(false); descriptor.addAssertion(clsAssertion); initClassAssertions(); axiomRemover.remove(descriptor); assertTrue(ontology.classAssertionAxioms(individual).collect(Collectors.toSet()).isEmpty()); final ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class); verify(adapterMock).addTransactionalChanges(captor.capture()); final List<?> changes = captor.getValue(); for (Object change : changes) { assertTrue(change instanceof RemoveAxiom); final RemoveAxiom ax = (RemoveAxiom) change; assertTrue(ax.getAxiom() instanceof OWLClassAssertionAxiom); } }
@Test void removeAxiomsByDescriptorWithDataPropertyAssertions() { final Assertion dpAssertion = Assertion .createDataPropertyAssertion(URI.create("http: final OWLDataProperty odp = dataFactory.getOWLDataProperty(IRI.create(dpAssertion.getIdentifier())); descriptor.addAssertion(dpAssertion); initDataPropertyAssertions(odp); final int count = EntitySearcher.getDataPropertyValues(individual, odp, ontology).collect(Collectors.toSet()).size(); axiomRemover.remove(descriptor); final ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class); verify(adapterMock).addTransactionalChanges(captor.capture()); final List<?> changes = captor.getValue(); assertEquals(count, changes.size()); verifyRemoveAxioms(odp, OWLDataPropertyAssertionAxiom.class, changes); }
@Test void removeAxiomsByDescriptorWithObjectPropertyAssertions() { final Assertion opAssertion = Assertion .createObjectPropertyAssertion(URI.create("http: final OWLObjectProperty oop = dataFactory.getOWLObjectProperty(IRI.create(opAssertion.getIdentifier())); descriptor.addAssertion(opAssertion); initObjectPropertyAssertions(oop); final int count = EntitySearcher.getObjectPropertyValues(individual, oop, ontology).collect(Collectors.toSet()).size(); axiomRemover.remove(descriptor); final ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class); verify(adapterMock).addTransactionalChanges(captor.capture()); final List<?> changes = captor.getValue(); assertEquals(count, changes.size()); verifyRemoveAxioms(oop, OWLObjectPropertyAssertionAxiom.class, changes); }
@Test void removeRetainsValuesOfAssertionsNotPresentInDescriptor() { final Assertion opAssertion = Assertion .createObjectPropertyAssertion(URI.create("http: final Assertion opAssertionTwo = Assertion .createObjectPropertyAssertion(URI.create("http: descriptor.addAssertion(opAssertion); final OWLObjectProperty opOne = dataFactory.getOWLObjectProperty(IRI.create(opAssertion.getIdentifier())); final OWLObjectProperty opTwo = dataFactory.getOWLObjectProperty(IRI.create(opAssertionTwo.getIdentifier())); initObjectPropertyAssertions(opOne, opTwo); final int countTwo = EntitySearcher.getObjectPropertyValues(individual, opTwo, ontology).collect(Collectors.toSet()).size(); axiomRemover.remove(descriptor); final int resultCountOne = EntitySearcher.getObjectPropertyValues(individual, opOne, ontology).collect(Collectors.toSet()).size(); final int resultCountTwo = EntitySearcher.getObjectPropertyValues(individual, opTwo, ontology).collect(Collectors.toSet()).size(); assertEquals(0, resultCountOne); assertEquals(countTwo, resultCountTwo); }
@Test void removeAxiomsByDescriptorWithAnnotationPropertyAssertions() { final Assertion apAssertion = Assertion.createAnnotationPropertyAssertion( URI.create("http: final OWLAnnotationProperty oap = dataFactory.getOWLAnnotationProperty(IRI.create(apAssertion.getIdentifier())); descriptor.addAssertion(apAssertion); initAnnotationAssertions(oap); axiomRemover.remove(descriptor); assertEquals(0, EntitySearcher.getAnnotationAssertionAxioms(individual.getIRI(), ontology).collect(Collectors.toSet()) .size()); final ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class); verify(adapterMock).addTransactionalChanges(captor.capture()); final List<?> changes = captor.getValue(); verifyAnnotationRemoveAxioms(oap, changes); }
@Test void removeCombinationOfDataObjectAndAnnotationPropertiesAndClassAssertion() { final Set<OWLPropertyExpression> removed = initForCombinedTest(); axiomRemover.remove(descriptor); final ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class); verify(adapterMock).addTransactionalChanges(captor.capture()); final List<?> changes = captor.getValue(); for (Object change : changes) { final RemoveAxiom ax = (RemoveAxiom) change; final OWLPropertyExpression op; if (!(ax.getAxiom() instanceof OWLClassAssertionAxiom)) { if (ax.getAxiom() instanceof OWLAnnotationAssertionAxiom) { op = ((OWLAnnotationAssertionAxiom) ax.getAxiom()).getProperty(); } else { op = ((OWLPropertyAssertionAxiom) ax.getAxiom()).getProperty(); } assertTrue(removed.contains(op)); } } }