Skip to content

Package: AxiomLoader

AxiomLoader

nameinstructionbranchcomplexitylinemethod
AxiomLoader(Connector, RuntimeConfiguration)
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
createLoader(NamedResource, AxiomBuilder)
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
findStatements(AxiomDescriptor)
M: 0 C: 57
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
loadAxioms(AxiomDescriptor)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
loadAxioms(NamedResource, boolean, URI)
M: 3 C: 19
86%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 4
100%
M: 0 C: 1
100%
processAssertions(AxiomDescriptor)
M: 0 C: 69
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 14
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2022 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.descriptor.AxiomDescriptor;
16: import cz.cvut.kbss.ontodriver.model.Assertion;
17: import cz.cvut.kbss.ontodriver.model.Axiom;
18: import cz.cvut.kbss.ontodriver.model.NamedResource;
19: import cz.cvut.kbss.ontodriver.sesame.config.RuntimeConfiguration;
20: import cz.cvut.kbss.ontodriver.sesame.connector.Connector;
21: import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException;
22: import cz.cvut.kbss.ontodriver.sesame.loader.StatementLoader;
23: import cz.cvut.kbss.ontodriver.sesame.util.AxiomBuilder;
24: import cz.cvut.kbss.ontodriver.sesame.util.SesameUtils;
25: import org.eclipse.rdf4j.model.IRI;
26:
27: import java.util.*;
28:
29: class AxiomLoader {
30:
31: private final Connector connector;
32:
33: private final Map<IRI, Assertion> propertyToAssertion;
34: private Map<IRI, Assertion> explicitAssertions;
35: private Map<IRI, Assertion> inferredAssertions;
36:
37: private final RuntimeConfiguration config;
38:
39: AxiomLoader(Connector connector, RuntimeConfiguration config) {
40: this.connector = connector;
41: this.propertyToAssertion = new HashMap<>();
42: this.config = config;
43: }
44:
45: Collection<Axiom<?>> loadAxioms(AxiomDescriptor axiomDescriptor) throws SesameDriverException {
46: return findStatements(axiomDescriptor);
47: }
48:
49: private Collection<Axiom<?>> findStatements(AxiomDescriptor descriptor) throws SesameDriverException {
50: final Collection<Axiom<?>> result = new HashSet<>();
51: final Assertion unspecified = processAssertions(descriptor);
52: final AxiomBuilder axiomBuilder = new AxiomBuilder(descriptor.getSubject(), propertyToAssertion, unspecified);
53: final StatementLoader statementLoader = createLoader(descriptor.getSubject(), axiomBuilder);
54: statementLoader.setLoadAllThreshold(config.getLoadAllThreshold());
55:• if (unspecified == null || !unspecified.isInferred()) {
56: statementLoader.setIncludeInferred(false);
57: result.addAll(statementLoader.loadAxioms(descriptor, explicitAssertions));
58: }
59: statementLoader.setIncludeInferred(true);
60: result.addAll(statementLoader.loadAxioms(descriptor, inferredAssertions));
61: return result;
62: }
63:
64: private StatementLoader createLoader(NamedResource individual, AxiomBuilder axiomBuilder) {
65: final IRI subject = SesameUtils.toSesameIri(individual.getIdentifier(), connector.getValueFactory());
66: return config.getStatementLoaderFactory().create(connector, subject, axiomBuilder);
67: }
68:
69: /**
70: * Processes assertions in the specified descriptor.
71: * <p>
72: * Splits them into explicit and inferred and returns unspecified property, if it is present in the descriptor.
73: *
74: * @param descriptor The descriptor to process
75: * @return Unspecified property, if it is present
76: */
77: private Assertion processAssertions(AxiomDescriptor descriptor) {
78: final Set<Assertion> assertions = descriptor.getAssertions();
79: this.explicitAssertions = new HashMap<>(assertions.size());
80: this.inferredAssertions = new HashMap<>(assertions.size());
81: Assertion unspecified = null;
82:• for (Assertion a : assertions) {
83: final IRI property = SesameUtils.toSesameIri(a.getIdentifier(), connector.getValueFactory());
84: propertyToAssertion.put(property, a);
85:• if (a.equals(Assertion.createUnspecifiedPropertyAssertion(a.isInferred()))) {
86: unspecified = a;
87: }
88:• if (a.isInferred()) {
89: inferredAssertions.put(property, a);
90: } else {
91: explicitAssertions.put(property, a);
92: }
93: }
94: return unspecified;
95: }
96:
97: Collection<Axiom<?>> loadAxioms(NamedResource individual, boolean includeInferred, java.net.URI context)
98: throws SesameDriverException {
99: final AxiomBuilder axiomBuilder = new AxiomBuilder(individual, Collections.emptyMap(),
100: Assertion.createUnspecifiedPropertyAssertion(includeInferred));
101: final StatementLoader loader = createLoader(individual, axiomBuilder);
102:• return loader.loadAxioms(context != null ? Collections.singleton(context) : Collections.emptySet());
103: }
104: }