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: 30
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 7
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) 2022 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.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.owlapi.connector.OntologySnapshot;
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 final OWLOntology ontology;
35:
36: private final Set<URI> inferredAssertionUris = new HashSet<>();
37: private final Set<Assertion> inferredAssertions = new HashSet<>();
38: private final 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: resolveInferredAssertions(descriptor);
52:
53: final Collection<Axiom<?>> result = new ArrayList<>(loadInferredValues(subject));
54: result.addAll(loadExplicitValues(subject));
55: return result;
56: }
57:
58: private void resolveInferredAssertions(AxiomDescriptor descriptor) {
59: descriptor.getAssertions().forEach(assertion -> {
60:• if (assertion.isInferred()) {
61: inferredAssertionUris.add(assertion.getIdentifier());
62: inferredAssertions.add(assertion);
63: } else {
64: explicitAssertions.add(assertion);
65: }
66: });
67: }
68:
69: private Collection<Axiom<?>> loadInferredValues(NamedResource subject) {
70:• if (inferredAssertions.isEmpty()) {
71: return Collections.emptySet();
72: }
73: return new InferredAxiomLoader(adapter, snapshot).loadAxioms(subject, inferredAssertions);
74: }
75:
76: private Collection<Axiom<?>> loadExplicitValues(NamedResource subject) {
77:• if (explicitAssertions.isEmpty()) {
78: return Collections.emptySet();
79: }
80: final Collection<Axiom<?>> values = new ExplicitAxiomLoader(adapter, snapshot)
81: .loadAxioms(subject, explicitAssertions);
82:• return values.stream().filter(axiom -> !inferredAssertionUris.contains(axiom.getAssertion().getIdentifier()))
83: .collect(Collectors.toList());
84: }
85: }