Completed
Branch master (2d821a)
by Julian
49:45
created

de.tudresden.inf.lat.jcel.owlapi.main.JcelReasoner   F

Complexity

Total Complexity 73

Size/Duplication

Total Lines 622
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 622
rs 2.56
eloc 464
wmc 73

63 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstances(OWLClassExpression,boolean) 0 10 1
A getObjectPropertyDomains(OWLObjectPropertyExpression,boolean) 0 8 1
A getRootOntology() 0 6 1
A getPendingAxiomRemovals() 0 6 1
A getObjectPropertyValues(OWLNamedIndividual,OWLObjectPropertyExpression) 0 11 1
A getPrecomputableInferenceTypes() 0 12 1
A isConsistent() 0 6 1
A getReasonerName() 0 6 1
A getSuperDataProperties(OWLDataProperty,boolean) 0 8 1
A getUnsatisfiableClasses() 0 6 1
A getSuperClasses(OWLClassExpression,boolean) 0 10 1
A getStartTime() 0 2 1
A getTopObjectPropertyNode() 0 6 1
A ontologiesChanged(List) 0 4 1
A getInverseObjectProperties(OWLObjectPropertyExpression) 0 8 1
A JcelReasoner(OWLOntology,boolean,OWLReasonerConfiguration) 0 4 1
A getEquivalentClasses(OWLClassExpression) 0 8 1
A isEntailed(Set) 0 10 1
A addAxiom(OWLAxiom) 0 8 2
A getDifferentIndividuals(OWLNamedIndividual) 0 10 1
A removeAxiom(OWLAxiom) 0 8 2
A getDataPropertyDomains(OWLDataProperty,boolean) 0 8 1
A getPendingChanges() 0 6 1
A getIndividualNodeSetPolicy() 0 4 1
A isEntailed(OWLAxiom) 0 8 1
A getEquivalentDataProperties(OWLDataProperty) 0 8 1
A getSubDataProperties(OWLDataProperty,boolean) 0 8 1
A getTopDataPropertyNode() 0 4 1
A getTypes(OWLNamedIndividual,boolean) 0 10 1
A getEquivalentObjectProperties(OWLObjectPropertyExpression) 0 10 1
A getDisjointClasses(OWLClassExpression) 0 9 1
A getObjectPropertyRanges(OWLObjectPropertyExpression,boolean) 0 8 1
A resetReasoner() 0 2 1
A JcelReasoner(OWLOntology,boolean) 0 13 1
A getTimeOut() 0 6 1
A getRegisteredClasses(Set) 0 5 1
A isPrecomputed(InferenceType) 0 5 1
A getBottomClassNode() 0 6 1
A getBottomObjectPropertyNode() 0 7 1
A getSubObjectProperties(OWLObjectPropertyExpression,boolean) 0 10 1
B getReasonerVersion() 0 15 6
A getSameIndividuals(OWLNamedIndividual) 0 10 1
A isEntailmentCheckingSupported(AxiomType) 0 7 1
A getReasoner() 0 2 1
A getSuperObjectProperties(OWLObjectPropertyExpression,boolean) 0 10 1
A getBottomDataPropertyNode() 0 4 1
A interrupt() 0 4 1
A getTranslator() 0 2 1
A dispose() 0 5 1
A isSatisfiable(OWLClassExpression) 0 7 1
A getIntegerOntology() 0 12 1
A getFreshEntityPolicy() 0 4 1
A getSupportedTypes() 0 6 1
A precomputeInferences(InferenceType) 0 17 3
A getDisjointObjectProperties(OWLObjectPropertyExpression) 0 10 1
A getBufferingMode() 0 7 2
A getDisjointDataProperties(OWLDataPropertyExpression) 0 8 1
A flush() 0 8 1
A getDataPropertyValues(OWLNamedIndividual,OWLDataProperty) 0 9 1
A getReasonerConfiguration() 0 2 1
A getSubClasses(OWLClassExpression,boolean) 0 8 1
A getPendingAxiomAdditions() 0 6 1
A getTopClassNode() 0 6 1

How to fix   Complexity   

Complexity

Complex classes like de.tudresden.inf.lat.jcel.owlapi.main.JcelReasoner often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
/*
2
 *
3
 * Copyright (C) 2009-2017 Julian Mendez
4
 *
5
 *
6
 * This file is part of jcel.
7
 *
8
 *
9
 * The contents of this file are subject to the GNU Lesser General Public License
10
 * version 3
11
 *
12
 *
13
 * This program is free software: you can redistribute it and/or modify
14
 * it under the terms of the GNU Lesser General Public License as published by
15
 * the Free Software Foundation, either version 3 of the License, or
16
 * (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU Lesser General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU Lesser General Public License
24
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
25
 *
26
 *
27
 * Alternatively, the contents of this file may be used under the terms
28
 * of the Apache License, Version 2.0, in which case the
29
 * provisions of the Apache License, Version 2.0 are applicable instead of those
30
 * above.
31
 *
32
 *
33
 * Licensed under the Apache License, Version 2.0 (the "License");
34
 * you may not use this file except in compliance with the License.
35
 * You may obtain a copy of the License at
36
 *
37
 *     http://www.apache.org/licenses/LICENSE-2.0
38
 *
39
 * Unless required by applicable law or agreed to in writing, software
40
 * distributed under the License is distributed on an "AS IS" BASIS,
41
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
42
 * See the License for the specific language governing permissions and
43
 * limitations under the License.
44
 *
45
 */
