Skip to content

Package: AxiomLoader

AxiomLoader

nameinstructionbranchcomplexitylinemethod
AxiomLoader(RepoConnection, 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: * JOPA
3: * Copyright (C) 2024 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.ontodriver.rdf4j;
19:
20: import cz.cvut.kbss.ontodriver.descriptor.AxiomDescriptor;
21: import cz.cvut.kbss.ontodriver.model.Assertion;
22: import cz.cvut.kbss.ontodriver.model.Axiom;
23: import cz.cvut.kbss.ontodriver.model.NamedResource;
24: import cz.cvut.kbss.ontodriver.rdf4j.config.RuntimeConfiguration;
25: import cz.cvut.kbss.ontodriver.rdf4j.connector.RepoConnection;
26: import cz.cvut.kbss.ontodriver.rdf4j.exception.Rdf4jDriverException;
27: import cz.cvut.kbss.ontodriver.rdf4j.loader.StatementLoader;
28: import cz.cvut.kbss.ontodriver.rdf4j.util.AxiomBuilder;
29: import cz.cvut.kbss.ontodriver.rdf4j.util.Rdf4jUtils;
30: import org.eclipse.rdf4j.model.IRI;
31:
32: import java.util.*;
33:
34: class AxiomLoader {
35:
36: private final RepoConnection connector;
37:
38: private final Map<IRI, Assertion> propertyToAssertion;
39: private Map<IRI, Assertion> explicitAssertions;
40: private Map<IRI, Assertion> inferredAssertions;
41:
42: private final RuntimeConfiguration config;
43:
44: AxiomLoader(RepoConnection connector, RuntimeConfiguration config) {
45: this.connector = connector;
46: this.propertyToAssertion = new HashMap<>();
47: this.config = config;
48: }
49:
50: Collection<Axiom<?>> loadAxioms(AxiomDescriptor axiomDescriptor) throws Rdf4jDriverException {
51: return findStatements(axiomDescriptor);
52: }
53:
54: private Collection<Axiom<?>> findStatements(AxiomDescriptor descriptor) throws Rdf4jDriverException {
55: final Collection<Axiom<?>> result = new HashSet<>();
56: final Assertion unspecified = processAssertions(descriptor);
57: final AxiomBuilder axiomBuilder = new AxiomBuilder(descriptor.getSubject(), propertyToAssertion, unspecified);
58: final StatementLoader statementLoader = createLoader(descriptor.getSubject(), axiomBuilder);
59: statementLoader.setLoadAllThreshold(config.getLoadAllThreshold());
60:• if (unspecified == null || !unspecified.isInferred()) {
61: statementLoader.setIncludeInferred(false);
62: result.addAll(statementLoader.loadAxioms(descriptor, explicitAssertions));
63: }
64: statementLoader.setIncludeInferred(true);
65: result.addAll(statementLoader.loadAxioms(descriptor, inferredAssertions));
66: return result;
67: }
68:
69: private StatementLoader createLoader(NamedResource individual, AxiomBuilder axiomBuilder) {
70: final IRI subject = Rdf4jUtils.toRdf4jIri(individual.getIdentifier(), connector.getValueFactory());
71: return config.getStatementLoaderFactory().create(connector, subject, axiomBuilder);
72: }
73:
74: /**
75: * Processes assertions in the specified descriptor.
76: * <p>
77: * Splits them into explicit and inferred and returns unspecified property, if it is present in the descriptor.
78: *
79: * @param descriptor The descriptor to process
80: * @return Unspecified property, if it is present
81: */
82: private Assertion processAssertions(AxiomDescriptor descriptor) {
83: final Set<Assertion> assertions = descriptor.getAssertions();
84: this.explicitAssertions = new HashMap<>(assertions.size());
85: this.inferredAssertions = new HashMap<>(assertions.size());
86: Assertion unspecified = null;
87:• for (Assertion a : assertions) {
88: final IRI property = Rdf4jUtils.toRdf4jIri(a.getIdentifier(), connector.getValueFactory());
89: propertyToAssertion.put(property, a);
90:• if (a.equals(Assertion.createUnspecifiedPropertyAssertion(a.isInferred()))) {
91: unspecified = a;
92: }
93:• if (a.isInferred()) {
94: inferredAssertions.put(property, a);
95: } else {
96: explicitAssertions.put(property, a);
97: }
98: }
99: return unspecified;
100: }
101:
102: Collection<Axiom<?>> loadAxioms(NamedResource individual, boolean includeInferred, java.net.URI context)
103: throws Rdf4jDriverException {
104: final AxiomBuilder axiomBuilder = new AxiomBuilder(individual, Collections.emptyMap(),
105: Assertion.createUnspecifiedPropertyAssertion(includeInferred));
106: final StatementLoader loader = createLoader(individual, axiomBuilder);
107:• return loader.loadAxioms(context != null ? Collections.singleton(context) : Collections.emptySet());
108: }
109: }