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