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

de.tudresden.inf.lat.jcel.reasoner.main.RuleBasedReasoner   F

Complexity

Total Complexity 68

Size/Duplication

Total Lines 511
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 511
rs 2.96
eloc 359
wmc 68

51 Methods

Rating   Name   Duplication   Size   Complexity  
B getInstances(IntegerClassExpression,boolean) 0 40 6
A getDataPropertyValues(IntegerNamedIndividual,IntegerDataProperty) 0 5 1
A getTopDataPropertyNode() 0 5 1
A getObjectPropertyValues(IntegerNamedIndividual,IntegerObjectPropertyExpression) 0 8 1
A getObjectPropertyExpressionId(IntegerObjectPropertyExpression) 0 2 1
A toIntegerClass(Set) 0 4 1
A isClassified() 0 2 1
A RuleBasedReasoner(Set,IntegerOntologyObjectFactory) 0 5 1
A getProcessor() 0 2 1
A getBottomClassNode() 0 5 1
A getTypes(IntegerNamedIndividual,boolean) 0 22 4
A getBottomObjectPropertyNode() 0 5 1
A createProcessor(Set) 0 28 1
A getDifferentIndividuals(IntegerNamedIndividual) 0 6 1
A flush() 0 3 1
A toIntegerObjectPropertyExpression(Set) 0 4 1
A flattenClassExpression(IntegerClassExpression) 0 34 3
A interrupt() 0 4 1
A getDisjointClasses(IntegerClassExpression) 0 6 1
A getInverseObjectProperties(IntegerObjectPropertyExpression) 0 6 1
A getEquivalentObjectProperties(IntegerObjectPropertyExpression) 0 7 1
A getDisjointObjectProperties(IntegerObjectPropertyExpression) 0 6 1
A toIntegerNamedIndividual(Set) 0 4 1
A getSameIndividuals(IntegerNamedIndividual) 0 5 1
A getSubObjectProperties(IntegerObjectPropertyExpression,boolean) 0 16 2
A getDisjointDataProperties(IntegerDataPropertyExpression) 0 6 1
A getDataPropertyDomains(IntegerDataProperty,boolean) 0 4 1
A getSuperDataProperties(IntegerDataProperty,boolean) 0 4 1
A getObjectPropertyDomains(IntegerObjectPropertyExpression,boolean) 0 6 1
A getDataTypeFactory() 0 2 1
A getSuperObjectProperties(IntegerObjectPropertyExpression,boolean) 0 16 2
A getSuperClasses(IntegerClassExpression,boolean) 0 18 2
A getReasonerName() 0 3 1
A getReasonerVersion() 0 3 1
A toIntegerDataProperty(Set) 0 4 1
A getSubDataProperties(IntegerDataProperty,boolean) 0 4 1
A isConsistent() 0 4 1
A getTimeOut() 0 3 1
A getObjectPropertyRanges(IntegerObjectPropertyExpression,boolean) 0 6 1
A getSubClasses(IntegerClassExpression,boolean) 0 15 2
A getUnsatisfiableClasses() 0 3 1
A isSatisfiable(IntegerClassExpression) 0 6 1
A isEntailed(ComplexIntegerAxiom) 0 6 1
A dispose() 0 2 1
A getBottomDataPropertyNode() 0 5 1
A getEquivalentClasses(IntegerClassExpression) 0 7 1
A getTopClassNode() 0 5 1
A getEquivalentDataProperties(IntegerDataProperty) 0 4 1
A getTopObjectPropertyNode() 0 5 1
A isEntailed(Set) 0 6 1
A classify() 0 16 4

How to fix   Complexity   

Complexity

