Skip to content

Package: EpistemicAxiomRemover

EpistemicAxiomRemover

nameinstructionbranchcomplexitylinemethod
EpistemicAxiomRemover(Connector, ValueFactory, String)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
remove(AxiomDescriptor)
M: 0 C: 80
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 15
100%
M: 0 C: 1
100%
remove(NamedResource, Map, URI)
M: 11 C: 79
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) 2016 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.sesame.connector.Connector;
18: import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException;
19: import cz.cvut.kbss.ontodriver.descriptor.AxiomDescriptor;
20: import cz.cvut.kbss.ontodriver.model.Assertion;
21: import cz.cvut.kbss.ontodriver.model.NamedResource;
22: import cz.cvut.kbss.ontodriver.model.Value;
23: import cz.cvut.kbss.ontodriver.sesame.util.SesameUtils;
24: import org.openrdf.model.Resource;
25: import org.openrdf.model.Statement;
26: import org.openrdf.model.URI;
27: import org.openrdf.model.ValueFactory;
28:
29: import java.util.*;
30:
31: /**
32: * This class performs an epistemic remove of axioms described by the axiom
33: * descriptor. </p>
34: * <p/>
35: * Epistemic remove means that only information known to the application is
36: * deleted. The assertions in the descriptor represent this information. Thus,
37: * only these assertions are removed from the ontology. Note that if the
38: * descriptor contains an unspecified property assertion, all property
39: * assertions related to the subject individual are removed from the property's
40: * context.
41: */
42: class EpistemicAxiomRemover {
43:
44: private final Connector connector;
45: private final ValueFactory valueFactory;
46: private final String language;
47:
48: EpistemicAxiomRemover(Connector connector, ValueFactory valueFactory, String language) {
49: this.connector = connector;
50: this.valueFactory = valueFactory;
51: this.language = language;
52: }
53:
54: void remove(AxiomDescriptor axiomDescriptor) throws SesameDriverException {
55: final Resource individual = SesameUtils.toSesameUri(axiomDescriptor.getSubject()
56: .getIdentifier(), valueFactory);
57: final Collection<Statement> toRemove = new HashSet<>();
58:• for (Assertion a : axiomDescriptor.getAssertions()) {
59:• if (a.isInferred()) {
60: continue;
61: }
62: final URI contextUri = SesameUtils.toSesameUri(axiomDescriptor.getAssertionContext(a), valueFactory);
63:• if (contextUri != null) {
64: toRemove.addAll(connector.findStatements(individual,
65: SesameUtils.toSesameUri(a.getIdentifier(), valueFactory), null, a.isInferred(), contextUri));
66: } else {
67: toRemove.addAll(connector.findStatements(individual,
68: SesameUtils.toSesameUri(a.getIdentifier(), valueFactory), null, a.isInferred()));
69: }
70: }
71: connector.removeStatements(toRemove);
72: }
73:
74: void remove(NamedResource individual, Map<Assertion, Set<Value<?>>> values, java.net.URI context)
75: throws SesameDriverException {
76: final URI sesameContext = SesameUtils.toSesameUri(context, valueFactory);
77: final Resource subject = SesameUtils.toSesameUri(individual.getIdentifier(), valueFactory);
78: final Collection<Statement> toRemove = new ArrayList<>();
79: final SesameValueConverter valueConverter = new SesameValueConverter(valueFactory, language);
80:• for (Map.Entry<Assertion, Set<Value<?>>> entry : values.entrySet()) {
81: final URI property = SesameUtils.toSesameUri(entry.getKey().getIdentifier(), valueFactory);
82:• for (Value<?> val : entry.getValue()) {
83: final org.openrdf.model.Value sesameValue = valueConverter.toSesameValue(entry.getKey(), val);
84:• if (sesameContext != null) {
85: toRemove.add(valueFactory.createStatement(subject, property, sesameValue, sesameContext));
86: } else {
87: toRemove.add(valueFactory.createStatement(subject, property, sesameValue));
88: }
89: }
90: }
91: connector.removeStatements(toRemove);
92: }
93: }