Package: EpistemicAxiomRemover
EpistemicAxiomRemover
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
EpistemicAxiomRemover(Connector, ValueFactory, String) |
|
|
|
|
|
||||||||||||||||||||
remove(AxiomDescriptor) |
|
|
|
|
|
||||||||||||||||||||
remove(NamedResource, Map, URI) |
|
|
|
|
|
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.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 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:
31: /**
32: * This class performs an epistemic remove of axioms described by the axiom descriptor.
33: * <p/>
34: * Epistemic remove means that only information known to the application is
35: * deleted. The assertions in the descriptor represent this information. Thus,
36: * only these assertions are removed from the ontology. Note that if the
37: * descriptor contains an unspecified property assertion, all property
38: * assertions related to the subject individual are removed from the property's
39: * context.
40: */
41: class EpistemicAxiomRemover {
42:
43: private final Connector connector;
44: private final ValueFactory valueFactory;
45: private final String language;
46:
47: EpistemicAxiomRemover(Connector connector, ValueFactory valueFactory, String language) {
48: this.connector = connector;
49: this.valueFactory = valueFactory;
50: this.language = language;
51: }
52:
53: void remove(AxiomDescriptor axiomDescriptor) throws SesameDriverException {
54: final Resource individual = SesameUtils.toSesameIri(axiomDescriptor.getSubject().getIdentifier(), valueFactory);
55: final Collection<Statement> toRemove = new HashSet<>();
56:• for (Assertion a : axiomDescriptor.getAssertions()) {
57:• if (a.isInferred()) {
58: continue;
59: }
60: final IRI contextUri = SesameUtils.toSesameIri(axiomDescriptor.getAssertionContext(a), valueFactory);
61: toRemove.addAll(connector.findStatements(individual,
62: SesameUtils.toSesameIri(a.getIdentifier(), valueFactory), null, a.isInferred(), contextUri));
63: }
64: connector.removeStatements(toRemove);
65: }
66:
67: void remove(NamedResource individual, Map<Assertion, Set<Value<?>>> values, java.net.URI context)
68: throws SesameDriverException {
69: final IRI sesameContext = SesameUtils.toSesameIri(context, valueFactory);
70: final Resource subject = SesameUtils.toSesameIri(individual.getIdentifier(), valueFactory);
71: final Collection<Statement> toRemove = new ArrayList<>();
72: final SesameValueConverter valueConverter = new SesameValueConverter(valueFactory, language);
73:• for (Map.Entry<Assertion, Set<Value<?>>> entry : values.entrySet()) {
74: final IRI property = SesameUtils.toSesameIri(entry.getKey().getIdentifier(), valueFactory);
75:• for (Value<?> val : entry.getValue()) {
76: final org.eclipse.rdf4j.model.Value sesameValue = valueConverter.toSesameValue(entry.getKey(), val);
77:• if (sesameContext != null) {
78: toRemove.add(valueFactory.createStatement(subject, property, sesameValue, sesameContext));
79: } else {
80: toRemove.add(valueFactory.createStatement(subject, property, sesameValue));
81: }
82: }
83: }
84: connector.removeStatements(toRemove);
85: }
86: }