Complex classes like de.tudresden.inf.lat.jcel.reasoner.main.RuleBasedReasoner 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.reasoner.main;
48
49
import java.util.Collections;
50
import java.util.HashMap;
51
import java.util.HashSet;
52
import java.util.Map;
53
import java.util.Objects;
54
import java.util.Set;
55
import java.util.logging.Logger;
56
57
import de.tudresden.inf.lat.jcel.core.algorithm.common.Processor;
58
import de.tudresden.inf.lat.jcel.core.algorithm.rulebased.RuleBasedProcessor;
59
import de.tudresden.inf.lat.jcel.core.graph.IntegerHierarchicalGraph;
60
import de.tudresden.inf.lat.jcel.coreontology.axiom.IntegerAnnotation;
61
import de.tudresden.inf.lat.jcel.coreontology.axiom.NormalizedIntegerAxiom;
62
import de.tudresden.inf.lat.jcel.coreontology.datatype.IntegerEntityType;
63
import de.tudresden.inf.lat.jcel.coreontology.datatype.OntologyExpressivity;
64
import de.tudresden.inf.lat.jcel.ontology.axiom.complex.ComplexIntegerAxiom;
65
import de.tudresden.inf.lat.jcel.ontology.axiom.extension.ComplexAxiomExpressivityDetector;
66
import de.tudresden.inf.lat.jcel.ontology.axiom.extension.IntegerOntologyObjectFactory;
67
import de.tudresden.inf.lat.jcel.ontology.datatype.IntegerClass;
68
import de.tudresden.inf.lat.jcel.ontology.datatype.IntegerClassExpression;
69
import de.tudresden.inf.lat.jcel.ontology.datatype.IntegerDataProperty;
70
import de.tudresden.inf.lat.jcel.ontology.datatype.IntegerDataPropertyExpression;
71
import de.tudresden.inf.lat.jcel.ontology.datatype.IntegerDataTypeFactory;
72
import de.tudresden.inf.lat.jcel.ontology.datatype.IntegerNamedIndividual;
73
import de.tudresden.inf.lat.jcel.ontology.datatype.IntegerObjectPropertyExpression;
74
import de.tudresden.inf.lat.jcel.ontology.normalization.ObjectPropertyIdFinder;
75
import de.tudresden.inf.lat.jcel.ontology.normalization.OntologyNormalizer;
76
77
/**
78
 * This class models a rule-based reasoner.
79
 * 
80
 * @author Julian Mendez
81
 */