46
47
package de.tudresden.inf.lat.jcel.owlapi.main;
48
49
import java.util.ArrayList;
50
import java.util.Collections;
51
import java.util.Date;
52
import java.util.HashSet;
53
import java.util.List;
54
import java.util.Objects;
55
import java.util.Set;
56
import java.util.StringTokenizer;
57
import java.util.logging.Logger;
58
59
import org.semanticweb.owlapi.model.AxiomType;
60
import org.semanticweb.owlapi.model.OWLAxiom;
61
import org.semanticweb.owlapi.model.OWLClass;
62
import org.semanticweb.owlapi.model.OWLClassExpression;
63
import org.semanticweb.owlapi.model.OWLDataProperty;
64
import org.semanticweb.owlapi.model.OWLDataPropertyExpression;
65
import org.semanticweb.owlapi.model.OWLLiteral;
66
import org.semanticweb.owlapi.model.OWLNamedIndividual;
67
import org.semanticweb.owlapi.model.OWLObjectPropertyExpression;
68
import org.semanticweb.owlapi.model.OWLOntology;
69
import org.semanticweb.owlapi.model.OWLOntologyChange;
70
import org.semanticweb.owlapi.model.OWLOntologyChangeListener;
71
import org.semanticweb.owlapi.model.OWLOntologyChangeVisitorEx;
72
import org.semanticweb.owlapi.reasoner.AxiomNotInProfileException;
73
import org.semanticweb.owlapi.reasoner.BufferingMode;
74
import org.semanticweb.owlapi.reasoner.ClassExpressionNotInProfileException;
75
import org.semanticweb.owlapi.reasoner.FreshEntitiesException;
76
import org.semanticweb.owlapi.reasoner.FreshEntityPolicy;
77
import org.semanticweb.owlapi.reasoner.InconsistentOntologyException;
78
import org.semanticweb.owlapi.reasoner.IndividualNodeSetPolicy;
79
import org.semanticweb.owlapi.reasoner.InferenceType;
80
import org.semanticweb.owlapi.reasoner.Node;
81
import org.semanticweb.owlapi.reasoner.NodeSet;
82
import org.semanticweb.owlapi.reasoner.OWLReasoner;
83
import org.semanticweb.owlapi.reasoner.OWLReasonerConfiguration;
84
import org.semanticweb.owlapi.reasoner.ReasonerInterruptedException;
85
import org.semanticweb.owlapi.reasoner.ReasonerProgressMonitor;
86
import org.semanticweb.owlapi.reasoner.TimeOutException;
87
import org.semanticweb.owlapi.reasoner.UnsupportedEntailmentTypeException;
88
import org.semanticweb.owlapi.util.Version;
89
90
import de.tudresden.inf.lat.jcel.ontology.axiom.complex.ComplexIntegerAxiom;
91
import de.tudresden.inf.lat.jcel.ontology.axiom.extension.IntegerOntologyObjectFactoryImpl;
92
import de.tudresden.inf.lat.jcel.ontology.datatype.IntegerClass;
93
import de.tudresden.inf.lat.jcel.owlapi.translator.Translator;
94
import de.tudresden.inf.lat.jcel.reasoner.main.IntegerReasoner;
95
import de.tudresden.inf.lat.jcel.reasoner.main.RuleBasedReasoner;
96
97
/**
98
 * This class is the connection with the OWL API. It implements some functions,
99
 * and throws an exception for the unimplemented ones.
100
 * 
101
 * @author Julian Mendez
102
 */
