Package: InferredSimpleListIterator
InferredSimpleListIterator
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
InferredSimpleListIterator(ListDescriptor, OntologySnapshot, AxiomAdapter) |
|
|
|
|
|
||||||||||||||||||||
doStep() |
|
|
|
|
|
||||||||||||||||||||
hasNext() |
|
|
|
|
|
||||||||||||||||||||
next() |
|
|
|
|
|
||||||||||||||||||||
removeWithoutReconnect() |
|
|
|
|
|
||||||||||||||||||||
replaceNode(NamedResource) |
|
|
|
|
|
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.list;
16:
17: import cz.cvut.kbss.ontodriver.owlapi.AxiomAdapter;
18: import cz.cvut.kbss.ontodriver.owlapi.connector.OntologySnapshot;
19: import cz.cvut.kbss.ontodriver.owlapi.exception.ReasonerNotAvailableException;
20: import cz.cvut.kbss.ontodriver.descriptor.ListDescriptor;
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 org.semanticweb.owlapi.model.OWLIndividual;
25: import org.semanticweb.owlapi.model.OWLNamedIndividual;
26: import org.semanticweb.owlapi.model.OWLOntologyChange;
27: import org.semanticweb.owlapi.reasoner.NodeSet;
28: import org.semanticweb.owlapi.reasoner.OWLReasoner;
29:
30: import java.util.Collections;
31: import java.util.List;
32: import java.util.NoSuchElementException;
33: import java.util.stream.Collectors;
34:
35: /**
36: * This class differs from the way basic SimpleListIterator iterates over the list. Here, we do step before even calling
37: * nextItem in order to avoid consulting the reasoner twice for values of the current node's successors.
38: * <p>
39: * We can do this because we need not worry about remove operations, they're not supported on inferred iterator.
40: * <p>
41: * TODO Check if the inferred iterators' logic is correct, especially for the nextValue method
42: */
43: class InferredSimpleListIterator extends SimpleListIterator {
44:
45: private final OWLReasoner reasoner;
46:
47: InferredSimpleListIterator(ListDescriptor descriptor, OntologySnapshot snapshot,
48: AxiomAdapter axiomAdapter) {
49: super(descriptor, snapshot, axiomAdapter);
50:• if (snapshot.getReasoner() == null) {
51: throw new ReasonerNotAvailableException();
52: }
53: this.reasoner = snapshot.getReasoner();
54: }
55:
56: @Override
57: public boolean hasNext() {
58:• if (nextItem == null) {
59: doStep();
60: }
61:• return !nextItem.isEmpty();
62: }
63:
64: @Override
65: void doStep() {
66: final NodeSet<OWLNamedIndividual> nodeSet = reasoner.getObjectPropertyValues(currentNode, currentProperty);
67:• this.nextItem = nodeSet.isEmpty() ? Collections.emptySet() : nodeSet.entities().collect(Collectors.toSet());
68: this.previousProperty = currentProperty;
69: this.currentProperty = hasNextProperty;
70: this.previousNode = this.currentNode;
71: }
72:
73: @Override
74: public Axiom<NamedResource> next() {
75:• if (!hasNext()) {
76: throw new NoSuchElementException("There are no more elements.");
77: }
78: checkMaxSuccessors(previousProperty, nextItem);
79: final OWLIndividual item = nextItem.iterator().next(); // We know the individual is named
80: this.currentNode = item.asOWLNamedIndividual();
81: final NamedResource subject = NamedResource.create(previousNode.getIRI().toURI());
82: final NamedResource value = NamedResource.create(currentNode.getIRI().toURI());
83: final Assertion assertion = Assertion.createObjectPropertyAssertion(previousProperty.getIRI().toURI(), false);
84: doStep();
85: return axiomAdapter.createAxiom(subject, assertion, value);
86: }
87:
88: @Override
89: List<OWLOntologyChange> removeWithoutReconnect() {
90: throw new UnsupportedOperationException();
91: }
92:
93: @Override
94: List<OWLOntologyChange> replaceNode(NamedResource newValue) {
95: throw new UnsupportedOperationException();
96: }
97: }