Skip to content

Package: SnapshotStorageConnectorWithInference

SnapshotStorageConnectorWithInference

nameinstructionbranchcomplexitylinemethod
SnapshotStorageConnectorWithInference(AbstractStorageConnector, Map)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
contains(Resource, Property, RDFNode, Collection)
M: 0 C: 23
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
containsWithInference(Resource, Property, RDFNode, Collection)
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%
find(Resource, Property, RDFNode, Collection)
M: 0 C: 29
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
findWithInference(Resource, Property, RDFNode, Collection)
M: 0 C: 28
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
isConsistent(String)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
lambda$contains$1(Resource, Property, RDFNode, String)
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$containsWithInference$3(Resource, Property, RDFNode, String)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$find$0(Resource, Property, RDFNode, String)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
lambda$findWithInference$2(Resource, Property, RDFNode, String)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
snapshotCentralDataset()
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2020 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.jena.connector;
14:
15: import org.apache.jena.rdf.model.Property;
16: import org.apache.jena.rdf.model.RDFNode;
17: import org.apache.jena.rdf.model.Resource;
18: import org.apache.jena.rdf.model.Statement;
19:
20: import java.util.Collection;
21: import java.util.List;
22: import java.util.Map;
23: import java.util.stream.Collectors;
24:
25: /**
26: * This connector implementation supports proper inference.
27: */
28: class SnapshotStorageConnectorWithInference extends SnapshotStorageConnector implements InferredStorageConnector {
29:
30: private final Map<String, String> reasonerConfig;
31:
32: SnapshotStorageConnectorWithInference(AbstractStorageConnector centralConnector,
33: Map<String, String> reasonerConfig) {
34: super(centralConnector);
35: this.reasonerConfig = reasonerConfig;
36: }
37:
38: @Override
39: void snapshotCentralDataset() {
40: final SnapshotStorageWithInference s = new SnapshotStorageWithInference(configuration, reasonerConfig);
41: s.initialize();
42: s.addCentralData(centralConnector.getStorage().getDataset());
43: this.storage = s;
44: }
45:
46: @Override
47: public List<Statement> find(Resource subject, Property property, RDFNode value, Collection<String> contexts) {
48: ensureTransactionalState();
49:• if (contexts.isEmpty()) {
50: return ((SnapshotStorageWithInference) storage).getRawDefaultGraph()
51: .listStatements(subject, property, value).toList();
52: } else {
53: return contexts.stream().map(ctx -> ((SnapshotStorageWithInference) storage).getRawNamedGraph(ctx)
54: .listStatements(subject,
55: property, value)
56: .toList())
57: .flatMap(Collection::stream).collect(Collectors.toList());
58: }
59: }
60:
61: @Override
62: public boolean contains(Resource subject, Property property, RDFNode value, Collection<String> contexts) {
63: ensureTransactionalState();
64:• if (contexts.isEmpty()) {
65: return ((SnapshotStorageWithInference) storage).getRawDefaultGraph().contains(subject, property, value);
66: } else {
67: return contexts.stream().anyMatch(c -> ((SnapshotStorageWithInference) storage).getRawNamedGraph(c)
68: .contains(subject, property,
69: value));
70: }
71: }
72:
73: @Override
74: public List<Statement> findWithInference(Resource subject, Property property, RDFNode value,
75: Collection<String> contexts) {
76: ensureTransactionalState();
77:• if (contexts.isEmpty()) {
78: return storage.getDefaultGraph().listStatements(subject, property, value).toList();
79: } else {
80: return contexts.stream()
81: .map(ctx -> storage.getNamedGraph(ctx).listStatements(subject, property, value).toList())
82: .flatMap(Collection::stream).collect(Collectors.toList());
83: }
84: }
85:
86: @Override
87: public boolean containsWithInference(Resource subject, Property property, RDFNode value,
88: Collection<String> contexts) {
89: ensureTransactionalState();
90:• if (contexts.isEmpty()) {
91: return storage.getDefaultGraph().contains(subject, property, value);
92: } else {
93: return contexts.stream().anyMatch(c -> storage.getNamedGraph(c).contains(subject, property, value));
94: }
95: }
96:
97: @Override
98: public boolean isConsistent(String context) {
99: ensureTransactionalState();
100: return ((SnapshotStorageWithInference) storage).checkConsistency(context).isValid();
101: }
102: }