82
public class RuleBasedReasoner implements IntegerReasoner {
83
84
	private static final Logger logger = Logger.getLogger(RuleBasedReasoner.class.getName());
85
86
	private final Map<IntegerClassExpression, Integer> auxClassInvMap = new HashMap<>();
87
	private final Map<Integer, IntegerClassExpression> auxClassMap = new HashMap<>();
88
	private boolean classified = false;
89
	private final OntologyEntailmentChecker entailmentChecker = new OntologyEntailmentChecker(this);
90
	private final IntegerOntologyObjectFactory factory;
91
	private boolean interruptRequested = false;
92
	private RuleBasedProcessor processor = null;
93
	private final long timeOut = 0;
94
95
	public RuleBasedReasoner(Set<ComplexIntegerAxiom> ontology, IntegerOntologyObjectFactory factory) {
96
		Objects.requireNonNull(ontology);
97
		Objects.requireNonNull(factory);
98
		this.factory = factory;
99
		this.processor = createProcessor(ontology);
100
	}
101
102
	@Override
103
	public void classify() {
104
		if (!this.classified) {
105
			logger.fine("starting classification ...");
106
			flush();
107
108
			while (this.processor.process()) {
109
				if (this.interruptRequested) {
110
					this.interruptRequested = false;
111
					throw new RuntimeException("Classification interrupted.");
112
				}
113
			}
114
			logger.fine("classification finished.");
115
		}
116
117
		this.classified = true;
118
	}
119
120
	private RuleBasedProcessor createProcessor(Set<ComplexIntegerAxiom> ontology) {
121
		logger.fine("creating processor (phase 1) ...");
122
123
		OntologyExpressivity expressivity = new ComplexAxiomExpressivityDetector(ontology);
124
125
		logger.fine("description logic family : " + expressivity.toString() + " .");
126
127
		Set<Integer> originalClassSet = new HashSet<>();
128
		Set<Integer> originalObjectPropertySet = new HashSet<>();
129
130
		ontology.forEach(axiom -> {
131
			originalClassSet.addAll(axiom.getClassesInSignature());
132
			originalObjectPropertySet.addAll(axiom.getObjectPropertiesInSignature());
133
		});
134
135
		logger.fine("number of axioms : " + ontology.size());
136
		logger.fine("number of classes : " + originalClassSet.size());
137
		logger.fine("number of object properties : " + originalObjectPropertySet.size());
138
139
		logger.fine("normalizing ontology ...");
140
		OntologyNormalizer axiomNormalizer = new OntologyNormalizer();
141
		Set<NormalizedIntegerAxiom> normalizedAxiomSet = axiomNormalizer.normalize(ontology, this.factory);
142
143
		logger.fine("creating processor (phase 2) ...");
144
		RuleBasedProcessor ret = new RuleBasedProcessor(originalObjectPropertySet, originalClassSet, normalizedAxiomSet,
145
				expressivity, this.factory.getNormalizedAxiomFactory(), this.factory.getEntityManager());
146
		logger.fine("processor created.");
147
		return ret;
148
	}
149
150
	@Override
151
	public void dispose() {
152
		// it does nothing
153
	}
154
155
	protected IntegerClass flattenClassExpression(IntegerClassExpression ce) {
156
		IntegerClass ret = null;
157
		if (ce instanceof IntegerClass) {
158
			ret = (IntegerClass) ce;
159
		} else {
160
			Integer classIndex = this.auxClassInvMap.get(ce);
161
			if (Objects.isNull(classIndex)) {
162
				Integer auxClassId = this.factory.getEntityManager().createAnonymousEntity(IntegerEntityType.CLASS,
163
						false);
164
				ret = getDataTypeFactory().createClass(auxClassId);
165
				this.auxClassMap.put(auxClassId, ce);
166
				this.auxClassInvMap.put(ce, auxClassId);
167
				Set<IntegerClassExpression> argument = new HashSet<>();
168
				argument.add(ret);
169
				argument.add(ce);
170
171
				Set<ComplexIntegerAxiom> extendedOntology = new HashSet<>();
172
				Set<IntegerAnnotation> annotations = Collections.emptySet();
173
				extendedOntology
174
						.add(this.factory.getComplexAxiomFactory().createEquivalentClassesAxiom(argument, annotations));
175
176
				OntologyNormalizer axiomNormalizer = new OntologyNormalizer();
177
				Set<NormalizedIntegerAxiom> extendedNormalizedAxiomSet = axiomNormalizer.normalize(extendedOntology,
178
						this.factory);
179
180
				this.processor.addAxioms(extendedNormalizedAxiomSet);
181
182
				this.classified = false;
183
			} else {
184
				ret = getDataTypeFactory().createClass(classIndex);
185
			}
186
		}
187
188
		return ret;
189
	}
190
191
	@Override
192
	public void flush() {
193
		this.classified = false;
194
	}
195
196
	@Override
197
	public Set<IntegerClass> getBottomClassNode() {
198
		classify();
199
		IntegerHierarchicalGraph graph = getProcessor().getClassHierarchy();
200
		return toIntegerClass(graph.getEquivalents(graph.getBottomElement()));
201
	}
202
203
	@Override
204
	public Set<IntegerDataProperty> getBottomDataPropertyNode() {
205
		classify();
206
		IntegerHierarchicalGraph graph = getProcessor().getDataPropertyHierarchy();
207
		return toIntegerDataProperty(graph.getEquivalents(graph.getBottomElement()));
208
	}
209
210
	@Override
211
	public Set<IntegerObjectPropertyExpression> getBottomObjectPropertyNode() {
212
		classify();
213
		IntegerHierarchicalGraph graph = getProcessor().getObjectPropertyHierarchy();
214
		return toIntegerObjectPropertyExpression(graph.getEquivalents(graph.getBottomElement()));
215
	}
216
217
	@Override
218
	public Set<Set<IntegerClass>> getDataPropertyDomains(IntegerDataProperty pe, boolean direct) {
219
		Objects.requireNonNull(pe);
220
		throw new UnsupportedQueryException("Unsupported query: DataPropertyDomains of " + pe);
221
	}
222
223
	@Override
224
	public Set<IntegerClass> getDataPropertyValues(IntegerNamedIndividual ind, IntegerDataProperty pe) {
225
		Objects.requireNonNull(ind);
226
		Objects.requireNonNull(pe);
227
		throw new UnsupportedQueryException("Unsupported query: DataPropertyValues of " + ind + "," + pe);
228
	}
229
230
	private IntegerDataTypeFactory getDataTypeFactory() {
231
		return this.factory.getDataTypeFactory();
232
	}
233
234
	@Override
235
	public Set<Set<IntegerNamedIndividual>> getDifferentIndividuals(IntegerNamedIndividual ind) {
236
		Objects.requireNonNull(ind);
237
		classify();
238
		// TODO Auto-generated method stub
239
		return null;
240
	}
241
242
	@Override
243
	public Set<Set<IntegerClass>> getDisjointClasses(IntegerClassExpression ce) {
244
		Objects.requireNonNull(ce);
245
		classify();
246
		// TODO Auto-generated method stub
247
		return null;
248
	}
249
250
	@Override
251
	public Set<Set<IntegerDataProperty>> getDisjointDataProperties(IntegerDataPropertyExpression pe) {
252
		Objects.requireNonNull(pe);
253
		classify();
254
		// TODO Auto-generated method stub
255
		return null;
256
	}
257
258
	@Override
259
	public Set<Set<IntegerObjectPropertyExpression>> getDisjointObjectProperties(IntegerObjectPropertyExpression pe) {
260
		Objects.requireNonNull(pe);
261
		classify();
262
		// TODO Auto-generated method stub
263
		return null;
264
	}
265
266
	@Override
267
	public Set<IntegerClass> getEquivalentClasses(IntegerClassExpression ce) {
268
		Objects.requireNonNull(ce);
269
		IntegerClass cls = flattenClassExpression(ce);
270
		classify();
271
		IntegerHierarchicalGraph graph = getProcessor().getClassHierarchy();
272
		return toIntegerClass(graph.getEquivalents(cls.getId()));
273
	}
274
275
	@Override
276
	public Set<IntegerDataProperty> getEquivalentDataProperties(IntegerDataProperty pe) {
277
		Objects.requireNonNull(pe);
278
		throw new UnsupportedQueryException("Unsupported query: EquivalentDataProperties of " + pe);
279
	}
280
281
	@Override
282
	public Set<IntegerObjectPropertyExpression> getEquivalentObjectProperties(IntegerObjectPropertyExpression pe) {
283
		Objects.requireNonNull(pe);
284
		classify();
285
		Integer propId = getObjectPropertyExpressionId(pe);
286
		IntegerHierarchicalGraph graph = getProcessor().getObjectPropertyHierarchy();
287
		return toIntegerObjectPropertyExpression(graph.getEquivalents(propId));
288
	}
289
290
	@Override
291
	public Set<Set<IntegerNamedIndividual>> getInstances(IntegerClassExpression ce, boolean direct) {
292
		Objects.requireNonNull(ce);
293
		Set<Set<IntegerNamedIndividual>> ret = new HashSet<>();
294
		IntegerClass cls = flattenClassExpression(ce);
295
		classify();
296
297
		Integer classId = cls.getId();
298
		Set<Integer> classIdSet = new HashSet<>();
299
		classIdSet.add(classId);
300
		if (!direct) {
301
			classIdSet.addAll(getProcessor().getClassHierarchy().getDescendants(classId));
302
		}
303
304
		Set<Integer> indivIdSet = new HashSet<>();
305
		indivIdSet.addAll(getProcessor().getDirectTypes().keySet());
306
307
		while (!indivIdSet.isEmpty()) {
308
			Integer indivId = indivIdSet.iterator().next();
309
			indivIdSet.remove(indivId);
310
311
			Set<Integer> types = getProcessor().getDirectTypes().get(indivId);
312
			boolean found = types.contains(classId);
313
314
			if (!found && !direct) {
315
				Set<Integer> classIdSetCopy = new HashSet<>();
316
				classIdSetCopy.addAll(classIdSet);
317
				classIdSetCopy.retainAll(types);
318
				found = !classIdSetCopy.isEmpty();
319
			}
320
321
			if (found) {
322
				Set<Integer> equivIndivId = getProcessor().getSameIndividualMap().get(indivId);
323
				Set<IntegerNamedIndividual> elem = toIntegerNamedIndividual(equivIndivId);
324
				indivIdSet.removeAll(equivIndivId);
325
				ret.add(elem);
326
			}
327
		}
328
329
		return ret;
330
	}
331
332
	@Override
333
	public Set<IntegerObjectPropertyExpression> getInverseObjectProperties(IntegerObjectPropertyExpression pe) {
334
		Objects.requireNonNull(pe);
335
		classify();
336
		// TODO implement this query
337
		throw new UnsupportedQueryException("Unsupported query: InverseObjectProperties of " + pe);
338
	}
339
340
	@Override
341
	public Set<Set<IntegerClass>> getObjectPropertyDomains(IntegerObjectPropertyExpression pe, boolean direct) {
342
		Objects.requireNonNull(pe);
343
		classify();
344
		// TODO implement this query
345
		throw new UnsupportedQueryException("Unsupported query: ObjectPropertyDomains of " + pe + "," + direct);
346
	}
347
348
	private Integer getObjectPropertyExpressionId(IntegerObjectPropertyExpression propExpr) {
349
		return propExpr.accept(new ObjectPropertyIdFinder(this.factory.getEntityManager()));
350
	}
351
352
	@Override
353
	public Set<Set<IntegerClass>> getObjectPropertyRanges(IntegerObjectPropertyExpression pe, boolean direct) {
354
		Objects.requireNonNull(pe);
355
		classify();
356
		// TODO implement this query
357
		throw new UnsupportedQueryException("Unsupported query: ObjectPropertyRanges of " + pe + "," + direct);
358
	}
359
360
	@Override
361
	public Set<Set<IntegerNamedIndividual>> getObjectPropertyValues(IntegerNamedIndividual ind,
362
			IntegerObjectPropertyExpression pe) {
363
		Objects.requireNonNull(ind);
364
		Objects.requireNonNull(pe);
365
		classify();
366
		// TODO implement this query
367
		throw new UnsupportedQueryException("Unsupported query: ObjectPropertyValues of " + ind + "," + pe);
368
	}
369
370
	public Processor getProcessor() {
371
		return this.processor;
372
	}
373
374
	@Override
375
	public String getReasonerName() {
376
		return VersionInfo.reasonerName;
377
	}
378
379
	@Override
380
	public String getReasonerVersion() {
381
		return VersionInfo.reasonerVersion;
382
	}
383
384
	@Override
385
	public Set<IntegerNamedIndividual> getSameIndividuals(IntegerNamedIndividual ind) {
386
		Objects.requireNonNull(ind);
387
		classify();
388
		return toIntegerNamedIndividual(getProcessor().getSameIndividualMap().get(ind.getId()));
389
	}
390
391
	@Override
392
	public Set<Set<IntegerClass>> getSubClasses(IntegerClassExpression ce, boolean direct) {
393
		Objects.requireNonNull(ce);
394
		IntegerClass cls = flattenClassExpression(ce);
395
		classify();
396
		IntegerHierarchicalGraph graph = getProcessor().getClassHierarchy();
397
		Set<Integer> set = null;
398
		if (direct) {
399
			set = graph.getChildren(cls.getId());
400
		} else {
401
			set = graph.getDescendants(cls.getId());
402
		}
403
		Set<Set<IntegerClass>> ret = new HashSet<>();
404
		set.forEach(currentElem -> ret.add(toIntegerClass(graph.getEquivalents(currentElem))));
405
		return ret;
406
	}
407
408
	@Override
409
	public Set<Set<IntegerDataProperty>> getSubDataProperties(IntegerDataProperty pe, boolean direct) {
410
		Objects.requireNonNull(pe);
411
		throw new UnsupportedQueryException("Unsupported query: SubDataProperties of " + pe);
412
	}
413
414
	@Override
415
	public Set<Set<IntegerObjectPropertyExpression>> getSubObjectProperties(IntegerObjectPropertyExpression pe,
416
			boolean direct) {
417
		Objects.requireNonNull(pe);
418
		classify();
419
		Integer propId = getObjectPropertyExpressionId(pe);
420
		IntegerHierarchicalGraph graph = getProcessor().getObjectPropertyHierarchy();
421
		Set<Integer> set = null;
422
		if (direct) {
423
			set = graph.getChildren(propId);
424
		} else {
425
			set = graph.getDescendants(propId);
426
		}
427
		Set<Set<IntegerObjectPropertyExpression>> ret = new HashSet<>();
428
		set.forEach(currentElem -> ret.add(toIntegerObjectPropertyExpression(graph.getEquivalents(currentElem))));
429
		return ret;
430
	}
431
432
	@Override
433
	public Set<Set<IntegerClass>> getSuperClasses(IntegerClassExpression ce, boolean direct) {
434
		Objects.requireNonNull(ce);
435
		IntegerClass cls = flattenClassExpression(ce);
436
		classify();
437
		IntegerHierarchicalGraph graph = getProcessor().getClassHierarchy();
438
		Set<Integer> set = null;
439
		if (direct) {
440
			set = graph.getParents(cls.getId());
441
		} else {
442
			set = graph.getAncestors(cls.getId());
443
		}
444
		Set<Set<IntegerClass>> ret = new HashSet<>();
445
		set.forEach(currentElem -> {
446
			Set<Integer> equivalents = graph.getEquivalents(currentElem);
447
			ret.add(toIntegerClass(equivalents));
448
		});
449
		return ret;
450
	}
451
452
	@Override
453
	public Set<Set<IntegerDataProperty>> getSuperDataProperties(IntegerDataProperty pe, boolean direct) {
454
		Objects.requireNonNull(pe);
455
		throw new UnsupportedQueryException("Unsupported query: SuperDataProperties of " + pe);
456
	}
457
458
	@Override
459
	public Set<Set<IntegerObjectPropertyExpression>> getSuperObjectProperties(IntegerObjectPropertyExpression pe,
460
			boolean direct) {
461
		Objects.requireNonNull(pe);
462
		classify();
463
		Integer propId = getObjectPropertyExpressionId(pe);
464
		IntegerHierarchicalGraph graph = getProcessor().getObjectPropertyHierarchy();
465
		Set<Integer> set = null;
466
		if (direct) {
467
			set = graph.getParents(propId);
468
		} else {
469
			set = graph.getAncestors(propId);
470
		}
471
		Set<Set<IntegerObjectPropertyExpression>> ret = new HashSet<>();
472
		set.forEach(currentElem -> ret.add(toIntegerObjectPropertyExpression(graph.getEquivalents(currentElem))));
473
		return ret;
474
	}
475
476
	@Override
477
	public long getTimeOut() {
478
		return this.timeOut;
479
	}
480
481
	@Override
482
	public Set<IntegerClass> getTopClassNode() {
483
		classify();
484
		IntegerHierarchicalGraph graph = getProcessor().getClassHierarchy();
485
		return toIntegerClass(graph.getEquivalents(graph.getTopElement()));
486
	}
487
488
	@Override
489
	public Set<IntegerDataProperty> getTopDataPropertyNode() {
490
		classify();
491
		IntegerHierarchicalGraph graph = getProcessor().getDataPropertyHierarchy();
492
		return toIntegerDataProperty(graph.getEquivalents(graph.getTopElement()));
493
	}
494
495
	@Override
496
	public Set<IntegerObjectPropertyExpression> getTopObjectPropertyNode() {
497
		classify();
498
		IntegerHierarchicalGraph graph = getProcessor().getObjectPropertyHierarchy();
499
		return toIntegerObjectPropertyExpression(graph.getEquivalents(graph.getTopElement()));
500
	}
501
502
	@Override
503
	public Set<Set<IntegerClass>> getTypes(IntegerNamedIndividual ind, boolean direct) {
504
		Objects.requireNonNull(ind);
505
		classify();
506
		IntegerHierarchicalGraph graph = getProcessor().getClassHierarchy();
507
		Map<Integer, Set<Integer>> map = getProcessor().getDirectTypes();
508
		Set<Integer> directElemSet = map.get(ind.getId());
509
		if (Objects.isNull(directElemSet)) {
510
			directElemSet = Collections.emptySet();
511
		}
512
		Set<Integer> set = null;
513
		if (direct) {
514
			set = directElemSet;
515
		} else {
516
			set = new HashSet<>();
517
			for (Integer current : directElemSet) {
518
				set.addAll(graph.getAncestors(current));
519
			}
520
		}
521
		Set<Set<IntegerClass>> ret = new HashSet<>();
522
		set.forEach(currentElem -> ret.add(toIntegerClass(graph.getEquivalents(currentElem))));
523
		return ret;
524
	}
525
526
	@Override
527
	public Set<IntegerClass> getUnsatisfiableClasses() {
528
		return getBottomClassNode();
529
	}
530
531
	@Override
532
	public void interrupt() {
533
		this.classified = false;
534
		this.interruptRequested = true;
535
	}
536
537
	public boolean isClassified() {
538
		return this.classified;
539
	}
540
541
	@Override
542
	public boolean isConsistent() {
543
		classify();
544
		return !getUnsatisfiableClasses().contains(getProcessor().getClassHierarchy().getTopElement());
545
	}
546
547
	@Override
548
	public boolean isEntailed(ComplexIntegerAxiom axiom) {
549
		Objects.requireNonNull(axiom);
550
		classify();
551
		boolean ret = axiom.accept(this.entailmentChecker);
552
		return ret;
553
	}
554
555
	@Override
556
	public boolean isEntailed(Set<ComplexIntegerAxiom> axioms) {
557
		Objects.requireNonNull(axioms);
558
		classify();
559
560
		return axioms.stream().allMatch(axiom -> axiom.accept(this.entailmentChecker));
561
	}
562
563
	@Override
564
	public boolean isSatisfiable(IntegerClassExpression classExpression) {
565
		Objects.requireNonNull(classExpression);
566
		IntegerClass cls = flattenClassExpression(classExpression);
567
		classify();
568
		return !getUnsatisfiableClasses().contains(cls);
569
	}
570
571
	private Set<IntegerClass> toIntegerClass(Set<Integer> set) {
572
		Set<IntegerClass> ret = new HashSet<>();
573
		set.forEach(elem -> ret.add(getDataTypeFactory().createClass(elem)));
574
		return ret;
575
	}
576
577
	private Set<IntegerDataProperty> toIntegerDataProperty(Set<Integer> set) {
578
		Set<IntegerDataProperty> ret = new HashSet<>();
579
		set.forEach(elem -> ret.add(getDataTypeFactory().createDataProperty(elem)));
580
		return ret;
581
	}
582
583
	private Set<IntegerNamedIndividual> toIntegerNamedIndividual(Set<Integer> set) {
584
		Set<IntegerNamedIndividual> ret = new HashSet<>();
585
		set.forEach(elem -> ret.add(getDataTypeFactory().createNamedIndividual(elem)));
586
		return ret;
587
	}
588
589
	private Set<IntegerObjectPropertyExpression> toIntegerObjectPropertyExpression(Set<Integer> set) {
590
		Set<IntegerObjectPropertyExpression> ret = new HashSet<>();
591
		set.forEach(elem -> ret.add(getDataTypeFactory().createObjectProperty(elem)));
592
		return ret;
593
	}
594
595
}
596