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.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 org.openrdf.model.Resource;
24: import org.openrdf.model.Statement;
25: import org.openrdf.model.URI;
26: import org.openrdf.model.ValueFactory;
27:
28: import java.util.*;
29:
30: /**
31: * This class performs an epistemic remove of axioms described by the axiom
32: * descriptor. </p>
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: * @author ledvima1
42: */
43: class EpistemicAxiomRemover {
44:
45: private final Connector connector;
46: private final ValueFactory valueFactory;
47: private final String language;
48:
49: EpistemicAxiomRemover(Connector connector, ValueFactory valueFactory, String language) {
50: this.connector = connector;
51: this.valueFactory = valueFactory;
52: this.language = language;
53: }
54:
55: void remove(AxiomDescriptor axiomDescriptor) throws SesameDriverException {
56: final Resource individual = SesameUtils.toSesameUri(axiomDescriptor.getSubject()
57: .getIdentifier(), valueFactory);
58: final Collection<Statement> toRemove = new HashSet<>();
59:• for (Assertion a : axiomDescriptor.getAssertions()) {
60:• if (a.isInferred()) {
61: continue;
62: }
63: toRemove.addAll(connector.findStatements(individual,
64: SesameUtils.toSesameUri(a.getIdentifier(), valueFactory), null, a.isInferred(),
65: SesameUtils.toSesameUri(axiomDescriptor.getAssertionContext(a), valueFactory)));
66: }
67: connector.removeStatements(toRemove);
68: }
69:
70: void remove(NamedResource individual, Map<Assertion, Set<Value<?>>> values, java.net.URI context) throws SesameDriverException {
71: final URI sesameContext = SesameUtils.toSesameUri(context, valueFactory);
72: final Resource subject = SesameUtils.toSesameUri(individual.getIdentifier(), valueFactory);
73: final Collection<Statement> toRemove = new ArrayList<>();
74: final SesameValueConverter valueConverter = new SesameValueConverter(valueFactory, language);
75:• for (Map.Entry<Assertion, Set<Value<?>>> entry : values.entrySet()) {
76: final URI property = SesameUtils.toSesameUri(entry.getKey().getIdentifier(), valueFactory);
77:• for (Value<?> val : entry.getValue()) {
78: final org.openrdf.model.Value sesameValue = valueConverter.toSesameValue(entry.getKey(), val);
79:• if (sesameContext != null) {
80: toRemove.add(valueFactory.createStatement(subject, property, sesameValue, sesameContext));
81: } else {
82: toRemove.add(valueFactory.createStatement(subject, property, sesameValue));
83: }
84: }
85: }
86: connector.removeStatements(toRemove);
87: }
88: }