Skip to content

Package: AxiomLoader

AxiomLoader

nameinstructionbranchcomplexitylinemethod
AxiomLoader(Connector, ValueFactory)
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%
findStatements(AxiomDescriptor)
M: 0 C: 60
100%
M: 1 C: 3
75%
M: 1 C: 2
67%
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: 15 C: 43
74%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 7
88%
M: 0 C: 1
100%
processAssertions(AxiomDescriptor)
M: 0 C: 68
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 13
100%
M: 0 C: 1
100%

Coverage

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