Skip to content

Package: EpistemicAxiomRemover

EpistemicAxiomRemover

nameinstructionbranchcomplexitylinemethod
EpistemicAxiomRemover(StorageConnector)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
lambda$null$2(Resource, Property, Assertion, String, Value)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
lambda$null$4(Resource, Property, Assertion, Value)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
lambda$remove$0(Assertion)
M: 0 C: 7
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$remove$1(AxiomDescriptor, Resource, Assertion)
M: 0 C: 22
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
lambda$remove$3(Resource, String, Assertion, Set)
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
lambda$remove$5(Resource, Assertion, Set)
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
remove(AxiomDescriptor)
M: 0 C: 17
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
remove(NamedResource, Map, URI)
M: 0 C: 23
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 7
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2020 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.jena;
16:
17: import cz.cvut.kbss.ontodriver.descriptor.AxiomDescriptor;
18: import cz.cvut.kbss.ontodriver.jena.connector.StorageConnector;
19: import cz.cvut.kbss.ontodriver.jena.util.JenaUtils;
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.apache.jena.rdf.model.Property;
24: import org.apache.jena.rdf.model.Resource;
25: import org.apache.jena.rdf.model.ResourceFactory;
26:
27: import java.net.URI;
28: import java.util.Map;
29: import java.util.Set;
30:
31: /**
32: * This class performs an epistemic removal of statements.
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 statements representing these properties 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 StorageConnector connector;
44:
45: EpistemicAxiomRemover(StorageConnector connector) {
46: this.connector = connector;
47: }
48:
49: /**
50: * Removes statements corresponding to the subject and properties specified by the descriptor.
51: *
52: * @param descriptor Descriptor of statements to remove
53: */
54: void remove(AxiomDescriptor descriptor) {
55: final Resource subject = ResourceFactory.createResource(descriptor.getSubject().getIdentifier().toString());
56:• descriptor.getAssertions().stream().filter(a -> !a.isInferred()).forEach(assertion -> {
57: final URI context = descriptor.getAssertionContext(assertion);
58: final Property property = ResourceFactory.createProperty(assertion.getIdentifier().toString());
59:• connector.remove(subject, property, null, context != null ? context.toString() : null);
60: });
61: }
62:
63: /**
64: * Removes statements corresponding to the specified values.
65: * <p>
66: * This version removes precisely statements whose subject, property and object match the specified data.
67: *
68: * @param subject Statement subject
69: * @param properties Assertions to values
70: * @param context Context from which to remove the statements
71: */
72: void remove(NamedResource subject, Map<Assertion, Set<Value<?>>> properties, URI context) {
73: final Resource resource = ResourceFactory.createResource(subject.getIdentifier().toString());
74:• if (context != null) {
75: final String strCtx = context.toString();
76: properties.forEach((assertion, values) -> {
77: final Property property = ResourceFactory.createProperty(assertion.getIdentifier().toString());
78: values.forEach(value -> connector
79: .remove(resource, property, JenaUtils.valueToRdfNode(assertion, value), strCtx));
80: });
81: } else {
82: properties.forEach((assertion, values) -> {
83: final Property property = ResourceFactory.createProperty(assertion.getIdentifier().toString());
84: values.forEach(
85: value -> connector
86: .remove(resource, property, JenaUtils.valueToRdfNode(assertion, value), null));
87: });
88: }
89: }
90: }