103
public class JcelReasoner implements OWLReasoner, OWLOntologyChangeListener {
104
105
	private static final Logger logger = Logger.getLogger(JcelReasoner.class.getName());
106
107
	private final boolean buffering = false;
108
	private RuleBasedReasoner jcelCore;
109
	private final OWLOntologyChangeVisitorEx<Boolean> ontologyChangeVisitor = new JcelOntologyChangeVisitorEx(this);
110
	private final Set<OWLAxiom> pendingAxiomAdditions = new HashSet<>();
111
	private final Set<OWLAxiom> pendingAxiomRemovals = new HashSet<>();
112
	private final List<OWLOntologyChange> pendingChanges = new ArrayList<>();
113
	private OWLReasonerConfiguration reasonerConfiguration = null;
114
	private final OWLOntology rootOntology;
115
	private final Date start = new Date();
116
	private final Set<AxiomType<?>> supportedAxiomTypes;
117
	private final Translator translator;
118
119
	/**
120
	 * Constructs a new jcel reasoner.
121
	 * 
122
	 * @param rootOntology
123
	 *            root ontology
124
	 * @param buffering
125
	 *            <code>true</code> if and only if the reasoner is buffering
126
	 */
127
	public JcelReasoner(OWLOntology rootOntology, boolean buffering) {
128
		Objects.requireNonNull(rootOntology);
129
		logger.fine("configuring jcel reasoner ...");
130
		this.rootOntology = rootOntology;
131
		this.translator = new Translator(rootOntology.getOWLOntologyManager().getOWLDataFactory(),
132
				new IntegerOntologyObjectFactoryImpl());
133
		this.rootOntology.getOWLOntologyManager().addOntologyChangeListener(this);
134
		this.supportedAxiomTypes = getSupportedTypes();
135
136
		logger.fine("resetting reasoner ...");
137
		resetReasoner();
138
139
		logger.fine("jcel reasoner configured.");
140
	}
141
142
	/**
143
	 * Constructs a new jcel reasoner.
144
	 * 
145
	 * @param rootOntology
146
	 *            root ontology
147
	 * @param buffering
148
	 *            <code>true</code> if and only if the reasoner is buffering
149
	 * @param configuration
150
	 *            reasoner configuration
151
	 */
152
	public JcelReasoner(OWLOntology rootOntology, boolean buffering, OWLReasonerConfiguration configuration) {
153
		this(rootOntology, buffering);
154
		Objects.requireNonNull(configuration);
155
		this.reasonerConfiguration = configuration;
156
	}
157
158
	public boolean addAxiom(OWLAxiom axiom) {
159
		Objects.requireNonNull(axiom);
160
		logger.finer("addAxiom(" + axiom + ")");
161
		boolean ret = this.pendingAxiomAdditions.add(axiom);
162
		if (!this.buffering) {
163
			resetReasoner();
164
		}
165
		return ret;
166
	}
167
168
	@Override
169
	public void dispose() {
170
		logger.finer("dispose()");
171
		this.rootOntology.getOWLOntologyManager().removeOntologyChangeListener(this);
172
		getReasoner().dispose();
173
	}
174
175
	@Override
176
	public void flush() {
177
		logger.finer("flush()");
178
		this.pendingAxiomAdditions.clear();
179
		this.pendingAxiomRemovals.clear();
180
		this.pendingChanges.clear();
181
		resetReasoner();
182
		getReasoner().flush();
183
	}
184
185
	@Override
186
	public Node<OWLClass> getBottomClassNode() {
187
		logger.finer("getBottomClassNode()");
188
		Node<OWLClass> ret = getTranslator().translateSC(getReasoner().getBottomClassNode());
189
		logger.finer("" + ret);
190
		return ret;
191
	}
192
193
	@Override
194
	public Node<OWLDataProperty> getBottomDataPropertyNode() {
195
		logger.finer("getBottomDataPropertyNode()");
196
		throw new UnsupportedReasonerOperationInJcelException("Unsupported operation : getBottomDataPropertyNode()");
197
	}
198
199
	@Override
200
	public Node<OWLObjectPropertyExpression> getBottomObjectPropertyNode() {
201
		logger.finer("getBottomObjectPropertyNode()");
202
		Node<OWLObjectPropertyExpression> ret = getTranslator()
203
				.translateSOPE(getReasoner().getBottomObjectPropertyNode());
204
		logger.finer("" + ret);
205
		return ret;
206
	}
207
208
	@Override
209
	public BufferingMode getBufferingMode() {
210
		logger.finer("getBufferingMode()");
211
212
		BufferingMode ret = this.buffering ? BufferingMode.BUFFERING : BufferingMode.NON_BUFFERING;
213
		logger.finer("" + ret);
214
		return ret;
215
	}
216
217
	@Override
218
	public NodeSet<OWLClass> getDataPropertyDomains(OWLDataProperty dataProperty, boolean direct)
219
			throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException,
220
			TimeOutException {
221
		Objects.requireNonNull(dataProperty);
222
		logger.finer("getDataPropertyDomains(" + dataProperty + ", " + direct + ")");
223
		throw new UnsupportedReasonerOperationInJcelException(
224
				"Unsupported operation : getDataPropertyDomains(OWLDataProperty, boolean)");
225
	}
226
227
	@Override
228
	public Set<OWLLiteral> getDataPropertyValues(OWLNamedIndividual individual, OWLDataProperty dataProperty)
229
			throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException,
230
			TimeOutException {
231
		Objects.requireNonNull(individual);
232
		Objects.requireNonNull(dataProperty);
233
		logger.finer("getDataPropertyValues(" + individual + ", " + dataProperty + ")");
234
		throw new UnsupportedReasonerOperationInJcelException(
235
				"Unsupported operation : getDataPropertyValues(OWLNamedIndividual, OWLDataProperty)");
236
	}
237
238
	@Override
239
	public NodeSet<OWLNamedIndividual> getDifferentIndividuals(OWLNamedIndividual individual)
240
			throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException,
241
			TimeOutException {
242
		Objects.requireNonNull(individual);
243
		logger.finer("getDifferentIndividuals(" + individual + ")");
244
		NodeSet<OWLNamedIndividual> ret = getTranslator()
245
				.translateSSI(getReasoner().getDifferentIndividuals(getTranslator().translateI(individual)));
246
		logger.finer("" + ret);
247
		return ret;
248
	}
249
250
	@Override
251
	public NodeSet<OWLClass> getDisjointClasses(OWLClassExpression classExpression) throws ReasonerInterruptedException,
252
			TimeOutException, FreshEntitiesException, InconsistentOntologyException {
253
		Objects.requireNonNull(classExpression);
254
		logger.finer("getDisjointClasses(" + classExpression + ")");
255
		NodeSet<OWLClass> ret = getTranslator()
256
				.translateSSC(getReasoner().getDisjointClasses(getTranslator().translateCE(classExpression)));
257
		logger.finer("" + ret);
258
		return ret;
259
	}
260
261
	@Override
262
	public NodeSet<OWLDataProperty> getDisjointDataProperties(OWLDataPropertyExpression dataPropertyExpression)
263
			throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException,
264
			TimeOutException {
265
		Objects.requireNonNull(dataPropertyExpression);
266
		logger.finer("getDisjointDataProperties(" + dataPropertyExpression + ")");
267
		throw new UnsupportedReasonerOperationInJcelException(
268
				"Unsupported operation : getDisjointDataProperties(OWLDataPropertyExpression)");
269
	}
270
271
	@Override
272
	public NodeSet<OWLObjectPropertyExpression> getDisjointObjectProperties(
273
			OWLObjectPropertyExpression objectPropertyExpression) throws InconsistentOntologyException,
274
			FreshEntitiesException, ReasonerInterruptedException, TimeOutException {
275
		Objects.requireNonNull(objectPropertyExpression);
276
		logger.finer("getDisjointDataProperties(" + objectPropertyExpression + ")");
277
		NodeSet<OWLObjectPropertyExpression> ret = getTranslator().translateSSOPE(
278
				getReasoner().getDisjointObjectProperties(getTranslator().translateOPE(objectPropertyExpression)));
279
		logger.finer("" + ret);
280
		return ret;
281
	}
282
283
	Set<IntegerClass> getRegisteredClasses(Set<IntegerClass> set) {
284
		Set<IntegerClass> ret = new HashSet<>();
285
		set.stream().filter(cls -> getTranslator().getTranslationRepository().getOptOWLClass(cls.getId()).isPresent())
286
				.forEach(cls -> ret.add(cls));
287
		return ret;
288
	}
289
290
	@Override
291
	public Node<OWLClass> getEquivalentClasses(OWLClassExpression classExpression) {
292
		Objects.requireNonNull(classExpression);
293
		logger.finer("getEquivalentClasses(" + classExpression + ")");
294
		Node<OWLClass> ret = getTranslator().translateSC(
295
				getRegisteredClasses(getReasoner().getEquivalentClasses(getTranslator().translateCE(classExpression))));
296
		logger.finer("" + ret);
297
		return ret;
298
	}
299
300
	@Override
301
	public Node<OWLDataProperty> getEquivalentDataProperties(OWLDataProperty dataProperty)
302
			throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException,
303
			TimeOutException {
304
		Objects.requireNonNull(dataProperty);
305
		logger.finer("getEquivalentDataProperties(" + dataProperty + ")");
306
		throw new UnsupportedReasonerOperationInJcelException(
307
				"Unsupported operation : getEquivalentDataProperties(OWLDataProperty)");
308
	}
309
310
	@Override
311
	public Node<OWLObjectPropertyExpression> getEquivalentObjectProperties(
312
			OWLObjectPropertyExpression objectPropertyExpression) throws InconsistentOntologyException,
313
			FreshEntitiesException, ReasonerInterruptedException, TimeOutException {
314
		Objects.requireNonNull(objectPropertyExpression);
315
		logger.finer("getEquivalentObjectProperties(" + objectPropertyExpression + ")");
316
		Node<OWLObjectPropertyExpression> ret = getTranslator().translateSOPE(
317
				getReasoner().getEquivalentObjectProperties(getTranslator().translateOPE(objectPropertyExpression)));
318
		logger.finer("" + ret);
319
		return ret;
320
	}
321
322
	@Override
323
	public FreshEntityPolicy getFreshEntityPolicy() {
324
		logger.finer("getFreshEntityPolicy()");
325
		throw new UnsupportedReasonerOperationInJcelException("Unsupported operation : getFreshEntityPolicy()");
326
	}
327
328
	@Override
329
	public IndividualNodeSetPolicy getIndividualNodeSetPolicy() {
330
		logger.finer("getIndividualNodeSetPolicy()");
331
		throw new UnsupportedReasonerOperationInJcelException("Unsupported operation : getIndividualNodeSetPolicy()");
332
	}
333
334
	@Override
335
	public NodeSet<OWLNamedIndividual> getInstances(OWLClassExpression classExpression, boolean direct)
336
			throws InconsistentOntologyException, ClassExpressionNotInProfileException, FreshEntitiesException,
337
			ReasonerInterruptedException, TimeOutException {
338
		Objects.requireNonNull(classExpression);
339
		logger.finer("getInstances(" + classExpression + ", " + direct + ")");
340
		NodeSet<OWLNamedIndividual> ret = getTranslator()
341
				.translateSSI(getReasoner().getInstances(getTranslator().translateCE(classExpression), direct));
342
		logger.finer("" + ret);
343
		return ret;
344
	}
345
346
	private Set<ComplexIntegerAxiom> getIntegerOntology() {
347
		Set<OWLAxiom> owlAxiomSet = new HashSet<>();
348
		owlAxiomSet.addAll(this.rootOntology.getAxioms());
349
		this.rootOntology.getImportsClosure().forEach(ont -> owlAxiomSet.addAll(ont.getAxioms()));
350
351
		this.translator.getTranslationRepository().addAxiomEntities(this.rootOntology);
352
353
		logger.fine("translating axioms ...");
354
		Set<ComplexIntegerAxiom> ret = this.translator.translateSA(owlAxiomSet);
355
356
		logger.fine("axioms translated.");
357
		return ret;
358
	}
359
360
	@Override
361
	public Node<OWLObjectPropertyExpression> getInverseObjectProperties(
362
			OWLObjectPropertyExpression objectPropertyExpression) throws InconsistentOntologyException,
363
			FreshEntitiesException, ReasonerInterruptedException, TimeOutException {
364
		Objects.requireNonNull(objectPropertyExpression);
365
		logger.finer("getInverseObjectProperties(" + objectPropertyExpression + ")");
366
		throw new UnsupportedReasonerOperationInJcelException(
367
				"Unsupported operation : getInverseObjectProperties(OWLObjectPropertyExpression)");
368
	}
369
370
	@Override
371
	public NodeSet<OWLClass> getObjectPropertyDomains(OWLObjectPropertyExpression objectPropertyExpression,
372
			boolean direct) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException,
373
			TimeOutException {
374
		Objects.requireNonNull(objectPropertyExpression);
375
		logger.finer("getObjectPropertyDomains(" + objectPropertyExpression + ", " + direct + ")");
376
		throw new UnsupportedReasonerOperationInJcelException(
377
				"Unsupported operation : getObjectPropertyDomains(OWLObjectPropertyExpression, boolean)");
378
	}
379
380
	@Override
381
	public NodeSet<OWLClass> getObjectPropertyRanges(OWLObjectPropertyExpression objectPropertyExpression,
382
			boolean direct) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException,
383
			TimeOutException {
384
		Objects.requireNonNull(objectPropertyExpression);
385
		logger.finer("getObjectPropertyRanges(" + objectPropertyExpression + ", " + direct + ")");
386
		throw new UnsupportedReasonerOperationInJcelException(
387
				"Unsupported operation : getObjectPropertyRanges(OWLObjectPropertyExpression, boolean)");
388
	}
389
390
	@Override
391
	public NodeSet<OWLNamedIndividual> getObjectPropertyValues(OWLNamedIndividual individual,
392
			OWLObjectPropertyExpression objectPropertyExpression) throws InconsistentOntologyException,
393
			FreshEntitiesException, ReasonerInterruptedException, TimeOutException {
394
		Objects.requireNonNull(individual);
395
		Objects.requireNonNull(objectPropertyExpression);
396
		logger.finer("getObjectPropertyValues(" + individual + ", " + objectPropertyExpression + ")");
397
		NodeSet<OWLNamedIndividual> ret = getTranslator().translateSSI(getReasoner().getObjectPropertyValues(
398
				getTranslator().translateI(individual), getTranslator().translateOPE(objectPropertyExpression)));
399
		logger.finer("" + ret);
400
		return ret;
401
	}
402
403
	@Override
404
	public Set<OWLAxiom> getPendingAxiomAdditions() {
405
		logger.finer("getPendingAxiomAdditions()");
406
		Set<OWLAxiom> ret = this.pendingAxiomAdditions;
407
		logger.finer("" + ret);
408
		return Collections.unmodifiableSet(ret);
409
	}
410
411
	@Override
412
	public Set<OWLAxiom> getPendingAxiomRemovals() {
413
		logger.finer("getPendingAxiomRemovals()");
414
		Set<OWLAxiom> ret = this.pendingAxiomRemovals;
415
		logger.finer("" + ret);
416
		return Collections.unmodifiableSet(ret);
417
	}
418
419
	@Override
420
	public List<OWLOntologyChange> getPendingChanges() {
421
		logger.finer("getPendingChanges()");
422
		List<OWLOntologyChange> ret = this.pendingChanges;
423
		logger.finer("" + ret);
424
		return Collections.unmodifiableList(ret);
425
	}
426
427
	@Override
428
	public Set<InferenceType> getPrecomputableInferenceTypes() {
429
		logger.finer("getPrecomputableInferenceTypes()");
430
		Set<InferenceType> ret = new HashSet<>();
431
		ret.add(InferenceType.CLASS_HIERARCHY);
432
		ret.add(InferenceType.OBJECT_PROPERTY_HIERARCHY);
433
		ret.add(InferenceType.CLASS_ASSERTIONS);
434
		ret.add(InferenceType.OBJECT_PROPERTY_ASSERTIONS);
435
		ret.add(InferenceType.SAME_INDIVIDUAL);
436
		ret.add(InferenceType.DIFFERENT_INDIVIDUALS);
437
		logger.finer("" + ret);
438
		return ret;
439
	}
440
441
	public IntegerReasoner getReasoner() {
442
		return this.jcelCore;
443
	}
444
445
	public OWLReasonerConfiguration getReasonerConfiguration() {
446
		return this.reasonerConfiguration;
447
	}
448
449
	@Override
450
	public String getReasonerName() {
451
		logger.finer("getReasonerName()");
452
		String ret = getReasoner().getReasonerName();
453
		logger.finer("" + ret);
454
		return ret;
455
	}
456
457
	@Override
458
	public Version getReasonerVersion() {
459
		logger.finer("getReasonerVersion()");
460
		Version ret = new Version(0, 0, 0, 0);
461
		String versionId = getReasoner().getReasonerVersion();
462
		if (Objects.nonNull(versionId)) {
463
			StringTokenizer stok = new StringTokenizer(versionId, ".");
464
			int major = stok.hasMoreTokens() ? Integer.parseInt(stok.nextToken()) : 0;
465
			int minor = stok.hasMoreTokens() ? Integer.parseInt(stok.nextToken()) : 0;
466
			int patch = stok.hasMoreTokens() ? Integer.parseInt(stok.nextToken()) : 0;
467
			int build = stok.hasMoreTokens() ? Integer.parseInt(stok.nextToken()) : 0;
468
			ret = new Version(major, minor, patch, build);
469
		}
470
		logger.finer("" + ret);
471
		return ret;
472
	}
473
474
	@Override
475
	public OWLOntology getRootOntology() {
476
		logger.finer("getRootOntology()");
477
		OWLOntology ret = this.rootOntology;
478
		logger.finer("" + ret);
479
		return ret;
480
	}
481
482
	@Override
483
	public Node<OWLNamedIndividual> getSameIndividuals(OWLNamedIndividual individual)
484
			throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException,
485
			TimeOutException {
486
		Objects.requireNonNull(individual);
487
		logger.finer("getSameIndividuals(" + individual + ")");
488
		Node<OWLNamedIndividual> ret = getTranslator()
489
				.translateSI(getReasoner().getSameIndividuals(getTranslator().translateI(individual)));
490
		logger.finer("" + ret);
491
		return ret;
492
	}
493
494
	public Date getStartTime() {
495
		return this.start;
496
	}
497
498
	@Override
499
	public NodeSet<OWLClass> getSubClasses(OWLClassExpression classExpression, boolean direct) {
500
		Objects.requireNonNull(classExpression);
501
		logger.finer("getSubClasses(" + classExpression + ", " + direct + ")");
502
		NodeSet<OWLClass> ret = getTranslator()
503
				.translateSSC(getReasoner().getSubClasses(getTranslator().translateCE(classExpression), direct));
504
		logger.finer("" + ret);
505
		return ret;
506
	}
507
508
	@Override
509
	public NodeSet<OWLDataProperty> getSubDataProperties(OWLDataProperty dataProperty, boolean direct)
510
			throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException,
511
			TimeOutException {
512
		Objects.requireNonNull(dataProperty);
513
		logger.finer("getSubDataProperties(" + dataProperty + ", " + direct + ")");
514
		throw new UnsupportedReasonerOperationInJcelException(
515
				"Unsupported operation : getSubDataProperties(OWLDataProperty, boolean)");
516
	}
517
518
	@Override
519
	public NodeSet<OWLObjectPropertyExpression> getSubObjectProperties(
520
			OWLObjectPropertyExpression objectPropertyExpression, boolean direct) throws InconsistentOntologyException,
521
			FreshEntitiesException, ReasonerInterruptedException, TimeOutException {
522
		Objects.requireNonNull(objectPropertyExpression);
523
		logger.finer("getSubObjectProperties(" + objectPropertyExpression + ", " + direct + ")");
524
		NodeSet<OWLObjectPropertyExpression> ret = getTranslator().translateSSOPE(
525
				getReasoner().getSubObjectProperties(getTranslator().translateOPE(objectPropertyExpression), direct));
526
		logger.finer("" + ret);
527
		return ret;
528
	}
529
530
	@Override
531
	public NodeSet<OWLClass> getSuperClasses(OWLClassExpression classExpression, boolean direct)
532
			throws InconsistentOntologyException, ClassExpressionNotInProfileException, FreshEntitiesException,
533
			ReasonerInterruptedException, TimeOutException {
534
		Objects.requireNonNull(classExpression);
535
		logger.finer("getSuperClasses(" + classExpression + ", " + direct + ")");
536
		NodeSet<OWLClass> ret = getTranslator()
537
				.translateSSC(getReasoner().getSuperClasses(getTranslator().translateCE(classExpression), direct));
538
		logger.finer("" + ret);
539
		return ret;
540
	}
541
542
	@Override
543
	public NodeSet<OWLDataProperty> getSuperDataProperties(OWLDataProperty dataProperty, boolean direct)
544
			throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException,
545
			TimeOutException {
546
		Objects.requireNonNull(dataProperty);
547
		logger.finer("getSuperDataProperties(" + dataProperty + ", " + direct + ")");
548
		throw new UnsupportedReasonerOperationInJcelException(
549
				"Unsupported operation : getSuperDataProperties(OWLDataProperty, boolean)");
550
	}
551
552
	@Override
553
	public NodeSet<OWLObjectPropertyExpression> getSuperObjectProperties(
554
			OWLObjectPropertyExpression objectPropertyExpression, boolean direct) throws InconsistentOntologyException,
555
			FreshEntitiesException, ReasonerInterruptedException, TimeOutException {
556
		Objects.requireNonNull(objectPropertyExpression);
557
		logger.finer("getSuperObjectProperties(" + objectPropertyExpression + ", " + direct + ")");
558
		NodeSet<OWLObjectPropertyExpression> ret = getTranslator().translateSSOPE(
559
				getReasoner().getSuperObjectProperties(getTranslator().translateOPE(objectPropertyExpression), direct));
560
		logger.finer("" + ret);
561
		return ret;
562
	}
563
564
	private Set<AxiomType<?>> getSupportedTypes() {
565
		Set<AxiomType<?>> ret = new HashSet<>();
566
		ret.add(AxiomType.EQUIVALENT_CLASSES);
567
		ret.add(AxiomType.SUBCLASS_OF);
568
		ret.add(AxiomType.SUB_OBJECT_PROPERTY);
569
		return Collections.unmodifiableSet(ret);
570
	}
571
572
	@Override
573
	public long getTimeOut() {
574
		logger.finer("getTimeOut()");
575
		long ret = getReasoner().getTimeOut();
576
		logger.finer("" + ret);
577
		return ret;
578
	}
579
580
	@Override
581
	public Node<OWLClass> getTopClassNode() {
582
		logger.finer("getTopClassNode()");
583
		Node<OWLClass> ret = getTranslator().translateSC(getReasoner().getTopClassNode());
584
		logger.finer("" + ret);
585
		return ret;
586
	}
587
588
	@Override
589
	public Node<OWLDataProperty> getTopDataPropertyNode() {
590
		logger.finer("getTopDataPropertyNode()");
591
		throw new UnsupportedReasonerOperationInJcelException("Unsupported operation : getTopDataPropertyNode()");
592
	}
593
594
	@Override
595
	public Node<OWLObjectPropertyExpression> getTopObjectPropertyNode() {
596
		logger.finer("getTopObjectPropertyNode()");
597
		Node<OWLObjectPropertyExpression> ret = getTranslator().translateSOPE(getReasoner().getTopObjectPropertyNode());
598
		logger.finer("" + ret);
599
		return ret;
600
	}
601
602
	public Translator getTranslator() {
603
		return this.translator;
604
	}
605
606
	@Override
607
	public NodeSet<OWLClass> getTypes(OWLNamedIndividual individual, boolean direct)
608
			throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException,
609
			TimeOutException {
610
		Objects.requireNonNull(individual);
611
		logger.finer("getTypes(" + individual + ", " + direct + ")");
612
		NodeSet<OWLClass> ret = getTranslator()
613
				.translateSSC(getReasoner().getTypes(getTranslator().translateI(individual), direct));
614
		logger.finer("" + ret);
615
		return ret;
616
	}
617
618
	@Override
619
	public Node<OWLClass> getUnsatisfiableClasses() throws ReasonerInterruptedException, TimeOutException {
620
		logger.finer("getUnsatisfiableClasses()");
621
		Node<OWLClass> ret = getTranslator().translateSC(getReasoner().getUnsatisfiableClasses());
622
		logger.finer("" + ret);
623
		return ret;
624
	}
625
626
	@Override
627
	public void interrupt() {
628
		logger.finer("interrupt()");
629
		throw new UnsupportedReasonerOperationInJcelException("Unsupported operation : interrupt()");
630
	}
631
632
	@Override
633
	public boolean isConsistent() throws ReasonerInterruptedException, TimeOutException {
634
		logger.finer("isConsistent()");
635
		boolean ret = getReasoner().isConsistent();
636
		logger.finer("" + ret);
637
		return ret;
638
	}
639
640
	@Override
641
	public boolean isEntailed(OWLAxiom axiom) throws ReasonerInterruptedException, UnsupportedEntailmentTypeException,
642
			TimeOutException, AxiomNotInProfileException, FreshEntitiesException {
643
		Objects.requireNonNull(axiom);
644
		logger.finer("isEntailed((OWLAxiom) " + axiom + ")");
645
		boolean ret = getReasoner().isEntailed(getTranslator().translateSA(Collections.singleton(axiom)));
646
		logger.finer("" + ret);
647
		return ret;
648
	}
649
650
	@Override
651
	public boolean isEntailed(Set<? extends OWLAxiom> axiomSet) throws ReasonerInterruptedException,
652
			UnsupportedEntailmentTypeException, TimeOutException, AxiomNotInProfileException, FreshEntitiesException {
653
		Objects.requireNonNull(axiomSet);
654
		logger.finer("isEntailed((Set<? extends OWLAxiom>) " + axiomSet + ")");
655
		Set<OWLAxiom> set = new HashSet<>();
656
		axiomSet.forEach(axiom -> set.add(axiom));
657
		boolean ret = getReasoner().isEntailed(getTranslator().translateSA(set));
658
		logger.finer("" + ret);
659
		return ret;
660
	}
661
662
	@Override
663
	public boolean isEntailmentCheckingSupported(AxiomType<?> axiomType) {
664
		Objects.requireNonNull(axiomType);
665
		logger.finer("isEntailmentCheckingSupported(" + axiomType + ")");
666
		boolean ret = this.supportedAxiomTypes.contains(axiomType);
667
		logger.finer("" + ret);
668
		return ret;
669
	}
670
671
	@Override
672
	public boolean isPrecomputed(InferenceType inferenceType) {
673
		Objects.requireNonNull(inferenceType);
674
		logger.finer("isPrecomputed(" + inferenceType + ")");
675
		throw new UnsupportedReasonerOperationInJcelException("Unsupported operation : isPrecomputed()");
676
	}
677
678
	@Override
679
	public boolean isSatisfiable(OWLClassExpression classExpression) {
680
		Objects.requireNonNull(classExpression);
681
		logger.finer("isSatisfiable(" + classExpression + ")");
682
		boolean ret = getReasoner().isSatisfiable(getTranslator().translateCE(classExpression));
683
		logger.finer("" + ret);
684
		return ret;
685
	}
686
687
	@Override
688
	public void ontologiesChanged(List<? extends OWLOntologyChange> changes) {
689
		this.pendingChanges.addAll(changes);
690
		changes.forEach(change -> change.accept(this.ontologyChangeVisitor));
691
	}
692
693
	@Override
694
	public void precomputeInferences(InferenceType... inferenceTypes)
695
			throws ReasonerInterruptedException, TimeOutException, InconsistentOntologyException {
696
		Objects.requireNonNull(inferenceTypes);
697
		logger.finer("precomputeInferences(" + inferenceTypes + ")");
698
		if (Objects.nonNull(this.reasonerConfiguration)) {
699
			this.reasonerConfiguration.getProgressMonitor().reasonerTaskStarted(ReasonerProgressMonitor.CLASSIFYING);
700
			this.reasonerConfiguration.getProgressMonitor().reasonerTaskBusy();
701
		}
702
703
		logger.finer("classifying ...");
704
		Date start = new Date();
705
		getReasoner().classify();
706
		logger.finer("jcel classified in " + ((new Date()).getTime() - start.getTime()) + "ms");
707
708
		if (Objects.nonNull(this.reasonerConfiguration)) {
709
			this.reasonerConfiguration.getProgressMonitor().reasonerTaskStopped();
710
		}
711
	}
712
713
	public boolean removeAxiom(OWLAxiom axiom) {
714
		Objects.requireNonNull(axiom);
715
		logger.finer("removeAxiom(" + axiom + ")");
716
		boolean ret = this.pendingAxiomRemovals.add(axiom);
717
		if (!this.buffering) {
718
			resetReasoner();
719
		}
720
		return ret;
721
	}
722
723
	private void resetReasoner() {
724
		this.jcelCore = new RuleBasedReasoner(getIntegerOntology(), this.translator.getOntologyObjectFactory());
725
	}
726
727
}
728