Skip to content

Package: MainAxiomLoader

MainAxiomLoader

nameinstructionbranchcomplexitylinemethod
MainAxiomLoader(OwlapiAdapter, OntologySnapshot)
M: 0 C: 28
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
findAxioms(AxiomDescriptor)
M: 0 C: 33
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
lambda$loadExplicitValues$1(Axiom)
M: 0 C: 11
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$resolveInferredAssertions$0(Assertion)
M: 0 C: 21
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
loadExplicitValues(NamedResource)
M: 0 C: 27
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
loadInferredValues(NamedResource)
M: 0 C: 18
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
resolveInferredAssertions(AxiomDescriptor)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
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.owlapi;
16:
17: import cz.cvut.kbss.ontodriver.owlapi.connector.OntologySnapshot;
18: import cz.cvut.kbss.ontodriver.descriptor.AxiomDescriptor;
19: import cz.cvut.kbss.ontodriver.model.Assertion;
20: import cz.cvut.kbss.ontodriver.model.Axiom;
21: import cz.cvut.kbss.ontodriver.model.NamedResource;
22: import org.semanticweb.owlapi.model.IRI;
23: import org.semanticweb.owlapi.model.OWLOntology;
24:
25: import java.net.URI;
26: import java.util.*;
27: import java.util.stream.Collectors;
28:
29: class MainAxiomLoader {
30:
31: private final OwlapiAdapter adapter;
32: private final OntologySnapshot snapshot;
33:
34: private OWLOntology ontology;
35:
36: private Set<URI> inferredAssertionUris = new HashSet<>();
37: private Set<Assertion> inferredAssertions = new HashSet<>();
38: private Set<Assertion> explicitAssertions = new HashSet<>();
39:
40: MainAxiomLoader(OwlapiAdapter adapter, OntologySnapshot snapshot) {
41: this.adapter = adapter;
42: this.snapshot = snapshot;
43: this.ontology = snapshot.getOntology();
44: }
45:
46: Collection<Axiom<?>> findAxioms(AxiomDescriptor descriptor) {
47: final NamedResource subject = descriptor.getSubject();
48:• if (!ontology.containsIndividualInSignature(IRI.create(subject.getIdentifier()))) {
49: return Collections.emptySet();
50: }
51: final Collection<Axiom<?>> result = new ArrayList<>();
52: resolveInferredAssertions(descriptor);
53:
54: result.addAll(loadInferredValues(subject));
55: result.addAll(loadExplicitValues(subject));
56: return result;
57: }
58:
59: private void resolveInferredAssertions(AxiomDescriptor descriptor) {
60: descriptor.getAssertions().forEach(assertion -> {
61:• if (assertion.isInferred()) {
62: inferredAssertionUris.add(assertion.getIdentifier());
63: inferredAssertions.add(assertion);
64: } else {
65: explicitAssertions.add(assertion);
66: }
67: });
68: }
69:
70: private Collection<Axiom<?>> loadInferredValues(NamedResource subject) {
71:• if (inferredAssertions.isEmpty()) {
72: return Collections.emptySet();
73: }
74: return new InferredAxiomLoader(adapter, snapshot).loadAxioms(subject, inferredAssertions);
75: }
76:
77: private Collection<Axiom<?>> loadExplicitValues(NamedResource subject) {
78:• if (explicitAssertions.isEmpty()) {
79: return Collections.emptySet();
80: }
81: final Collection<Axiom<?>> values = new ExplicitAxiomLoader(adapter, snapshot)
82: .loadAxioms(subject, explicitAssertions);
83:• return values.stream().filter(axiom -> !inferredAssertionUris.contains(axiom.getAssertion().getIdentifier()))
84: .collect(Collectors.toList());
85: }
86: }