Package: AxiomLoader
AxiomLoader
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
AxiomLoader(Connector, RuntimeConfiguration) |
|
|
|
|
|
||||||||||||||||||||
createLoader(NamedResource, AxiomBuilder) |
|
|
|
|
|
||||||||||||||||||||
findStatements(AxiomDescriptor) |
|
|
|
|
|
||||||||||||||||||||
loadAxioms(AxiomDescriptor) |
|
|
|
|
|
||||||||||||||||||||
loadAxioms(NamedResource, boolean, URI) |
|
|
|
|
|
||||||||||||||||||||
processAssertions(AxiomDescriptor) |
|
|
|
|
|
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.rdf4j;
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.rdf4j.config.RuntimeConfiguration;
20: import cz.cvut.kbss.ontodriver.rdf4j.connector.Connector;
21: import cz.cvut.kbss.ontodriver.rdf4j.exception.Rdf4jDriverException;
22: import cz.cvut.kbss.ontodriver.rdf4j.loader.StatementLoader;
23: import cz.cvut.kbss.ontodriver.rdf4j.util.AxiomBuilder;
24: import cz.cvut.kbss.ontodriver.rdf4j.util.Rdf4jUtils;
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 Rdf4jDriverException {
46: return findStatements(axiomDescriptor);
47: }
48:
49: private Collection<Axiom<?>> findStatements(AxiomDescriptor descriptor) throws Rdf4jDriverException {
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 = Rdf4jUtils.toRdf4jIri(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 = Rdf4jUtils.toRdf4jIri(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 Rdf4jDriverException {
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: }