EpistemicAxiomRemover { void removeAxioms(NamedResource subject, Map<Assertion, Set<Value<?>>> toRemove) { final List<OWLOntologyChange> changes = new ArrayList<>(); final OWLNamedIndividual individual = OwlapiUtils.getIndividual(subject, dataFactory); for (Map.Entry<Assertion, Set<Value<?>>> e : toRemove.entrySet()) { final IRI assertionIri = IRI.create(e.getKey().getIdentifier()); if (ontology.containsDataPropertyInSignature(assertionIri)) { changes.addAll(removeDataPropertyAssertions(individual, e.getKey(), e.getValue())); } else if (ontology.containsObjectPropertyInSignature(assertionIri)) { changes.addAll(removeObjectPropertyAssertions(individual, assertionIri, e.getValue())); } else if (ontology.containsAnnotationPropertyInSignature(assertionIri)) { changes.addAll(removeAnnotationAssertions(individual, e.getKey(), e.getValue())); } else if (e.getKey().isClassAssertion()) { changes.addAll(removeClassAssertionAxioms(individual, e.getValue())); } } owlapiAdapter.addTransactionalChanges(snapshot.applyChanges(changes)); } EpistemicAxiomRemover(OwlapiAdapter adapter, OntologySnapshot snapshot);   }
@Test void removeAxiomsRemovesCorrespondingAssertions() { final Map<Assertion, Set<Value<?>>> toRemove = initForRemoveAxiomsTest(); axiomRemover.removeAxioms(SUBJECT, toRemove); final ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class); verify(adapterMock).addTransactionalChanges(captor.capture()); final List<?> changes = captor.getValue(); final int toRemoveSize = toRemove.values().stream().mapToInt(Set::size).sum(); assertEquals(toRemoveSize, changes.size()); for (Object change : changes) { final RemoveAxiom ax = (RemoveAxiom) change; final Assertion a; if (ax.getAxiom().annotationPropertiesInSignature().anyMatch(x -> true)) { a = Assertion.createPropertyAssertion( ax.getAxiom().annotationPropertiesInSignature().iterator().next().getIRI().toURI(), false); } else if (ax.getAxiom().dataPropertiesInSignature().anyMatch(x -> true)) { a = Assertion.createPropertyAssertion( ax.getAxiom().dataPropertiesInSignature().iterator().next().getIRI().toURI(), false); } else if (ax.getAxiom().objectPropertiesInSignature().anyMatch(x -> true)) { a = Assertion.createPropertyAssertion( ax.getAxiom().objectPropertiesInSignature().iterator().next().getIRI().toURI(), false); } else { a = Assertion.createPropertyAssertion(URI.create(Vocabulary.RDF_TYPE), false); } assertTrue(toRemove.containsKey(a)); } }
@Test void removeAxiomsWithUnknownPropertyDoesNothing() { final Map<Assertion, Set<Value<?>>> toRemove = new HashMap<>(); final Assertion unknownProperty = Assertion .createPropertyAssertion(URI.create("http: toRemove.put(unknownProperty, Collections.singleton(new Value<>("StringValue"))); axiomRemover.removeAxioms(SUBJECT, toRemove); verify(manager, never()).applyChange(any(OWLOntologyChange.class)); verify(manager).applyChanges(Collections.emptyList()); }