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