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