Skip to content

Package: InferredSimpleListIterator

InferredSimpleListIterator

nameinstructionbranchcomplexitylinemethod
InferredSimpleListIterator(ListDescriptor, OntologySnapshot, AxiomAdapter)
M: 4 C: 13
76%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 4
80%
M: 0 C: 1
100%
doStep()
M: 0 C: 30
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
hasNext()
M: 0 C: 13
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
next()
M: 5 C: 47
90%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 9
90%
M: 0 C: 1
100%
removeWithoutReconnect()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
replaceNode(NamedResource)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

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