Skip to content

Package: EpistemicAxiomRemover

EpistemicAxiomRemover

nameinstructionbranchcomplexitylinemethod
EpistemicAxiomRemover(Connector, ValueFactory)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
lambda$remove$0(URI)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
remove(AbstractAxiomDescriptor)
M: 0 C: 59
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 13
100%
M: 0 C: 1
100%
remove(NamedResource, Map, URI)
M: 11 C: 77
88%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 1 C: 14
93%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2022 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.ontodriver.sesame;
16:
17: import cz.cvut.kbss.ontodriver.descriptor.AbstractAxiomDescriptor;
18: import cz.cvut.kbss.ontodriver.model.Assertion;
19: import cz.cvut.kbss.ontodriver.model.NamedResource;
20: import cz.cvut.kbss.ontodriver.model.Value;
21: import cz.cvut.kbss.ontodriver.sesame.connector.Connector;
22: import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException;
23: import cz.cvut.kbss.ontodriver.sesame.util.SesameUtils;
24: import org.eclipse.rdf4j.model.IRI;
25: import org.eclipse.rdf4j.model.Resource;
26: import org.eclipse.rdf4j.model.Statement;
27: import org.eclipse.rdf4j.model.ValueFactory;
28:
29: import java.util.*;
30: import java.util.stream.Collectors;
31:
32: /**
33: * This class performs an epistemic remove of axioms described by the axiom descriptor.
34: * <p/>
35: * Epistemic remove means that only information known to the application is deleted. The assertions in the descriptor
36: * represent this information. Thus, only these assertions are removed from the ontology. Note that if the descriptor
37: * contains an unspecified property assertion, all property assertions related to the subject individual are removed
38: * from the property's context.
39: */
40: class EpistemicAxiomRemover {
41:
42: private final Connector connector;
43: private final ValueFactory valueFactory;
44:
45: EpistemicAxiomRemover(Connector connector, ValueFactory valueFactory) {
46: this.connector = connector;
47: this.valueFactory = valueFactory;
48: }
49:
50: void remove(AbstractAxiomDescriptor axiomDescriptor) throws SesameDriverException {
51: final Resource individual = SesameUtils.toSesameIri(axiomDescriptor.getSubject().getIdentifier(), valueFactory);
52: final Collection<Statement> toRemove = new HashSet<>();
53:• for (Assertion a : axiomDescriptor.getAssertions()) {
54:• if (a.isInferred()) {
55: continue;
56: }
57: final Set<IRI> contexts = axiomDescriptor.getAssertionContexts(a).stream()
58: .map(uri -> SesameUtils.toSesameIri(uri, valueFactory))
59: .collect(Collectors.toSet());
60: toRemove.addAll(connector.findStatements(individual,
61: SesameUtils.toSesameIri(a.getIdentifier(), valueFactory), null, a.isInferred(), contexts));
62: }
63: connector.removeStatements(toRemove);
64: }
65:
66: void remove(NamedResource individual, Map<Assertion, Set<Value<?>>> values, java.net.URI context)
67: throws SesameDriverException {
68: final IRI sesameContext = SesameUtils.toSesameIri(context, valueFactory);
69: final Resource subject = SesameUtils.toSesameIri(individual.getIdentifier(), valueFactory);
70: final Collection<Statement> toRemove = new ArrayList<>();
71: final SesameValueConverter valueConverter = new SesameValueConverter(valueFactory);
72:• for (Map.Entry<Assertion, Set<Value<?>>> entry : values.entrySet()) {
73: final IRI property = SesameUtils.toSesameIri(entry.getKey().getIdentifier(), valueFactory);
74:• for (Value<?> val : entry.getValue()) {
75: final org.eclipse.rdf4j.model.Value sesameValue = valueConverter.toSesameValue(entry.getKey(), val);
76:• if (sesameContext != null) {
77: toRemove.add(valueFactory.createStatement(subject, property, sesameValue, sesameContext));
78: } else {
79: toRemove.add(valueFactory.createStatement(subject, property, sesameValue));
80: }
81: }
82: }
83: connector.removeStatements(toRemove);
84: }
85: }