Debian Codegraph @

FaCT++.Java/src/main/java/uk/ac/manchester/cs/factplusplus/owlapiv3/FaCTPlusPlusReasoner.java

raw symbols SCIP
1 package uk.ac.manchester.cs.factplusplus.owlapiv3;
2
3 import java.io.PrintStream;
4 import java.util.ArrayList;
5 import java.util.Arrays;
6 import java.util.Collection;
7 import java.util.Collections;
8 import java.util.HashMap;
9 import java.util.HashSet;
10 import java.util.Iterator;
11 import java.util.List;
12 import java.util.Map;
13 import java.util.Set;
14 import java.util.concurrent.ConcurrentHashMap;
15 import java.util.concurrent.atomic.AtomicBoolean;
16
17 import javax.xml.datatype.DatatypeConfigurationException;
18 import javax.xml.datatype.DatatypeConstants;
19 import javax.xml.datatype.DatatypeFactory;
20 import javax.xml.datatype.XMLGregorianCalendar;
21
22 import org.semanticweb.owlapi.model.AddAxiom;
23 import org.semanticweb.owlapi.model.AxiomType;
24 import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom;
25 import org.semanticweb.owlapi.model.OWLAnnotationProperty;
26 import org.semanticweb.owlapi.model.OWLAnnotationPropertyDomainAxiom;
27 import org.semanticweb.owlapi.model.OWLAnnotationPropertyRangeAxiom;
28 import org.semanticweb.owlapi.model.OWLAsymmetricObjectPropertyAxiom;
29 import org.semanticweb.owlapi.model.OWLAxiom;
30 import org.semanticweb.owlapi.model.OWLAxiomVisitorEx;
31 import org.semanticweb.owlapi.model.OWLClass;
32 import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
33 import org.semanticweb.owlapi.model.OWLClassExpression;
34 import org.semanticweb.owlapi.model.OWLClassExpressionVisitorEx;
35 import org.semanticweb.owlapi.model.OWLDataAllValuesFrom;
36 import org.semanticweb.owlapi.model.OWLDataComplementOf;
37 import org.semanticweb.owlapi.model.OWLDataExactCardinality;
38 import org.semanticweb.owlapi.model.OWLDataFactory;
39 import org.semanticweb.owlapi.model.OWLDataHasValue;
40 import org.semanticweb.owlapi.model.OWLDataIntersectionOf;
41 import org.semanticweb.owlapi.model.OWLDataMaxCardinality;
42 import org.semanticweb.owlapi.model.OWLDataMinCardinality;
43 import org.semanticweb.owlapi.model.OWLDataOneOf;
44 import org.semanticweb.owlapi.model.OWLDataProperty;
45 import org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom;
46 import org.semanticweb.owlapi.model.OWLDataPropertyDomainAxiom;
47 import org.semanticweb.owlapi.model.OWLDataPropertyExpression;
48 import org.semanticweb.owlapi.model.OWLDataPropertyRangeAxiom;
49 import org.semanticweb.owlapi.model.OWLDataRange;
50 import org.semanticweb.owlapi.model.OWLDataRangeVisitorEx;
51 import org.semanticweb.owlapi.model.OWLDataSomeValuesFrom;
52 import org.semanticweb.owlapi.model.OWLDataUnionOf;
53 import org.semanticweb.owlapi.model.OWLDatatype;
54 import org.semanticweb.owlapi.model.OWLDatatypeDefinitionAxiom;
55 import org.semanticweb.owlapi.model.OWLDatatypeRestriction;
56 import org.semanticweb.owlapi.model.OWLDeclarationAxiom;
57 import org.semanticweb.owlapi.model.OWLDifferentIndividualsAxiom;
58 import org.semanticweb.owlapi.model.OWLDisjointClassesAxiom;
59 import org.semanticweb.owlapi.model.OWLDisjointDataPropertiesAxiom;
60 import org.semanticweb.owlapi.model.OWLDisjointObjectPropertiesAxiom;
61 import org.semanticweb.owlapi.model.OWLDisjointUnionAxiom;
62 import org.semanticweb.owlapi.model.OWLEntity;
63 import org.semanticweb.owlapi.model.OWLEntityVisitorEx;
64 import org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom;
65 import org.semanticweb.owlapi.model.OWLEquivalentDataPropertiesAxiom;
66 import org.semanticweb.owlapi.model.OWLEquivalentObjectPropertiesAxiom;
67 import org.semanticweb.owlapi.model.OWLFacetRestriction;
68 import org.semanticweb.owlapi.model.OWLFunctionalDataPropertyAxiom;
69 import org.semanticweb.owlapi.model.OWLFunctionalObjectPropertyAxiom;
70 import org.semanticweb.owlapi.model.OWLHasKeyAxiom;
71 import org.semanticweb.owlapi.model.OWLIndividual;
72 import org.semanticweb.owlapi.model.OWLInverseFunctionalObjectPropertyAxiom;
73 import org.semanticweb.owlapi.model.OWLInverseObjectPropertiesAxiom;
74 import org.semanticweb.owlapi.model.OWLIrreflexiveObjectPropertyAxiom;
75 import org.semanticweb.owlapi.model.OWLLiteral;
76 import org.semanticweb.owlapi.model.OWLLogicalEntity;
77 import org.semanticweb.owlapi.model.OWLNamedIndividual;
78 import org.semanticweb.owlapi.model.OWLNegativeDataPropertyAssertionAxiom;
79 import org.semanticweb.owlapi.model.OWLNegativeObjectPropertyAssertionAxiom;
80 import org.semanticweb.owlapi.model.OWLObject;
81 import org.semanticweb.owlapi.model.OWLObjectAllValuesFrom;
82 import org.semanticweb.owlapi.model.OWLObjectComplementOf;
83 import org.semanticweb.owlapi.model.OWLObjectExactCardinality;
84 import org.semanticweb.owlapi.model.OWLObjectHasSelf;
85 import org.semanticweb.owlapi.model.OWLObjectHasValue;
86 import org.semanticweb.owlapi.model.OWLObjectIntersectionOf;
87 import org.semanticweb.owlapi.model.OWLObjectInverseOf;
88 import org.semanticweb.owlapi.model.OWLObjectMaxCardinality;
89 import org.semanticweb.owlapi.model.OWLObjectMinCardinality;
90 import org.semanticweb.owlapi.model.OWLObjectOneOf;
91 import org.semanticweb.owlapi.model.OWLObjectProperty;
92 import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom;
93 import org.semanticweb.owlapi.model.OWLObjectPropertyDomainAxiom;
94 import org.semanticweb.owlapi.model.OWLObjectPropertyExpression;
95 import org.semanticweb.owlapi.model.OWLObjectPropertyRangeAxiom;
96 import org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom;
97 import org.semanticweb.owlapi.model.OWLObjectUnionOf;
98 import org.semanticweb.owlapi.model.OWLOntology;
99 import org.semanticweb.owlapi.model.OWLOntologyChange;
100 import org.semanticweb.owlapi.model.OWLOntologyChangeListener;
101 import org.semanticweb.owlapi.model.OWLOntologyManager;
102 import org.semanticweb.owlapi.model.OWLReflexiveObjectPropertyAxiom;
103 import org.semanticweb.owlapi.model.OWLRuntimeException;
104 import org.semanticweb.owlapi.model.OWLSameIndividualAxiom;
105 import org.semanticweb.owlapi.model.OWLSubAnnotationPropertyOfAxiom;
106 import org.semanticweb.owlapi.model.OWLSubClassOfAxiom;
107 import org.semanticweb.owlapi.model.OWLSubDataPropertyOfAxiom;
108 import org.semanticweb.owlapi.model.OWLSubObjectPropertyOfAxiom;
109 import org.semanticweb.owlapi.model.OWLSubPropertyChainOfAxiom;
110 import org.semanticweb.owlapi.model.OWLSymmetricObjectPropertyAxiom;
111 import org.semanticweb.owlapi.model.OWLTransitiveObjectPropertyAxiom;
112 import org.semanticweb.owlapi.model.RemoveAxiom;
113 import org.semanticweb.owlapi.model.SWRLRule;
114 import org.semanticweb.owlapi.reasoner.AxiomNotInProfileException;
115 import org.semanticweb.owlapi.reasoner.BufferingMode;
116 import org.semanticweb.owlapi.reasoner.ClassExpressionNotInProfileException;
117 import org.semanticweb.owlapi.reasoner.FreshEntitiesException;
118 import org.semanticweb.owlapi.reasoner.FreshEntityPolicy;
119 import org.semanticweb.owlapi.reasoner.InconsistentOntologyException;
120 import org.semanticweb.owlapi.reasoner.IndividualNodeSetPolicy;
121 import org.semanticweb.owlapi.reasoner.InferenceType;
122 import org.semanticweb.owlapi.reasoner.Node;
123 import org.semanticweb.owlapi.reasoner.NodeSet;
124 import org.semanticweb.owlapi.reasoner.OWLReasoner;
125 import org.semanticweb.owlapi.reasoner.OWLReasonerConfiguration;
126 import org.semanticweb.owlapi.reasoner.ReasonerInternalException;
127 import org.semanticweb.owlapi.reasoner.ReasonerInterruptedException;
128 import org.semanticweb.owlapi.reasoner.ReasonerProgressMonitor;
129 import org.semanticweb.owlapi.reasoner.TimeOutException;
130 import org.semanticweb.owlapi.reasoner.UnsupportedEntailmentTypeException;
131 import org.semanticweb.owlapi.reasoner.impl.DefaultNode;
132 import org.semanticweb.owlapi.reasoner.impl.DefaultNodeSet;
133 import org.semanticweb.owlapi.reasoner.impl.OWLClassNode;
134 import org.semanticweb.owlapi.reasoner.impl.OWLClassNodeSet;
135 import org.semanticweb.owlapi.reasoner.impl.OWLDataPropertyNode;
136 import org.semanticweb.owlapi.reasoner.impl.OWLDataPropertyNodeSet;
137 import org.semanticweb.owlapi.reasoner.impl.OWLDatatypeNode;
138 import org.semanticweb.owlapi.reasoner.impl.OWLDatatypeNodeSet;
139 import org.semanticweb.owlapi.reasoner.impl.OWLNamedIndividualNode;
140 import org.semanticweb.owlapi.reasoner.impl.OWLNamedIndividualNodeSet;
141 import org.semanticweb.owlapi.reasoner.impl.OWLObjectPropertyNode;
142 import org.semanticweb.owlapi.reasoner.impl.OWLObjectPropertyNodeSet;
143 import org.semanticweb.owlapi.util.Version;
144 import org.semanticweb.owlapi.vocab.OWL2Datatype;
145 import org.semanticweb.owlapi.vocab.OWLFacet;
146
147 import uk.ac.manchester.cs.factplusplus.AxiomPointer;
148 import uk.ac.manchester.cs.factplusplus.ClassPointer;
149 import uk.ac.manchester.cs.factplusplus.DataPropertyPointer;
150 import uk.ac.manchester.cs.factplusplus.DataTypeExpressionPointer;
151 import uk.ac.manchester.cs.factplusplus.DataTypeFacet;
152 import uk.ac.manchester.cs.factplusplus.DataTypePointer;
153 import uk.ac.manchester.cs.factplusplus.DataValuePointer;
154 import uk.ac.manchester.cs.factplusplus.FaCTPlusPlus;
155 import uk.ac.manchester.cs.factplusplus.FaCTPlusPlusProgressMonitor;
156 import uk.ac.manchester.cs.factplusplus.IndividualPointer;
157 import uk.ac.manchester.cs.factplusplus.NodePointer;
158 import uk.ac.manchester.cs.factplusplus.ObjectPropertyPointer;
159 import uk.ac.manchester.cs.factplusplus.Pointer;
160 import uk.ac.manchester.cs.owlapi.modularity.ModuleType;
161
162 /*
163 * Copyright (C) 2009-2010, University of Manchester
164 *
165 * Modifications to the initial code base are copyright of their
166 * respective authors, or their employers as appropriate. Authorship
167 * of the modifications may be determined from the ChangeLog placed at
168 * the end of this file.
169 *
170 * This library is free software; you can redistribute it and/or
171 * modify it under the terms of the GNU Lesser General Public
172 * License as published by the Free Software Foundation; either
173 * version 2.1 of the License, or (at your option) any later version.
174
175 * This library is distributed in the hope that it will be useful,
176 * but WITHOUT ANY WARRANTY; without even the implied warranty of
177 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
178 * Lesser General Public License for more details.
179
180 * You should have received a copy of the GNU Lesser General Public
181 * License along with this library; if not, write to the Free Software
182 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
183 */
184 /**
185 * Author: Matthew Horridge<br>
186 * The University of Manchester<br>
187 * Information Management Group<br>
188 * Date: 29-Dec-2009 Synchronization policy: all methods for OWLReasoner are
189 * synchronized, except the methods which do not touch the kernel or only affect
190 * threadsafe data structures. inner private classes are not synchronized since
191 * methods from those classes cannot be invoked from outsize synchronized
192 * methods.
193 */
194 public class FaCTPlusPlusReasoner implements OWLReasoner,
195 OWLOntologyChangeListener {
196
197 /**
198 * reasoner name
199 */
200 public static final String REASONER_NAME = "FaCT++";
201 /**
202 * reasoner version
203 */
204 public static final Version VERSION = new Version(1, 6, 4, 1);
205 protected final AtomicBoolean interrupted = new AtomicBoolean(false);
206 protected final FaCTPlusPlus kernel = new FaCTPlusPlus();
207 private volatile AxiomTranslator axiomTranslator = new AxiomTranslator();
208 private volatile ClassExpressionTranslator classExpressionTranslator;
209 private volatile DataRangeTranslator dataRangeTranslator;
210 private volatile ObjectPropertyTranslator objectPropertyTranslator;
211 private volatile DataPropertyTranslator dataPropertyTranslator;
212 private volatile IndividualTranslator individualTranslator;
213 private volatile EntailmentChecker entailmentChecker;
214 private final Map<OWLAxiom, AxiomPointer> axiom2PtrMap = new HashMap<>();
215 private final Map<AxiomPointer, OWLAxiom> ptr2AxiomMap = new HashMap<>();
216 private static final Set<InferenceType> SupportedInferenceTypes = new HashSet<>(
217 Arrays.asList(InferenceType.CLASS_ASSERTIONS,
218 InferenceType.CLASS_HIERARCHY,
219 InferenceType.DATA_PROPERTY_HIERARCHY,
220 InferenceType.OBJECT_PROPERTY_HIERARCHY,
221 InferenceType.SAME_INDIVIDUAL));
222 private final OWLOntologyManager manager;
223 private final OWLOntology rootOntology;
224 private final BufferingMode bufferingMode;
225 private final List<OWLOntologyChange> rawChanges = new ArrayList<>();
226 // private final ReentrantReadWriteLock rawChangesLock = new
227 // ReentrantReadWriteLock();
228 private final Set<OWLAxiom> reasonerAxioms = new HashSet<>();
229 private final long timeOut;
230 private final OWLReasonerConfiguration configuration;
231
232 @Override
233 public void ontologiesChanged(List<? extends OWLOntologyChange> changes) {
234 handleRawOntologyChanges(changes);
235 }
236
237 /**
238 * @return reasoner configuration
239 */
240 public OWLReasonerConfiguration getReasonerConfiguration() {
241 return configuration;
242 }
243
244 @Override
245 public BufferingMode getBufferingMode() {
246 return bufferingMode;
247 }
248
249 @Override
250 public long getTimeOut() {
251 return timeOut;
252 }
253
254 @Override
255 public OWLOntology getRootOntology() {
256 return rootOntology;
257 }
258
259 private final boolean log = false;
260
261 /**
262 * Handles raw ontology changes. If the reasoner is a buffering reasoner
263 * then the changes will be stored in a buffer. If the reasoner is a
264 * non-buffering reasoner then the changes will be automatically flushed
265 * through to the change filter and passed on to the reasoner.
266 *
267 * @param changes
268 * The list of raw changes.
269 */
270 private synchronized void handleRawOntologyChanges(
271 List<? extends OWLOntologyChange> changes) {
272 if (log) {
273 System.out.println(Thread.currentThread().getName()
274 + " OWLReasonerBase.handleRawOntologyChanges() " + changes);
275 }
276 rawChanges.addAll(changes);
277 // We auto-flush the changes if the reasoner is non-buffering
278 if (bufferingMode.equals(BufferingMode.NON_BUFFERING)) {
279 flush();
280 }
281 }
282
283 @Override
284 public synchronized List<OWLOntologyChange> getPendingChanges() {
285 return new ArrayList<>(rawChanges);
286 }
287
288 @Override
289 public synchronized Set<OWLAxiom> getPendingAxiomAdditions() {
290 if (rawChanges.size() > 0) {
291 Set<OWLAxiom> added = new HashSet<>();
292 computeDiff(added, new HashSet<OWLAxiom>());
293 return added;
294 }
295 return Collections.emptySet();
296 }
297
298 @Override
299 public synchronized Set<OWLAxiom> getPendingAxiomRemovals() {
300 if (rawChanges.size() > 0) {
301 Set<OWLAxiom> removed = new HashSet<>();
302 computeDiff(new HashSet<OWLAxiom>(), removed);
303 return removed;
304 }
305 return Collections.emptySet();
306 }
307
308 /**
309 * Flushes the pending changes from the pending change list. The changes
310 * will be analysed to determine which axioms have actually been added and
311 * removed from the imports closure of the root ontology and then the
312 * reasoner will be asked to handle these changes via the
313 * {@link #handleChanges(java.util.Set, java.util.Set)} method.
314 */
315 @Override
316 public synchronized void flush() {
317 // Process the changes
318 if (rawChanges.size() > 0) {
319 final Set<OWLAxiom> added = new HashSet<>();
320 final Set<OWLAxiom> removed = new HashSet<>();
321 computeDiff(added, removed);
322 reasonerAxioms.removeAll(removed);
323 reasonerAxioms.addAll(added);
324 rawChanges.clear();
325 if (!added.isEmpty() || !removed.isEmpty()) {
326 handleChanges(added, removed);
327 }
328 }
329 }
330
331 /**
332 * Computes a diff of what axioms have been added and what axioms have been
333 * removed from the list of pending changes. Note that even if the list of
334 * pending changes is non-empty then there may be no changes for the
335 * reasoner to deal with.
336 *
337 * @param added
338 * The logical axioms that have been added to the imports closure of
339 * the reasoner root ontology
340 * @param removed
341 * The logical axioms that have been removed from the imports closure
342 * of the reasoner root ontology
343 */
344 private synchronized void computeDiff(Set<OWLAxiom> added,
345 Set<OWLAxiom> removed) {
346 for (OWLOntologyChange change : rawChanges) {
347 if (change instanceof AddAxiom) {
348 OWLAxiom ax = change.getAxiom().getAxiomWithoutAnnotations();
349 // check whether an axiom is new
350 if (!reasonerAxioms.contains(ax)) {
351 added.add(ax);
352 }
353 } else if (change instanceof RemoveAxiom) {
354 removed.add(change.getAxiom().getAxiomWithoutAnnotations());
355 }
356 }
357 // in case an axiom was added and then removed without a flush()
358 added.removeAll(removed);
359 }
360
361 /**
362 * Gets the axioms that should be currently being reasoned over.
363 *
364 * @return A collections of axioms (not containing duplicates) that the
365 * reasoner should be taking into consideration when reasoning. This
366 * set of axioms many not correspond to the current state of the
367 * imports closure of the reasoner root ontology if the reasoner is
368 * buffered.
369 */
370 public synchronized Collection<OWLAxiom> getReasonerAxioms() {
371 return new ArrayList<>(reasonerAxioms);
372 }
373
374 @Override
375 public FreshEntityPolicy getFreshEntityPolicy() {
376 return configuration.getFreshEntityPolicy();
377 }
378
379 @Override
380 public IndividualNodeSetPolicy getIndividualNodeSetPolicy() {
381 return configuration.getIndividualNodeSetPolicy();
382 }
383
384 /**
385 * @return data factory
386 */
387 public OWLDataFactory getOWLDataFactory() {
388 return rootOntology.getOWLOntologyManager().getOWLDataFactory();
389 }
390
391 /**
392 * @param rootOntology
393 * ontology
394 * @param configuration
395 * configuration
396 * @param bufferingMode
397 * buffering
398 */
399 public FaCTPlusPlusReasoner(OWLOntology rootOntology,
400 OWLReasonerConfiguration configuration, BufferingMode bufferingMode) {
401 this.rootOntology = rootOntology;
402 this.bufferingMode = bufferingMode;
403 this.configuration = configuration;
404 timeOut = configuration.getTimeOut();
405 manager = rootOntology.getOWLOntologyManager();
406 for (OWLOntology ont : rootOntology.getImportsClosure()) {
407 for (OWLAxiom ax : ont.getLogicalAxioms()) {
408 reasonerAxioms.add(ax.getAxiomWithoutAnnotations());
409 }
410 for (OWLAxiom ax : ont.getAxioms(AxiomType.DECLARATION)) {
411 reasonerAxioms.add(ax.getAxiomWithoutAnnotations());
412 }
413 }
414 axiomTranslator = new AxiomTranslator();
415 classExpressionTranslator = new ClassExpressionTranslator();
416 dataRangeTranslator = new DataRangeTranslator();
417 objectPropertyTranslator = new ObjectPropertyTranslator();
418 dataPropertyTranslator = new DataPropertyTranslator();
419 individualTranslator = new IndividualTranslator();
420 entailmentChecker = new EntailmentChecker();
421 kernel.setTopBottomPropertyNames(
422 "http://www.w3.org/2002/07/owl#topObjectProperty",
423 "http://www.w3.org/2002/07/owl#bottomObjectProperty",
424 "http://www.w3.org/2002/07/owl#topDataProperty",
425 "http://www.w3.org/2002/07/owl#bottomDataProperty");
426 kernel.setProgressMonitor(new ProgressMonitorAdapter(configuration
427 .getProgressMonitor(), interrupted));
428 long millis = configuration.getTimeOut();
429 if (millis == Long.MAX_VALUE) {
430 millis = 0;
431 }
432 kernel.setOperationTimeout(millis);
433 kernel.setFreshEntityPolicy(configuration.getFreshEntityPolicy() == FreshEntityPolicy.ALLOW);
434 loadReasonerAxioms();
435 }
436
437 // /////////////////////////////////////////////////////////////////////////
438 //
439 // load/retract axioms
440 //
441 // /////////////////////////////////////////////////////////////////////////
442 private void loadAxiom(OWLAxiom axiom) {
443 if (axiom2PtrMap.containsKey(axiom)) {
444 return;
445 }
446 final AxiomPointer axiomPointer = axiom.accept(axiomTranslator);
447 if (axiomPointer != null) {
448 axiom2PtrMap.put(axiom, axiomPointer);
449 ptr2AxiomMap.put(axiomPointer, axiom);
450 }
451 }
452
453 private void retractAxiom(OWLAxiom axiom) {
454 final AxiomPointer ptr = axiom2PtrMap.get(axiom);
455 if (ptr != null) {
456 kernel.retract(ptr);
457 axiom2PtrMap.remove(axiom);
458 ptr2AxiomMap.remove(ptr);
459 }
460 }
461
462 /**
463 * Asks the reasoner implementation to handle axiom additions and removals
464 * from the imports closure of the root ontology. The changes will not
465 * include annotation axiom additions and removals.
466 *
467 * @param addAxioms
468 * The axioms to be added to the reasoner.
469 * @param removeAxioms
470 * The axioms to be removed from the reasoner
471 */
472 protected void handleChanges(Set<OWLAxiom> addAxioms,
473 Set<OWLAxiom> removeAxioms) {
474 kernel.startChanges();
475 for (OWLAxiom ax_a : addAxioms) {
476 loadAxiom(ax_a);
477 }
478 for (OWLAxiom ax_r : removeAxioms) {
479 retractAxiom(ax_r);
480 }
481 kernel.endChanges();
482 }
483
484 private void loadReasonerAxioms() {
485 getReasonerConfiguration().getProgressMonitor().reasonerTaskStarted(
486 ReasonerProgressMonitor.LOADING);
487 getReasonerConfiguration().getProgressMonitor().reasonerTaskBusy();
488 kernel.clearKernel();
489 axiomTranslator = new AxiomTranslator();
490 classExpressionTranslator = new ClassExpressionTranslator();
491 dataRangeTranslator = new DataRangeTranslator();
492 objectPropertyTranslator = new ObjectPropertyTranslator();
493 dataPropertyTranslator = new DataPropertyTranslator();
494 individualTranslator = new IndividualTranslator();
495 axiom2PtrMap.clear();
496 ptr2AxiomMap.clear();
497 for (OWLAxiom ax : reasonerAxioms) {
498 loadAxiom(ax);
499 }
500 getReasonerConfiguration().getProgressMonitor().reasonerTaskStopped();
501 }
502
503 // /////////////////////////////////////////////////////////////////////////////////////////////////////////////
504 // /////////////////////////////////////////////////////////////////////////////////////////////////////////////
505 // /////////////////////////////////////////////////////////////////////////////////////////////////////////////
506 // /////////////////////////////////////////////////////////////////////////////////////////////////////////////
507 // ////
508 // ////
509 // //// Implementation of reasoner interfaces
510 // ////
511 // ////
512 // /////////////////////////////////////////////////////////////////////////////////////////////////////////////
513 // /////////////////////////////////////////////////////////////////////////////////////////////////////////////
514 // /////////////////////////////////////////////////////////////////////////////////////////////////////////////
515 @Override
516 public String getReasonerName() {
517 return REASONER_NAME;
518 }
519
520 @Override
521 public Version getReasonerVersion() {
522 return VERSION;
523 }
524
525 @Override
526 public void interrupt() {
527 interrupted.set(true);
528 }
529
530 // precompute inferences
531 @Override
532 public synchronized void precomputeInferences(
533 InferenceType... inferenceTypes)
534 throws ReasonerInterruptedException, TimeOutException,
535 InconsistentOntologyException {
536 for (InferenceType it : inferenceTypes) {
537 if (SupportedInferenceTypes.contains(it)) {
538 kernel.realise();
539 return;
540 }
541 }
542 }
543
544 @Override
545 public boolean isPrecomputed(InferenceType inferenceType) {
546 if (SupportedInferenceTypes.contains(inferenceType)) {
547 return kernel.isRealised();
548 }
549 return true;
550 }
551
552 @Override
553 public Set<InferenceType> getPrecomputableInferenceTypes() {
554 return SupportedInferenceTypes;
555 }
556
557 // consistency
558 @Override
559 public synchronized boolean isConsistent()
560 throws ReasonerInterruptedException, TimeOutException {
561 return kernel.isKBConsistent();
562 }
563
564 private void checkConsistency() {
565 if (interrupted.get()) {
566 throw new ReasonerInterruptedException();
567 }
568 if (!isConsistent()) {
569 throw new InconsistentOntologyException();
570 }
571 }
572
573 @Override
574 public synchronized boolean
575 isSatisfiable(OWLClassExpression classExpression)
576 throws ReasonerInterruptedException, TimeOutException,
577 ClassExpressionNotInProfileException,
578 FreshEntitiesException, InconsistentOntologyException {
579 checkConsistency();
580 return kernel.isClassSatisfiable(toClassPointer(classExpression));
581 }
582
583 @Override
584 public Node<OWLClass> getUnsatisfiableClasses()
585 throws ReasonerInterruptedException, TimeOutException,
586 InconsistentOntologyException {
587 return getBottomClassNode();
588 }
589
590 // entailments
591 @Override
592 public synchronized boolean isEntailed(OWLAxiom axiom)
593 throws ReasonerInterruptedException,
594 UnsupportedEntailmentTypeException, TimeOutException,
595 AxiomNotInProfileException, FreshEntitiesException,
596 InconsistentOntologyException {
597 checkConsistency();
598 // if(rootOntology.containsAxiom(axiom, true)) {
599 // return true;
600 // }
601 Boolean entailed = axiom.accept(entailmentChecker);
602 if (entailed == null) {
603 throw new UnsupportedEntailmentTypeException(axiom);
604 }
605 return entailed;
606 }
607
608 @Override
609 public synchronized boolean isEntailed(Set<? extends OWLAxiom> axioms)
610 throws ReasonerInterruptedException,
611 UnsupportedEntailmentTypeException, TimeOutException,
612 AxiomNotInProfileException, FreshEntitiesException,
613 InconsistentOntologyException {
614 for (OWLAxiom ax : axioms) {
615 if (!isEntailed(ax)) {
616 return false;
617 }
618 }
619 return true;
620 }
621
622 @Override
623 public boolean isEntailmentCheckingSupported(AxiomType<?> axiomType) {
624 if (axiomType.equals(AxiomType.SWRL_RULE)) {
625 return false;
626 }
627 // FIXME!! check later
628 return true;
629 }
630
631 // tracing
632 /**
633 * @param axiom
634 * axiom to trace
635 * @return tracing set (set of axioms that were participate in achieving
636 * result) for a given entailment. Return empty set if the axiom is
637 * not entailed.
638 */
639 public Set<OWLAxiom> getTrace(OWLAxiom axiom) {
640 kernel.needTracing();
641 Set<OWLAxiom> ret = new HashSet<>();
642 if (isEntailed(axiom)) {
643 for (AxiomPointer ap : kernel.getTrace()) {
644 ret.add(ptr2AxiomMap.get(ap));
645 }
646 }
647 return ret;
648 }
649
650 // classes
651 @Override
652 public Node<OWLClass> getTopClassNode() {
653 return getEquivalentClasses(getOWLDataFactory().getOWLThing());
654 }
655
656 @Override
657 public Node<OWLClass> getBottomClassNode() {
658 return getEquivalentClasses(getOWLDataFactory().getOWLNothing());
659 }
660
661 @Override
662 public synchronized NodeSet<OWLClass> getSubClasses(OWLClassExpression ce,
663 boolean direct) throws ReasonerInterruptedException,
664 TimeOutException, FreshEntitiesException,
665 InconsistentOntologyException {
666 checkConsistency();
667 return classExpressionTranslator.getNodeSetFromPointers(kernel
668 .askSubClasses(toClassPointer(ce), direct));
669 }
670
671 @Override
672 public synchronized NodeSet<OWLClass> getSuperClasses(
673 OWLClassExpression ce, boolean direct)
674 throws InconsistentOntologyException,
675 ClassExpressionNotInProfileException, ReasonerInterruptedException,
676 TimeOutException {
677 checkConsistency();
678 return classExpressionTranslator.getNodeSetFromPointers(kernel
679 .askSuperClasses(toClassPointer(ce), direct));
680 }
681
682 @Override
683 public synchronized Node<OWLClass> getEquivalentClasses(
684 OWLClassExpression ce) throws InconsistentOntologyException,
685 ClassExpressionNotInProfileException, ReasonerInterruptedException,
686 TimeOutException {
687 checkConsistency();
688 ClassPointer[] pointers = kernel
689 .askEquivalentClasses(toClassPointer(ce));
690 return classExpressionTranslator.getNodeFromPointers(pointers);
691 }
692
693 @Override
694 public synchronized NodeSet<OWLClass> getDisjointClasses(
695 OWLClassExpression ce) {
696 checkConsistency();
697 return classExpressionTranslator.getNodeSetFromPointers(kernel
698 .askDisjointClasses(toClassPointer(ce)));
699 }
700
701 // object properties
702 @Override
703 public Node<OWLObjectPropertyExpression> getTopObjectPropertyNode() {
704 return getEquivalentObjectProperties(getOWLDataFactory()
705 .getOWLTopObjectProperty());
706 }
707
708 @Override
709 public Node<OWLObjectPropertyExpression> getBottomObjectPropertyNode() {
710 return getEquivalentObjectProperties(getOWLDataFactory()
711 .getOWLBottomObjectProperty());
712 }
713
714 @Override
715 public synchronized NodeSet<OWLObjectPropertyExpression>
716 getSubObjectProperties(OWLObjectPropertyExpression pe,
717 boolean direct) throws InconsistentOntologyException,
718 ReasonerInterruptedException, TimeOutException {
719 checkConsistency();
720 return objectPropertyTranslator.getNodeSetFromPointers(kernel
721 .askSubObjectProperties(toObjectPropertyPointer(pe), direct));
722 }
723
724 @Override
725 public synchronized NodeSet<OWLObjectPropertyExpression>
726 getSuperObjectProperties(OWLObjectPropertyExpression pe,
727 boolean direct) throws InconsistentOntologyException,
728 ReasonerInterruptedException, TimeOutException {
729 checkConsistency();
730 return objectPropertyTranslator.getNodeSetFromPointers(kernel
731 .askSuperObjectProperties(toObjectPropertyPointer(pe), direct));
732 }
733
734 @Override
735 public synchronized Node<OWLObjectPropertyExpression>
736 getEquivalentObjectProperties(OWLObjectPropertyExpression pe)
737 throws InconsistentOntologyException,
738 ReasonerInterruptedException, TimeOutException {
739 checkConsistency();
740 return objectPropertyTranslator.getNodeFromPointers(kernel
741 .askEquivalentObjectProperties(toObjectPropertyPointer(pe)));
742 }
743
744 @Override
745 public synchronized NodeSet<OWLObjectPropertyExpression>
746 getDisjointObjectProperties(OWLObjectPropertyExpression pe)
747 throws InconsistentOntologyException,
748 ReasonerInterruptedException, TimeOutException {
749 checkConsistency();
750 // TODO: incomplete
751 OWLObjectPropertyNodeSet toReturn = new OWLObjectPropertyNodeSet();
752 toReturn.addNode(getBottomObjectPropertyNode());
753 return toReturn;
754 }
755
756 @Override
757 public synchronized Node<OWLObjectPropertyExpression>
758 getInverseObjectProperties(OWLObjectPropertyExpression pe)
759 throws InconsistentOntologyException,
760 ReasonerInterruptedException, TimeOutException {
761 checkConsistency();
762 return objectPropertyTranslator.getNodeFromPointers(kernel
763 .askEquivalentObjectProperties(toObjectPropertyPointer(pe
764 .getInverseProperty())));
765 }
766
767 @Override
768 public synchronized NodeSet<OWLClass> getObjectPropertyDomains(
769 OWLObjectPropertyExpression pe, boolean direct)
770 throws InconsistentOntologyException, ReasonerInterruptedException,
771 TimeOutException {
772 checkConsistency();
773 return classExpressionTranslator.getNodeSetFromPointers(kernel
774 .askObjectPropertyDomain(
775 objectPropertyTranslator.getPointerFromEntity(pe),
776 direct));
777 }
778
779 @Override
780 public NodeSet<OWLClass> getObjectPropertyRanges(
781 OWLObjectPropertyExpression pe, boolean direct)
782 throws InconsistentOntologyException, ReasonerInterruptedException,
783 TimeOutException {
784 checkConsistency();
785 return classExpressionTranslator.getNodeSetFromPointers(kernel
786 .askObjectPropertyRange(
787 objectPropertyTranslator.getPointerFromEntity(pe),
788 direct));
789 }
790
791 // data properties
792 @Override
793 public Node<OWLDataProperty> getTopDataPropertyNode() {
794 OWLDataPropertyNode toReturn = new OWLDataPropertyNode();
795 toReturn.add(getOWLDataFactory().getOWLTopDataProperty());
796 return toReturn;
797 }
798
799 @Override
800 public Node<OWLDataProperty> getBottomDataPropertyNode() {
801 return getEquivalentDataProperties(getOWLDataFactory()
802 .getOWLBottomDataProperty());
803 }
804
805 @Override
806 public synchronized NodeSet<OWLDataProperty> getSubDataProperties(
807 OWLDataProperty pe, boolean direct)
808 throws InconsistentOntologyException, ReasonerInterruptedException,
809 TimeOutException {
810 checkConsistency();
811 return dataPropertyTranslator.getNodeSetFromPointers(kernel
812 .askSubDataProperties(toDataPropertyPointer(pe), direct));
813 }
814
815 @Override
816 public synchronized NodeSet<OWLDataProperty> getSuperDataProperties(
817 OWLDataProperty pe, boolean direct)
818 throws InconsistentOntologyException, ReasonerInterruptedException,
819 TimeOutException {
820 checkConsistency();
821 return dataPropertyTranslator.getNodeSetFromPointers(kernel
822 .askSuperDataProperties(toDataPropertyPointer(pe), direct));
823 }
824
825 @Override
826 public synchronized Node<OWLDataProperty> getEquivalentDataProperties(
827 OWLDataProperty pe) throws InconsistentOntologyException,
828 ReasonerInterruptedException, TimeOutException {
829 checkConsistency();
830 return dataPropertyTranslator.getNodeFromPointers(kernel
831 .askEquivalentDataProperties(toDataPropertyPointer(pe)));
832 }
833
834 @Override
835 public synchronized NodeSet<OWLDataProperty> getDisjointDataProperties(
836 OWLDataPropertyExpression pe) throws InconsistentOntologyException,
837 ReasonerInterruptedException, TimeOutException {
838 checkConsistency();
839 // TODO:
840 return new OWLDataPropertyNodeSet();
841 }
842
843 @Override
844 public NodeSet<OWLClass> getDataPropertyDomains(OWLDataProperty pe,
845 boolean direct) throws InconsistentOntologyException,
846 ReasonerInterruptedException, TimeOutException {
847 checkConsistency();
848 return classExpressionTranslator.getNodeSetFromPointers(kernel
849 .askDataPropertyDomain(
850 dataPropertyTranslator.getPointerFromEntity(pe),
851 direct));
852 }
853
854 // individuals
855 @Override
856 public synchronized NodeSet<OWLClass> getTypes(OWLNamedIndividual ind,
857 boolean direct) throws InconsistentOntologyException,
858 ReasonerInterruptedException, TimeOutException {
859 checkConsistency();
860 return classExpressionTranslator.getNodeSetFromPointers(kernel
861 .askIndividualTypes(toIndividualPointer(ind), direct));
862 }
863
864 @Override
865 public synchronized NodeSet<OWLNamedIndividual> getInstances(
866 OWLClassExpression ce, boolean direct)
867 throws InconsistentOntologyException,
868 ClassExpressionNotInProfileException, ReasonerInterruptedException,
869 TimeOutException {
870 checkConsistency();
871 return translateIndividualPointersToNodeSet(kernel.askInstances(
872 toClassPointer(ce), direct));
873 }
874
875 @Override
876 public synchronized NodeSet<OWLNamedIndividual> getObjectPropertyValues(
877 OWLNamedIndividual ind, OWLObjectPropertyExpression pe)
878 throws InconsistentOntologyException, ReasonerInterruptedException,
879 TimeOutException {
880 checkConsistency();
881 return translateIndividualPointersToNodeSet(kernel
882 .askRelatedIndividuals(toIndividualPointer(ind),
883 toObjectPropertyPointer(pe)));
884 }
885
886 @Override
887 public synchronized Set<OWLLiteral> getDataPropertyValues(
888 OWLNamedIndividual ind, OWLDataProperty pe)
889 throws InconsistentOntologyException, ReasonerInterruptedException,
890 TimeOutException {
891 // TODO:
892 checkConsistency();
893 return Collections.emptySet();
894 }
895
896 @Override
897 public synchronized Node<OWLNamedIndividual> getSameIndividuals(
898 OWLNamedIndividual ind) throws InconsistentOntologyException,
899 ReasonerInterruptedException, TimeOutException {
900 checkConsistency();
901 return individualTranslator.getNodeFromPointers(kernel
902 .askSameAs(toIndividualPointer(ind)));
903 }
904
905 @Override
906 public NodeSet<OWLNamedIndividual> getDifferentIndividuals(
907 OWLNamedIndividual ind) throws InconsistentOntologyException,
908 ReasonerInterruptedException, TimeOutException {
909 OWLClassExpression ce = getOWLDataFactory().getOWLObjectOneOf(ind)
910 .getObjectComplementOf();
911 return getInstances(ce, false);
912 }
913
914 /**
915 * get all individuals from the set individuals that has r-successor and
916 * s-successor and those are related via OP: r op s
917 *
918 * @param individuals
919 * set of individuals to choose from
920 * @param r
921 * first operand of the comparison
922 * @param s
923 * second operand of the comparison
924 * @param op
925 * comparison operation: 0 means "==", 1 means "!=", 2 means "&lt;",
926 * 3 means "&lt;=", 4 means "&gt;", 5 means "&gt;="
927 * @return data related individuals
928 */
929 public Node<OWLNamedIndividual> getDataRelatedIndividuals(
930 Set<OWLIndividual> individuals, OWLDataProperty r,
931 OWLDataProperty s, int op) {
932 checkConsistency();
933 // load all the individuals as parameters
934 translateIndividualSet(individuals);
935 return individualTranslator.getNodeFromPointers(kernel
936 .getDataRelatedIndividuals(toDataPropertyPointer(r),
937 toDataPropertyPointer(s), op));
938 }
939
940 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
941 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
942 // //
943 // // Translation to FaCT++ structures and back
944 // //
945 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
946 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
947 private abstract class OWLEntityTranslator<E extends OWLObject, P extends Pointer> {
948
949 private final Map<E, P> entity2PointerMap = new ConcurrentHashMap<>();
950 protected final Map<P, E> pointer2EntityMap = new ConcurrentHashMap<>();
951
952 protected void fillEntityPointerMaps(E entity, P pointer) {
953 entity2PointerMap.put(entity, pointer);
954 pointer2EntityMap.put(pointer, entity);
955 }
956
957 protected OWLEntityTranslator() {
958 E topEntity = getTopEntity();
959 if (topEntity != null) {
960 fillEntityPointerMaps(topEntity, getTopEntityPointer());
961 }
962 E bottomEntity = getBottomEntity();
963 if (bottomEntity != null) {
964 fillEntityPointerMaps(bottomEntity, getBottomEntityPointer());
965 }
966 }
967
968 protected P registerNewEntity(E entity) {
969 P pointer = createPointerForEntity(entity);
970 fillEntityPointerMaps(entity, pointer);
971 return pointer;
972 }
973
974 public E getEntityFromPointer(P pointer) {
975 return pointer2EntityMap.get(pointer);
976 }
977
978 public P getPointerFromEntity(E entity) {
979 if (entity.isTopEntity()) {
980 return getTopEntityPointer();
981 } else if (entity.isBottomEntity()) {
982 return getBottomEntityPointer();
983 } else {
984 P pointer = entity2PointerMap.get(entity);
985 if (pointer == null) {
986 pointer = registerNewEntity(entity);
987 }
988 return pointer;
989 }
990 }
991
992 public Node<E> getNodeFromPointers(P[] pointers) {
993 DefaultNode<E> node = createDefaultNode();
994 for (P pointer : pointers) {
995 final E entityFromPointer = getEntityFromPointer(pointer);
996 if (entityFromPointer != null) {
997 node.add(entityFromPointer);
998 }
999 }
1000 return node;
1001 }
1002
1003 public NodeSet<E> getNodeSetFromPointers(P[][] pointers) {
1004 DefaultNodeSet<E> nodeSet = createDefaultNodeSet();
1005 for (P[] pointerArray : pointers) {
1006 nodeSet.addNode(getNodeFromPointers(pointerArray));
1007 }
1008 return nodeSet;
1009 }
1010
1011 protected abstract DefaultNode<E> createDefaultNode();
1012
1013 protected abstract DefaultNodeSet<E> createDefaultNodeSet();
1014
1015 protected abstract P getTopEntityPointer();
1016
1017 protected abstract P getBottomEntityPointer();
1018
1019 protected abstract P createPointerForEntity(E entity);
1020
1021 protected abstract E getTopEntity();
1022
1023 protected abstract E getBottomEntity();
1024 }
1025
1026 protected ClassPointer toClassPointer(OWLClassExpression classExpression) {
1027 return classExpression.accept(classExpressionTranslator);
1028 }
1029
1030 protected DataTypeExpressionPointer toDataTypeExpressionPointer(
1031 OWLDataRange dataRange) {
1032 return dataRange.accept(dataRangeTranslator);
1033 }
1034
1035 protected ObjectPropertyPointer toObjectPropertyPointer(
1036 OWLObjectPropertyExpression propertyExpression) {
1037 return objectPropertyTranslator.getPointerFromEntity(propertyExpression);
1038 }
1039
1040 protected DataPropertyPointer toDataPropertyPointer(
1041 OWLDataPropertyExpression propertyExpression) {
1042 return dataPropertyTranslator.getPointerFromEntity(propertyExpression
1043 .asOWLDataProperty());
1044 }
1045
1046 protected synchronized IndividualPointer toIndividualPointer(
1047 OWLIndividual individual) {
1048 if (!individual.isAnonymous()) {
1049 return individualTranslator.getPointerFromEntity(individual
1050 .asOWLNamedIndividual());
1051 } else {
1052 return kernel.getIndividual(individual.toStringID());
1053 }
1054 }
1055
1056 protected synchronized DataTypePointer toDataTypePointer(
1057 OWLDatatype datatype) {
1058 if (datatype == null) {
1059 throw new IllegalArgumentException("datatype cannot be null");
1060 }
1061 String name = checkDateTime(datatype);
1062 return kernel.getBuiltInDataType(name);
1063 }
1064
1065 protected static final String checkDateTime(OWLDatatype datatype) {
1066 String name = datatype.toStringID();
1067 if (datatype.isBuiltIn()) {
1068 OWL2Datatype builtInDatatype = datatype.getBuiltInDatatype();
1069 OWL2Datatype xsdDateTime = OWL2Datatype.XSD_DATE_TIME;
1070 if (builtInDatatype == xsdDateTime) {
1071 name = name + "AsLong";
1072 }
1073 }
1074 return name;
1075 }
1076
1077 protected synchronized DataValuePointer toDataValuePointer(
1078 OWLLiteral literal) {
1079 String value = literal.getLiteral();
1080 if (literal.isRDFPlainLiteral()) {
1081 value = value + "@" + literal.getLang();
1082 }
1083 if (literal.getDatatype().isBuiltIn()
1084 && literal.getDatatype().getBuiltInDatatype() == OWL2Datatype.XSD_DATE_TIME) {
1085 return kernel.getDataValue(convertToLongDateTime(value),
1086 toDataTypePointer(literal.getDatatype()));
1087 }
1088 return kernel.getDataValue(value,
1089 toDataTypePointer(literal.getDatatype()));
1090 }
1091
1092 private static final String convertToLongDateTime(String input) {
1093 XMLGregorianCalendar calendar;
1094 try {
1095 calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(
1096 input);
1097 if (calendar.getTimezone() == DatatypeConstants.FIELD_UNDEFINED) {
1098 // set it to 0 (UTC) in this case; not perfect but avoids
1099 // indeterminate situations where two datetime literals cannot
1100 // be compared
1101 calendar.setTimezone(0);
1102 }
1103 long l = calendar.toGregorianCalendar().getTimeInMillis();
1104 // System.out.println("FaCTPlusPlusReasoner.convertToLongDateTime()\n"
1105 // + input + "\n" + Long.toString(l));
1106 return Long.toString(l);
1107 } catch (DatatypeConfigurationException e) {
1108 throw new OWLRuntimeException(
1109 "Error: the datatype support in the Java VM is broken! Cannot parse: "
1110 + input, e);
1111 }
1112 }
1113
1114 private NodeSet<OWLNamedIndividual> translateIndividualPointersToNodeSet(
1115 IndividualPointer[] pointers) {
1116 OWLNamedIndividualNodeSet ns = new OWLNamedIndividualNodeSet();
1117 for (IndividualPointer pointer : pointers) {
1118 if (pointer != null) {
1119 OWLNamedIndividual ind = individualTranslator
1120 .getEntityFromPointer(pointer);
1121 // XXX skipping anonymous individuals - counterintuitive but
1122 // that's the specs for you
1123 if (ind != null) {
1124 ns.addEntity(ind);
1125 }
1126 }
1127 }
1128 return ns;
1129 }
1130
1131 protected synchronized void translateIndividualSet(Set<OWLIndividual> inds) {
1132 kernel.initArgList();
1133 for (OWLIndividual ind : inds) {
1134 IndividualPointer ip = toIndividualPointer(ind);
1135 kernel.addArg(ip);
1136 }
1137 kernel.closeArgList();
1138 }
1139
1140 private class ClassExpressionTranslator extends
1141 OWLEntityTranslator<OWLClass, ClassPointer> implements
1142 OWLClassExpressionVisitorEx<ClassPointer> {
1143
1144 public ClassExpressionTranslator() {}
1145
1146 @Override
1147 protected ClassPointer getTopEntityPointer() {
1148 return kernel.getThing();
1149 }
1150
1151 @Override
1152 protected ClassPointer getBottomEntityPointer() {
1153 return kernel.getNothing();
1154 }
1155
1156 @Override
1157 protected OWLClass getTopEntity() {
1158 return getOWLDataFactory().getOWLThing();
1159 }
1160
1161 @Override
1162 protected OWLClass getBottomEntity() {
1163 return getOWLDataFactory().getOWLNothing();
1164 }
1165
1166 @Override
1167 protected ClassPointer createPointerForEntity(OWLClass entity) {
1168 return kernel.getNamedClass(entity.toStringID());
1169 }
1170
1171 @Override
1172 protected DefaultNode<OWLClass> createDefaultNode() {
1173 return new OWLClassNode();
1174 }
1175
1176 @Override
1177 protected DefaultNodeSet<OWLClass> createDefaultNodeSet() {
1178 return new OWLClassNodeSet();
1179 }
1180
1181 @Override
1182 public ClassPointer visit(OWLClass desc) {
1183 return getPointerFromEntity(desc);
1184 }
1185
1186 @Override
1187 public ClassPointer visit(OWLObjectIntersectionOf desc) {
1188 translateClassExpressionSet(desc.getOperands());
1189 return kernel.getConceptAnd();
1190 }
1191
1192 private void translateClassExpressionSet(
1193 Set<OWLClassExpression> classExpressions) {
1194 kernel.initArgList();
1195 for (OWLClassExpression ce : classExpressions) {
1196 ClassPointer cp = ce.accept(this);
1197 kernel.addArg(cp);
1198 }
1199 kernel.closeArgList();
1200 }
1201
1202 @Override
1203 public ClassPointer visit(OWLObjectUnionOf desc) {
1204 translateClassExpressionSet(desc.getOperands());
1205 return kernel.getConceptOr();
1206 }
1207
1208 @Override
1209 public ClassPointer visit(OWLObjectComplementOf desc) {
1210 return kernel.getConceptNot(desc.getOperand().accept(this));
1211 }
1212
1213 @Override
1214 public ClassPointer visit(OWLObjectSomeValuesFrom desc) {
1215 return kernel.getObjectSome(toObjectPropertyPointer(desc
1216 .getProperty()), desc.getFiller().accept(this));
1217 }
1218
1219 @Override
1220 public ClassPointer visit(OWLObjectAllValuesFrom desc) {
1221 return kernel.getObjectAll(toObjectPropertyPointer(desc
1222 .getProperty()), desc.getFiller().accept(this));
1223 }
1224
1225 @Override
1226 public ClassPointer visit(OWLObjectHasValue desc) {
1227 return kernel.getObjectValue(
1228 toObjectPropertyPointer(desc.getProperty()),
1229 toIndividualPointer(desc.getFiller()));
1230 }
1231
1232 @Override
1233 public ClassPointer visit(OWLObjectMinCardinality desc) {
1234 return kernel.getObjectAtLeast(desc.getCardinality(),
1235 toObjectPropertyPointer(desc.getProperty()), desc
1236 .getFiller().accept(this));
1237 }
1238
1239 @Override
1240 public ClassPointer visit(OWLObjectExactCardinality desc) {
1241 return kernel.getObjectExact(desc.getCardinality(),
1242 toObjectPropertyPointer(desc.getProperty()), desc
1243 .getFiller().accept(this));
1244 }
1245
1246 @Override
1247 public ClassPointer visit(OWLObjectMaxCardinality desc) {
1248 return kernel.getObjectAtMost(desc.getCardinality(),
1249 toObjectPropertyPointer(desc.getProperty()), desc
1250 .getFiller().accept(this));
1251 }
1252
1253 @Override
1254 public ClassPointer visit(OWLObjectHasSelf desc) {
1255 return kernel.getSelf(toObjectPropertyPointer(desc.getProperty()));
1256 }
1257
1258 @Override
1259 public ClassPointer visit(OWLObjectOneOf desc) {
1260 translateIndividualSet(desc.getIndividuals());
1261 return kernel.getOneOf();
1262 }
1263
1264 @Override
1265 public ClassPointer visit(OWLDataSomeValuesFrom desc) {
1266 return kernel.getDataSome(
1267 toDataPropertyPointer(desc.getProperty()),
1268 toDataTypeExpressionPointer(desc.getFiller()));
1269 }
1270
1271 @Override
1272 public ClassPointer visit(OWLDataAllValuesFrom desc) {
1273 return kernel.getDataAll(toDataPropertyPointer(desc.getProperty()),
1274 toDataTypeExpressionPointer(desc.getFiller()));
1275 }
1276
1277 @Override
1278 public ClassPointer visit(OWLDataHasValue desc) {
1279 return kernel.getDataValue(
1280 toDataPropertyPointer(desc.getProperty()),
1281 toDataValuePointer(desc.getFiller()));
1282 }
1283
1284 @Override
1285 public ClassPointer visit(OWLDataMinCardinality desc) {
1286 return kernel.getDataAtLeast(desc.getCardinality(),
1287 toDataPropertyPointer(desc.getProperty()),
1288 toDataTypeExpressionPointer(desc.getFiller()));
1289 }
1290
1291 @Override
1292 public ClassPointer visit(OWLDataExactCardinality desc) {
1293 return kernel.getDataExact(desc.getCardinality(),
1294 toDataPropertyPointer(desc.getProperty()),
1295 toDataTypeExpressionPointer(desc.getFiller()));
1296 }
1297
1298 @Override
1299 public ClassPointer visit(OWLDataMaxCardinality desc) {
1300 return kernel.getDataAtMost(desc.getCardinality(),
1301 toDataPropertyPointer(desc.getProperty()),
1302 toDataTypeExpressionPointer(desc.getFiller()));
1303 }
1304 }
1305
1306 private class DataRangeTranslator extends
1307 OWLEntityTranslator<OWLDatatype, DataTypePointer> implements
1308 OWLDataRangeVisitorEx<DataTypeExpressionPointer> {
1309
1310 public DataRangeTranslator() {}
1311
1312 @Override
1313 protected DataTypePointer getTopEntityPointer() {
1314 return kernel.getDataTop();
1315 }
1316
1317 @Override
1318 protected DataTypePointer getBottomEntityPointer() {
1319 return null;
1320 }
1321
1322 @Override
1323 protected DefaultNode<OWLDatatype> createDefaultNode() {
1324 return new OWLDatatypeNode();
1325 }
1326
1327 @Override
1328 protected OWLDatatype getTopEntity() {
1329 return getOWLDataFactory().getTopDatatype();
1330 }
1331
1332 @Override
1333 protected OWLDatatype getBottomEntity() {
1334 return null;
1335 }
1336
1337 @Override
1338 protected DefaultNodeSet<OWLDatatype> createDefaultNodeSet() {
1339 return new OWLDatatypeNodeSet();
1340 }
1341
1342 @Override
1343 protected DataTypePointer createPointerForEntity(OWLDatatype entity) {
1344 return kernel.getBuiltInDataType(checkDateTime(entity));
1345 }
1346
1347 @Override
1348 public DataTypeExpressionPointer visit(OWLDatatype node) {
1349 return kernel.getBuiltInDataType(checkDateTime(node));
1350 }
1351
1352 @Override
1353 public DataTypeExpressionPointer visit(OWLDataOneOf node) {
1354 kernel.initArgList();
1355 for (OWLLiteral literal : node.getValues()) {
1356 DataValuePointer dvp = toDataValuePointer(literal);
1357 kernel.addArg(dvp);
1358 }
1359 kernel.closeArgList();
1360 return kernel.getDataEnumeration();
1361 }
1362
1363 @Override
1364 public DataTypeExpressionPointer visit(OWLDataComplementOf node) {
1365 return kernel.getDataNot(node.getDataRange().accept(this));
1366 }
1367
1368 @Override
1369 public DataTypeExpressionPointer visit(OWLDataIntersectionOf node) {
1370 translateDataRangeSet(node.getOperands());
1371 return kernel.getDataIntersectionOf();
1372 }
1373
1374 private void translateDataRangeSet(Set<OWLDataRange> dataRanges) {
1375 kernel.initArgList();
1376 for (OWLDataRange op : dataRanges) {
1377 DataTypeExpressionPointer dtp = op.accept(this);
1378 kernel.addArg(dtp);
1379 }
1380 kernel.closeArgList();
1381 }
1382
1383 @Override
1384 public DataTypeExpressionPointer visit(OWLDataUnionOf node) {
1385 translateDataRangeSet(node.getOperands());
1386 return kernel.getDataUnionOf();
1387 }
1388
1389 @Override
1390 public DataTypeExpressionPointer visit(OWLDatatypeRestriction node) {
1391 DataTypeExpressionPointer dte = node.getDatatype().accept(this);
1392 for (OWLFacetRestriction restriction : node.getFacetRestrictions()) {
1393 DataValuePointer dv = toDataValuePointer(restriction
1394 .getFacetValue());
1395 DataTypeFacet facet;
1396 if (restriction.getFacet().equals(OWLFacet.MIN_INCLUSIVE)) {
1397 facet = kernel.getMinInclusiveFacet(dv);
1398 } else if (restriction.getFacet()
1399 .equals(OWLFacet.MAX_INCLUSIVE)) {
1400 facet = kernel.getMaxInclusiveFacet(dv);
1401 } else if (restriction.getFacet()
1402 .equals(OWLFacet.MIN_EXCLUSIVE)) {
1403 facet = kernel.getMinExclusiveFacet(dv);
1404 } else if (restriction.getFacet()
1405 .equals(OWLFacet.MAX_EXCLUSIVE)) {
1406 facet = kernel.getMaxExclusiveFacet(dv);
1407 } else if (restriction.getFacet().equals(OWLFacet.LENGTH)) {
1408 facet = kernel.getLength(dv);
1409 } else if (restriction.getFacet().equals(OWLFacet.MIN_LENGTH)) {
1410 facet = kernel.getMinLength(dv);
1411 } else if (restriction.getFacet().equals(OWLFacet.MAX_LENGTH)) {
1412 facet = kernel.getMaxLength(dv);
1413 } else if (restriction.getFacet().equals(
1414 OWLFacet.FRACTION_DIGITS)) {
1415 facet = kernel.getFractionDigitsFacet(dv);
1416 } else if (restriction.getFacet().equals(OWLFacet.PATTERN)) {
1417 facet = kernel.getPattern(dv);
1418 } else if (restriction.getFacet().equals(OWLFacet.TOTAL_DIGITS)) {
1419 facet = kernel.getTotalDigitsFacet(dv);
1420 } else {
1421 throw new OWLRuntimeException("Unsupported facet: "
1422 + restriction.getFacet());
1423 }
1424 dte = kernel.getRestrictedDataType(dte, facet);
1425 }
1426 return dte;
1427 }
1428 }
1429
1430 private class IndividualTranslator extends
1431 OWLEntityTranslator<OWLNamedIndividual, IndividualPointer> {
1432
1433 public IndividualTranslator() {}
1434
1435 @Override
1436 protected IndividualPointer getTopEntityPointer() {
1437 return null;
1438 }
1439
1440 @Override
1441 protected IndividualPointer getBottomEntityPointer() {
1442 return null;
1443 }
1444
1445 @Override
1446 protected IndividualPointer createPointerForEntity(
1447 OWLNamedIndividual entity) {
1448 return kernel.getIndividual(entity.toStringID());
1449 }
1450
1451 @Override
1452 protected OWLNamedIndividual getTopEntity() {
1453 return null;
1454 }
1455
1456 @Override
1457 protected OWLNamedIndividual getBottomEntity() {
1458 return null;
1459 }
1460
1461 @Override
1462 protected DefaultNode<OWLNamedIndividual> createDefaultNode() {
1463 return new OWLNamedIndividualNode();
1464 }
1465
1466 @Override
1467 protected DefaultNodeSet<OWLNamedIndividual> createDefaultNodeSet() {
1468 return new OWLNamedIndividualNodeSet();
1469 }
1470 }
1471
1472 private class ObjectPropertyTranslator
1473 extends
1474 OWLEntityTranslator<OWLObjectPropertyExpression, ObjectPropertyPointer> {
1475
1476 public ObjectPropertyTranslator() {}
1477
1478 @Override
1479 protected ObjectPropertyPointer getTopEntityPointer() {
1480 return kernel.getTopObjectProperty();
1481 }
1482
1483 @Override
1484 protected ObjectPropertyPointer getBottomEntityPointer() {
1485 return kernel.getBottomObjectProperty();
1486 }
1487
1488 @Override
1489 protected ObjectPropertyPointer registerNewEntity(
1490 OWLObjectPropertyExpression entity) {
1491 ObjectPropertyPointer pointer = createPointerForEntity(entity);
1492 fillEntityPointerMaps(entity, pointer);
1493 entity = entity.getInverseProperty();
1494 fillEntityPointerMaps(entity, createPointerForEntity(entity));
1495 return pointer;
1496 }
1497
1498 @Override
1499 protected ObjectPropertyPointer createPointerForEntity(
1500 OWLObjectPropertyExpression entity) {
1501 ObjectPropertyPointer p = kernel.getObjectProperty(entity
1502 .getNamedProperty().toStringID());
1503 if (entity.isAnonymous()) {
1504 p = kernel.getInverseProperty(p);
1505 }
1506 return p;
1507 }
1508
1509 @Override
1510 protected OWLObjectProperty getTopEntity() {
1511 return getOWLDataFactory().getOWLTopObjectProperty();
1512 }
1513
1514 @Override
1515 protected OWLObjectProperty getBottomEntity() {
1516 return getOWLDataFactory().getOWLBottomObjectProperty();
1517 }
1518
1519 @Override
1520 protected DefaultNode<OWLObjectPropertyExpression> createDefaultNode() {
1521 return new OWLObjectPropertyNode();
1522 }
1523
1524 @Override
1525 protected DefaultNodeSet<OWLObjectPropertyExpression>
1526 createDefaultNodeSet() {
1527 return new OWLObjectPropertyNodeSet();
1528 }
1529 }
1530
1531 private class DataPropertyTranslator extends
1532 OWLEntityTranslator<OWLDataProperty, DataPropertyPointer> {
1533
1534 public DataPropertyTranslator() {}
1535
1536 @Override
1537 protected DataPropertyPointer getTopEntityPointer() {
1538 return kernel.getTopDataProperty();
1539 }
1540
1541 @Override
1542 protected DataPropertyPointer getBottomEntityPointer() {
1543 return kernel.getBottomDataProperty();
1544 }
1545
1546 @Override
1547 protected DataPropertyPointer createPointerForEntity(
1548 OWLDataProperty entity) {
1549 return kernel.getDataProperty(entity.toStringID());
1550 }
1551
1552 @Override
1553 protected OWLDataProperty getTopEntity() {
1554 return getOWLDataFactory().getOWLTopDataProperty();
1555 }
1556
1557 @Override
1558 protected OWLDataProperty getBottomEntity() {
1559 return getOWLDataFactory().getOWLBottomDataProperty();
1560 }
1561
1562 @Override
1563 protected DefaultNode<OWLDataProperty> createDefaultNode() {
1564 return new OWLDataPropertyNode();
1565 }
1566
1567 @Override
1568 protected DefaultNodeSet<OWLDataProperty> createDefaultNodeSet() {
1569 return new OWLDataPropertyNodeSet();
1570 }
1571 }
1572
1573 private class AxiomTranslator implements OWLAxiomVisitorEx<AxiomPointer> {
1574
1575 private final class DeclarationVisitorEx implements
1576 OWLEntityVisitorEx<AxiomPointer> {
1577
1578 public DeclarationVisitorEx() {}
1579
1580 @Override
1581 public AxiomPointer visit(OWLClass cls) {
1582 return kernel.tellClassDeclaration(toClassPointer(cls));
1583 }
1584
1585 @Override
1586 public AxiomPointer visit(OWLObjectProperty property) {
1587 return kernel
1588 .tellObjectPropertyDeclaration(toObjectPropertyPointer(property));
1589 }
1590
1591 @Override
1592 public AxiomPointer visit(OWLDataProperty property) {
1593 return kernel
1594 .tellDataPropertyDeclaration(toDataPropertyPointer(property));
1595 }
1596
1597 @Override
1598 public AxiomPointer visit(OWLNamedIndividual individual) {
1599 return kernel
1600 .tellIndividualDeclaration(toIndividualPointer(individual));
1601 }
1602
1603 @Override
1604 public AxiomPointer visit(OWLDatatype datatype) {
1605 return kernel
1606 .tellDatatypeDeclaration(toDataTypePointer(datatype));
1607 }
1608
1609 @Override
1610 public AxiomPointer visit(OWLAnnotationProperty property) {
1611 return null;
1612 }
1613 }
1614
1615 private final DeclarationVisitorEx v;
1616
1617 public AxiomTranslator() {
1618 v = new DeclarationVisitorEx();
1619 }
1620
1621 @Override
1622 public AxiomPointer visit(OWLSubClassOfAxiom axiom) {
1623 return kernel.tellSubClassOf(toClassPointer(axiom.getSubClass()),
1624 toClassPointer(axiom.getSuperClass()));
1625 }
1626
1627 @Override
1628 public AxiomPointer
1629 visit(OWLNegativeObjectPropertyAssertionAxiom axiom) {
1630 return kernel.tellNotRelatedIndividuals(
1631 toIndividualPointer(axiom.getSubject()),
1632 toObjectPropertyPointer(axiom.getProperty()),
1633 toIndividualPointer(axiom.getObject()));
1634 }
1635
1636 @Override
1637 public AxiomPointer visit(OWLAsymmetricObjectPropertyAxiom axiom) {
1638 return kernel
1639 .tellAsymmetricObjectProperty(toObjectPropertyPointer(axiom
1640 .getProperty()));
1641 }
1642
1643 @Override
1644 public AxiomPointer visit(OWLReflexiveObjectPropertyAxiom axiom) {
1645 return kernel
1646 .tellReflexiveObjectProperty(toObjectPropertyPointer(axiom
1647 .getProperty()));
1648 }
1649
1650 @Override
1651 public AxiomPointer visit(OWLDisjointClassesAxiom axiom) {
1652 translateClassExpressionSet(axiom.getClassExpressions());
1653 return kernel.tellDisjointClasses();
1654 }
1655
1656 private void translateClassExpressionSet(
1657 Collection<OWLClassExpression> classExpressions) {
1658 kernel.initArgList();
1659 for (OWLClassExpression ce : classExpressions) {
1660 ClassPointer cp = toClassPointer(ce);
1661 kernel.addArg(cp);
1662 }
1663 kernel.closeArgList();
1664 }
1665
1666 @Override
1667 public AxiomPointer visit(OWLDataPropertyDomainAxiom axiom) {
1668 return kernel.tellDataPropertyDomain(
1669 toDataPropertyPointer(axiom.getProperty()),
1670 toClassPointer(axiom.getDomain()));
1671 }
1672
1673 @Override
1674 public AxiomPointer visit(OWLObjectPropertyDomainAxiom axiom) {
1675 return kernel.tellObjectPropertyDomain(
1676 toObjectPropertyPointer(axiom.getProperty()),
1677 toClassPointer(axiom.getDomain()));
1678 }
1679
1680 @Override
1681 public AxiomPointer visit(OWLEquivalentObjectPropertiesAxiom axiom) {
1682 translateObjectPropertySet(axiom.getProperties());
1683 return kernel.tellEquivalentObjectProperties();
1684 }
1685
1686 private void translateObjectPropertySet(
1687 Collection<OWLObjectPropertyExpression> properties) {
1688 kernel.initArgList();
1689 for (OWLObjectPropertyExpression property : properties) {
1690 ObjectPropertyPointer opp = toObjectPropertyPointer(property);
1691 kernel.addArg(opp);
1692 }
1693 kernel.closeArgList();
1694 }
1695
1696 @Override
1697 public AxiomPointer visit(OWLNegativeDataPropertyAssertionAxiom axiom) {
1698 return kernel.tellNotRelatedIndividualValue(
1699 toIndividualPointer(axiom.getSubject()),
1700 toDataPropertyPointer(axiom.getProperty()),
1701 toDataValuePointer(axiom.getObject()));
1702 }
1703
1704 @Override
1705 public AxiomPointer visit(OWLDifferentIndividualsAxiom axiom) {
1706 translateIndividualSet(axiom.getIndividuals());
1707 return kernel.tellDifferentIndividuals();
1708 }
1709
1710 @Override
1711 public AxiomPointer visit(OWLDisjointDataPropertiesAxiom axiom) {
1712 translateDataPropertySet(axiom.getProperties());
1713 return kernel.tellDisjointDataProperties();
1714 }
1715
1716 private void translateDataPropertySet(
1717 Set<OWLDataPropertyExpression> properties) {
1718 kernel.initArgList();
1719 for (OWLDataPropertyExpression property : properties) {
1720 DataPropertyPointer dpp = toDataPropertyPointer(property);
1721 kernel.addArg(dpp);
1722 }
1723 kernel.closeArgList();
1724 }
1725
1726 @Override
1727 public AxiomPointer visit(OWLDisjointObjectPropertiesAxiom axiom) {
1728 translateObjectPropertySet(axiom.getProperties());
1729 return kernel.tellDisjointObjectProperties();
1730 }
1731
1732 @Override
1733 public AxiomPointer visit(OWLObjectPropertyRangeAxiom axiom) {
1734 return kernel.tellObjectPropertyRange(
1735 toObjectPropertyPointer(axiom.getProperty()),
1736 toClassPointer(axiom.getRange()));
1737 }
1738
1739 @Override
1740 public AxiomPointer visit(OWLObjectPropertyAssertionAxiom axiom) {
1741 return kernel.tellRelatedIndividuals(
1742 toIndividualPointer(axiom.getSubject()),
1743 toObjectPropertyPointer(axiom.getProperty()),
1744 toIndividualPointer(axiom.getObject()));
1745 }
1746
1747 @Override
1748 public AxiomPointer visit(OWLFunctionalObjectPropertyAxiom axiom) {
1749 return kernel
1750 .tellFunctionalObjectProperty(toObjectPropertyPointer(axiom
1751 .getProperty()));
1752 }
1753
1754 @Override
1755 public AxiomPointer visit(OWLSubObjectPropertyOfAxiom axiom) {
1756 return kernel.tellSubObjectProperties(
1757 toObjectPropertyPointer(axiom.getSubProperty()),
1758 toObjectPropertyPointer(axiom.getSuperProperty()));
1759 }
1760
1761 @Override
1762 public AxiomPointer visit(OWLDisjointUnionAxiom axiom) {
1763 translateClassExpressionSet(axiom.getClassExpressions());
1764 return kernel
1765 .tellDisjointUnion(toClassPointer(axiom.getOWLClass()));
1766 }
1767
1768 @Override
1769 public AxiomPointer visit(OWLDeclarationAxiom axiom) {
1770 OWLEntity entity = axiom.getEntity();
1771 return entity.accept(v);
1772 }
1773
1774 @Override
1775 public AxiomPointer visit(OWLAnnotationAssertionAxiom axiom) {
1776 // Ignore
1777 return null;
1778 }
1779
1780 @Override
1781 public AxiomPointer visit(OWLSymmetricObjectPropertyAxiom axiom) {
1782 return kernel
1783 .tellSymmetricObjectProperty(toObjectPropertyPointer(axiom
1784 .getProperty()));
1785 }
1786
1787 @Override
1788 public AxiomPointer visit(OWLDataPropertyRangeAxiom axiom) {
1789 return kernel.tellDataPropertyRange(
1790 toDataPropertyPointer(axiom.getProperty()),
1791 toDataTypeExpressionPointer(axiom.getRange()));
1792 }
1793
1794 @Override
1795 public AxiomPointer visit(OWLFunctionalDataPropertyAxiom axiom) {
1796 return kernel
1797 .tellFunctionalDataProperty(toDataPropertyPointer(axiom
1798 .getProperty()));
1799 }
1800
1801 @Override
1802 public AxiomPointer visit(OWLEquivalentDataPropertiesAxiom axiom) {
1803 translateDataPropertySet(axiom.getProperties());
1804 return kernel.tellEquivalentDataProperties();
1805 }
1806
1807 @Override
1808 public AxiomPointer visit(OWLClassAssertionAxiom axiom) {
1809 return kernel.tellIndividualType(
1810 toIndividualPointer(axiom.getIndividual()),
1811 toClassPointer(axiom.getClassExpression()));
1812 }
1813
1814 @Override
1815 public AxiomPointer visit(OWLEquivalentClassesAxiom axiom) {
1816 translateClassExpressionSet(axiom.getClassExpressions());
1817 return kernel.tellEquivalentClass();
1818 }
1819
1820 @Override
1821 public AxiomPointer visit(OWLDataPropertyAssertionAxiom axiom) {
1822 return kernel.tellRelatedIndividualValue(
1823 toIndividualPointer(axiom.getSubject()),
1824 toDataPropertyPointer(axiom.getProperty()),
1825 toDataValuePointer(axiom.getObject()));
1826 }
1827
1828 @Override
1829 public AxiomPointer visit(OWLTransitiveObjectPropertyAxiom axiom) {
1830 return kernel
1831 .tellTransitiveObjectProperty(toObjectPropertyPointer(axiom
1832 .getProperty()));
1833 }
1834
1835 @Override
1836 public AxiomPointer visit(OWLIrreflexiveObjectPropertyAxiom axiom) {
1837 return kernel
1838 .tellIrreflexiveObjectProperty(toObjectPropertyPointer(axiom
1839 .getProperty()));
1840 }
1841
1842 @Override
1843 public AxiomPointer visit(OWLSubDataPropertyOfAxiom axiom) {
1844 return kernel.tellSubDataProperties(
1845 toDataPropertyPointer(axiom.getSubProperty()),
1846 toDataPropertyPointer(axiom.getSuperProperty()));
1847 }
1848
1849 @Override
1850 public AxiomPointer
1851 visit(OWLInverseFunctionalObjectPropertyAxiom axiom) {
1852 return kernel
1853 .tellInverseFunctionalObjectProperty(toObjectPropertyPointer(axiom
1854 .getProperty()));
1855 }
1856
1857 @Override
1858 public AxiomPointer visit(OWLSameIndividualAxiom axiom) {
1859 translateIndividualSet(axiom.getIndividuals());
1860 return kernel.tellSameIndividuals();
1861 }
1862
1863 @Override
1864 public AxiomPointer visit(OWLSubPropertyChainOfAxiom axiom) {
1865 translateObjectPropertySet(axiom.getPropertyChain());
1866 return kernel.tellSubObjectProperties(
1867 kernel.getPropertyComposition(),
1868 toObjectPropertyPointer(axiom.getSuperProperty()));
1869 }
1870
1871 @Override
1872 public AxiomPointer visit(OWLInverseObjectPropertiesAxiom axiom) {
1873 return kernel.tellInverseProperties(
1874 toObjectPropertyPointer(axiom.getFirstProperty()),
1875 toObjectPropertyPointer(axiom.getSecondProperty()));
1876 }
1877
1878 @Override
1879 public AxiomPointer visit(OWLHasKeyAxiom axiom) {
1880 translateObjectPropertySet(axiom.getObjectPropertyExpressions());
1881 ObjectPropertyPointer objectPropertyPointer = kernel
1882 .getObjectPropertyKey();
1883 translateDataPropertySet(axiom.getDataPropertyExpressions());
1884 DataPropertyPointer dataPropertyPointer = kernel
1885 .getDataPropertyKey();
1886 return kernel.tellHasKey(
1887 toClassPointer(axiom.getClassExpression()),
1888 dataPropertyPointer, objectPropertyPointer);
1889 }
1890
1891 @Override
1892 public AxiomPointer visit(OWLDatatypeDefinitionAxiom axiom) {
1893 kernel.getDataSubType(axiom.getDatatype().getIRI().toString(),
1894 toDataTypeExpressionPointer(axiom.getDataRange()));
1895 return null;
1896 }
1897
1898 @Override
1899 public AxiomPointer visit(SWRLRule rule) {
1900 // Ignore
1901 return null;
1902 }
1903
1904 @Override
1905 public AxiomPointer visit(OWLSubAnnotationPropertyOfAxiom axiom) {
1906 // Ignore
1907 return null;
1908 }
1909
1910 @Override
1911 public AxiomPointer visit(OWLAnnotationPropertyDomainAxiom axiom) {
1912 // Ignore
1913 return null;
1914 }
1915
1916 @Override
1917 public AxiomPointer visit(OWLAnnotationPropertyRangeAxiom axiom) {
1918 // Ignore
1919 return null;
1920 }
1921 }
1922
1923 private class EntailmentChecker implements OWLAxiomVisitorEx<Boolean> {
1924
1925 public EntailmentChecker() {}
1926
1927 @Override
1928 public Boolean visit(OWLSubClassOfAxiom axiom) {
1929 if (axiom.getSuperClass().equals(getOWLDataFactory().getOWLThing())) {
1930 return true;
1931 }
1932 if (axiom.getSubClass().equals(getOWLDataFactory().getOWLNothing())) {
1933 return true;
1934 }
1935 return kernel.isClassSubsumedBy(
1936 toClassPointer(axiom.getSubClass()),
1937 toClassPointer(axiom.getSuperClass()));
1938 }
1939
1940 @Override
1941 public Boolean visit(OWLNegativeObjectPropertyAssertionAxiom axiom) {
1942 return axiom.asOWLSubClassOfAxiom().accept(this);
1943 }
1944
1945 @Override
1946 public Boolean visit(OWLAsymmetricObjectPropertyAxiom axiom) {
1947 return kernel
1948 .isObjectPropertyAsymmetric(toObjectPropertyPointer(axiom
1949 .getProperty()));
1950 }
1951
1952 @Override
1953 public Boolean visit(OWLReflexiveObjectPropertyAxiom axiom) {
1954 return kernel
1955 .isObjectPropertyReflexive(toObjectPropertyPointer(axiom
1956 .getProperty()));
1957 }
1958
1959 @Override
1960 public Boolean visit(OWLDisjointClassesAxiom axiom) {
1961 Set<OWLClassExpression> classExpressions = axiom
1962 .getClassExpressions();
1963 if (classExpressions.size() == 2) {
1964 Iterator<OWLClassExpression> it = classExpressions.iterator();
1965 return kernel.isClassDisjointWith(toClassPointer(it.next()),
1966 toClassPointer(it.next()));
1967 } else {
1968 for (OWLAxiom ax : axiom.asOWLSubClassOfAxioms()) {
1969 if (!ax.accept(this)) {
1970 return false;
1971 }
1972 }
1973 return true;
1974 }
1975 }
1976
1977 @Override
1978 public Boolean visit(OWLDataPropertyDomainAxiom axiom) {
1979 return axiom.asOWLSubClassOfAxiom().accept(this);
1980 }
1981
1982 @Override
1983 public Boolean visit(OWLObjectPropertyDomainAxiom axiom) {
1984 return axiom.asOWLSubClassOfAxiom().accept(this);
1985 }
1986
1987 @Override
1988 public Boolean visit(OWLEquivalentObjectPropertiesAxiom axiom) {
1989 for (OWLAxiom ax : axiom.asSubObjectPropertyOfAxioms()) {
1990 if (!ax.accept(this)) {
1991 return false;
1992 }
1993 }
1994 return true;
1995 }
1996
1997 @Override
1998 public Boolean visit(OWLNegativeDataPropertyAssertionAxiom axiom) {
1999 return axiom.asOWLSubClassOfAxiom().accept(this);
2000 }
2001
2002 @Override
2003 public Boolean visit(OWLDifferentIndividualsAxiom axiom) {
2004 for (OWLSubClassOfAxiom ax : axiom.asOWLSubClassOfAxioms()) {
2005 if (!ax.accept(this)) {
2006 return false;
2007 }
2008 }
2009 return true;
2010 }
2011
2012 // TODO: this check is incomplete
2013 @Override
2014 public Boolean visit(OWLDisjointDataPropertiesAxiom axiom) {
2015 kernel.initArgList();
2016 for (OWLDataPropertyExpression p : axiom.getProperties()) {
2017 kernel.addArg(toDataPropertyPointer(p));
2018 }
2019 kernel.closeArgList();
2020 return kernel.arePropertiesDisjoint();
2021 }
2022
2023 @Override
2024 public Boolean visit(OWLDisjointObjectPropertiesAxiom axiom) {
2025 kernel.initArgList();
2026 for (OWLObjectPropertyExpression p : axiom.getProperties()) {
2027 kernel.addArg(toObjectPropertyPointer(p));
2028 }
2029 kernel.closeArgList();
2030 return kernel.arePropertiesDisjoint();
2031 }
2032
2033 @Override
2034 public Boolean visit(OWLObjectPropertyRangeAxiom axiom) {
2035 return axiom.asOWLSubClassOfAxiom().accept(this);
2036 }
2037
2038 @Override
2039 public Boolean visit(OWLObjectPropertyAssertionAxiom axiom) {
2040 return axiom.asOWLSubClassOfAxiom().accept(this);
2041 }
2042
2043 @Override
2044 public Boolean visit(OWLFunctionalObjectPropertyAxiom axiom) {
2045 return kernel
2046 .isObjectPropertyFunctional(toObjectPropertyPointer(axiom
2047 .getProperty()));
2048 }
2049
2050 @Override
2051 public Boolean visit(OWLSubObjectPropertyOfAxiom axiom) {
2052 return kernel.isObjectSubPropertyOf(
2053 toObjectPropertyPointer(axiom.getSubProperty()),
2054 toObjectPropertyPointer(axiom.getSuperProperty()));
2055 }
2056
2057 @Override
2058 public Boolean visit(OWLDisjointUnionAxiom axiom) {
2059 return axiom.getOWLEquivalentClassesAxiom().accept(this)
2060 && axiom.getOWLDisjointClassesAxiom().accept(this);
2061 }
2062
2063 @Override
2064 public Boolean visit(OWLDeclarationAxiom axiom) {
2065 // TODO uhm might be needed?
2066 return false;
2067 }
2068
2069 @Override
2070 public Boolean visit(OWLAnnotationAssertionAxiom axiom) {
2071 return false;
2072 }
2073
2074 @Override
2075 public Boolean visit(OWLSymmetricObjectPropertyAxiom axiom) {
2076 return kernel
2077 .isObjectPropertySymmetric(toObjectPropertyPointer(axiom
2078 .getProperty()));
2079 }
2080
2081 @Override
2082 public Boolean visit(OWLDataPropertyRangeAxiom axiom) {
2083 return axiom.asOWLSubClassOfAxiom().accept(this);
2084 }
2085
2086 @Override
2087 public Boolean visit(OWLFunctionalDataPropertyAxiom axiom) {
2088 return kernel.isDataPropertyFunctional(toDataPropertyPointer(axiom
2089 .getProperty()));
2090 }
2091
2092 @Override
2093 public Boolean visit(OWLEquivalentDataPropertiesAxiom axiom) {
2094 // TODO check
2095 // this is not implemented in OWL API
2096 // for (OWLAxiom ax : axiom.asSubDataPropertyOfAxioms()) {
2097 // if (!ax.accept(this)) {
2098 // return false;
2099 // }
2100 // }
2101 // return true;
2102 return null;
2103 }
2104
2105 @Override
2106 public Boolean visit(OWLClassAssertionAxiom axiom) {
2107 return kernel.isInstanceOf(
2108 toIndividualPointer(axiom.getIndividual()),
2109 toClassPointer(axiom.getClassExpression()));
2110 }
2111
2112 @Override
2113 public Boolean visit(OWLEquivalentClassesAxiom axiom) {
2114 Set<OWLClassExpression> classExpressionSet = axiom
2115 .getClassExpressions();
2116 if (classExpressionSet.size() == 2) {
2117 Iterator<OWLClassExpression> it = classExpressionSet.iterator();
2118 return kernel.isClassEquivalentTo(toClassPointer(it.next()),
2119 toClassPointer(it.next()));
2120 } else {
2121 for (OWLAxiom ax : axiom.asOWLSubClassOfAxioms()) {
2122 if (!ax.accept(this)) {
2123 return false;
2124 }
2125 }
2126 return true;
2127 }
2128 }
2129
2130 @Override
2131 public Boolean visit(OWLDataPropertyAssertionAxiom axiom) {
2132 return axiom.asOWLSubClassOfAxiom().accept(this);
2133 }
2134
2135 @Override
2136 public Boolean visit(OWLTransitiveObjectPropertyAxiom axiom) {
2137 return kernel
2138 .isObjectPropertyTransitive(toObjectPropertyPointer(axiom
2139 .getProperty()));
2140 }
2141
2142 @Override
2143 public Boolean visit(OWLIrreflexiveObjectPropertyAxiom axiom) {
2144 return kernel
2145 .isObjectPropertyIrreflexive(toObjectPropertyPointer(axiom
2146 .getProperty()));
2147 }
2148
2149 // TODO: this is incomplete
2150 @Override
2151 public Boolean visit(OWLSubDataPropertyOfAxiom axiom) {
2152 return kernel.isDataSubPropertyOf(
2153 toDataPropertyPointer(axiom.getSubProperty()),
2154 toDataPropertyPointer(axiom.getSuperProperty()));
2155 }
2156
2157 @Override
2158 public Boolean visit(OWLInverseFunctionalObjectPropertyAxiom axiom) {
2159 return kernel
2160 .isObjectPropertyInverseFunctional(toObjectPropertyPointer(axiom
2161 .getProperty()));
2162 }
2163
2164 @Override
2165 public Boolean visit(OWLSameIndividualAxiom axiom) {
2166 for (OWLSameIndividualAxiom ax : axiom.asPairwiseAxioms()) {
2167 Iterator<OWLIndividual> it = ax.getIndividuals().iterator();
2168 OWLIndividual indA = it.next();
2169 OWLIndividual indB = it.next();
2170 if (!kernel.isSameAs(toIndividualPointer(indA),
2171 toIndividualPointer(indB))) {
2172 return false;
2173 }
2174 }
2175 return true;
2176 }
2177
2178 @Override
2179 public Boolean visit(OWLSubPropertyChainOfAxiom axiom) {
2180 kernel.initArgList();
2181 for (OWLObjectPropertyExpression p : axiom.getPropertyChain()) {
2182 kernel.addArg(toObjectPropertyPointer(p));
2183 }
2184 kernel.closeArgList();
2185 return kernel.isSubPropertyChainOf(toObjectPropertyPointer(axiom
2186 .getSuperProperty()));
2187 }
2188
2189 @Override
2190 public Boolean visit(OWLInverseObjectPropertiesAxiom axiom) {
2191 for (OWLAxiom ax : axiom.asSubObjectPropertyOfAxioms()) {
2192 if (!ax.accept(this)) {
2193 return false;
2194 }
2195 }
2196 return true;
2197 }
2198
2199 @Override
2200 public Boolean visit(OWLHasKeyAxiom axiom) {
2201 // FIXME!! unsupported by FaCT++ ATM
2202 return null;
2203 }
2204
2205 @Override
2206 public Boolean visit(OWLDatatypeDefinitionAxiom axiom) {
2207 // FIXME!! unsupported by FaCT++ ATM
2208 return null;
2209 }
2210
2211 @Override
2212 public Boolean visit(SWRLRule rule) {
2213 // FIXME!! unsupported by FaCT++ ATM
2214 return null;
2215 }
2216
2217 @Override
2218 public Boolean visit(OWLSubAnnotationPropertyOfAxiom axiom) {
2219 return false;
2220 }
2221
2222 @Override
2223 public Boolean visit(OWLAnnotationPropertyDomainAxiom axiom) {
2224 return false;
2225 }
2226
2227 @Override
2228 public Boolean visit(OWLAnnotationPropertyRangeAxiom axiom) {
2229 return false;
2230 }
2231 }
2232
2233 @Override
2234 public synchronized void dispose() {
2235 manager.removeOntologyChangeListener(this);
2236 axiomTranslator = null;
2237 classExpressionTranslator = null;
2238 dataRangeTranslator = null;
2239 objectPropertyTranslator = null;
2240 dataPropertyTranslator = null;
2241 individualTranslator = null;
2242 entailmentChecker = null;
2243 axiom2PtrMap.clear();
2244 ptr2AxiomMap.clear();
2245 rawChanges.clear();
2246 reasonerAxioms.clear();
2247 kernel.dispose();
2248 }
2249
2250 private static class ProgressMonitorAdapter implements
2251 FaCTPlusPlusProgressMonitor {
2252
2253 private int count = 0;
2254 private int total = 0;
2255 private final ReasonerProgressMonitor progressMonitor;
2256 private final AtomicBoolean interrupted;
2257
2258 public ProgressMonitorAdapter(ReasonerProgressMonitor p,
2259 AtomicBoolean interr) {
2260 progressMonitor = p;
2261 interrupted = interr;
2262 }
2263
2264 @Override
2265 public void setClassificationStarted(int classCount) {
2266 count = 0;
2267 total = classCount;
2268 progressMonitor
2269 .reasonerTaskStarted(ReasonerProgressMonitor.CLASSIFYING);
2270 progressMonitor.reasonerTaskProgressChanged(count, classCount);
2271 }
2272
2273 @Override
2274 public void nextClass() {
2275 count++;
2276 progressMonitor.reasonerTaskProgressChanged(count, total);
2277 }
2278
2279 @Override
2280 public void setFinished() {
2281 progressMonitor.reasonerTaskStopped();
2282 }
2283
2284 @Override
2285 public boolean isCancelled() {
2286 if (interrupted.get()) {
2287 throw new ReasonerInterruptedException();
2288 }
2289 return false;
2290 }
2291 }
2292
2293 /**
2294 * @param pw
2295 * printstream
2296 * @param includeBottomNode
2297 * true if bottom node included
2298 */
2299 public void dumpClassHierarchy(PrintStream pw, boolean includeBottomNode) {
2300 dumpSubClasses(getTopClassNode(), pw, 0, includeBottomNode);
2301 }
2302
2303 private void dumpSubClasses(Node<OWLClass> node, PrintStream pw, int depth,
2304 boolean includeBottomNode) {
2305 if (includeBottomNode || !node.isBottomNode()) {
2306 for (int i = 0; i < depth; i++) {
2307 pw.print(" ");
2308 }
2309 pw.println(node);
2310 for (Node<OWLClass> sub : getSubClasses(
2311 node.getRepresentativeElement(), true)) {
2312 dumpSubClasses(sub, pw, depth + 1, includeBottomNode);
2313 }
2314 }
2315 }
2316
2317 /**
2318 * @param expression
2319 * expression to find
2320 * @return root node for expression
2321 */
2322 public NodePointer getRoot(OWLClassExpression expression) {
2323 return kernel.buildCompletionTree(toClassPointer(expression));
2324 }
2325
2326 /**
2327 * @param object
2328 * object to check
2329 * @param deterministicOnly
2330 * true if deterministic only
2331 * @return neighbors
2332 */
2333 public Node<? extends OWLObjectPropertyExpression> getObjectNeighbours(
2334 NodePointer object, boolean deterministicOnly) {
2335 return objectPropertyTranslator.getNodeFromPointers(kernel
2336 .getObjectNeighbours(object, deterministicOnly));
2337 }
2338
2339 /**
2340 * @param object
2341 * object to check
2342 * @param deterministicOnly
2343 * true if deterministic only
2344 * @return neighbors
2345 */
2346 public Node<OWLDataProperty> getDataNeighbours(NodePointer object,
2347 boolean deterministicOnly) {
2348 return dataPropertyTranslator.getNodeFromPointers(kernel
2349 .getDataNeighbours(object, deterministicOnly));
2350 }
2351
2352 /**
2353 * @param n
2354 * object to check
2355 * @param property
2356 * property to follow
2357 * @return neighbors
2358 */
2359 public Collection<NodePointer> getObjectNeighbours(NodePointer n,
2360 OWLObjectProperty property) {
2361 return Arrays.asList(kernel.getObjectNeighbours(n,
2362 toObjectPropertyPointer(property)));
2363 }
2364
2365 /**
2366 * @param n
2367 * object to check
2368 * @param property
2369 * property to follow
2370 * @return neighbors
2371 */
2372 public Collection<NodePointer> getDataNeighbours(NodePointer n,
2373 OWLDataProperty property) {
2374 return Arrays.asList(kernel.getDataNeighbours(n,
2375 toDataPropertyPointer(property)));
2376 }
2377
2378 /**
2379 * @param object
2380 * object to check
2381 * @param deterministicOnly
2382 * true if deterministic only
2383 * @return neighbors
2384 */
2385 public Node<? extends OWLClassExpression> getObjectLabel(
2386 NodePointer object, boolean deterministicOnly) {
2387 return classExpressionTranslator.getNodeFromPointers(kernel
2388 .getObjectLabel(object, deterministicOnly));
2389 }
2390
2391 /**
2392 * @param object
2393 * object to check
2394 * @param deterministicOnly
2395 * true if deterministic only
2396 * @return neighbors
2397 */
2398 public Node<? extends OWLDataRange> getDataLabel(NodePointer object,
2399 boolean deterministicOnly) {
2400 return dataRangeTranslator.getNodeFromPointers(kernel.getDataLabel(
2401 object, deterministicOnly));
2402 }
2403
2404 /**
2405 * @param object
2406 * node pointer
2407 * @return blocker for object
2408 */
2409 public NodePointer getBlocker(NodePointer object) {
2410 return kernel.getBlocker(object);
2411 }
2412
2413 /**
2414 * Translate OWLAPI enum for the type of module into the interface-friendly
2415 * int
2416 *
2417 * @param moduleType
2418 * module type
2419 * @return index
2420 */
2421 private static int getIndexByModuleType(ModuleType moduleType) {
2422 switch (moduleType) {
2423 case BOT:
2424 return 0;
2425 case TOP:
2426 return 1;
2427 case STAR:
2428 return 2;
2429 default:
2430 throw new ReasonerInternalException("Unsupported module type");
2431 }
2432 }
2433
2434 /**
2435 * Translate OWLAPI enum for the method of modularisation into the
2436 * interface-friendly int
2437 *
2438 * @param moduleMethod
2439 * module type
2440 * @return index
2441 */
2442 private static int getIndexByModuleMethod(ModuleMethod moduleMethod) {
2443 switch (moduleMethod) {
2444 case SYNTACTIC_STANDARD:
2445 return 0;
2446 case SYNTACTIC_COUNTING:
2447 return 1;
2448 case SEMANTIC:
2449 return 2;
2450 default:
2451 throw new ReasonerInternalException("Unsupported module method");
2452 }
2453 }
2454
2455 /**
2456 * Build an atomic decomposition using syntactic/semantic locality checking
2457 *
2458 * @param moduleMethod
2459 * if true, use semantic locality checking; if false, use syntactic
2460 * one
2461 * @param moduleType
2462 * if 0, use \bot modules; if 1, use \top modules; if 2, use STAR
2463 * modules
2464 * @return the size of the constructed atomic decomposition
2465 */
2466 public int getAtomicDecompositionSize(ModuleMethod moduleMethod,
2467 ModuleType moduleType) {
2468 final int iModuleMethod = getIndexByModuleMethod(moduleMethod);
2469 final int iModuleType = getIndexByModuleType(moduleType);
2470 return kernel.getAtomicDecompositionSize(iModuleMethod, iModuleType);
2471 }
2472
2473 /**
2474 * @param index
2475 * index of atom
2476 * @return atom
2477 */
2478 public Set<OWLAxiom> getAtomAxioms(int index) {
2479 AxiomPointer[] axioms = kernel.getAtomAxioms(index);
2480 return axiomsToSet(axioms);
2481 }
2482
2483 /**
2484 * @param index
2485 * index of module
2486 * @return module
2487 */
2488 public Set<OWLAxiom> getAtomModule(int index) {
2489 AxiomPointer[] axioms = kernel.getAtomModule(index);
2490 return axiomsToSet(axioms);
2491 }
2492
2493 private Set<OWLAxiom> axiomsToSet(AxiomPointer[] axioms) {
2494 Set<OWLAxiom> toReturn = new HashSet<>();
2495 for (AxiomPointer p : axioms) {
2496 final OWLAxiom owlAxiom = ptr2AxiomMap.get(p);
2497 if (owlAxiom != null) {
2498 toReturn.add(owlAxiom);
2499 }
2500 }
2501 return toReturn;
2502 }
2503
2504 /**
2505 * @param index
2506 * atom index
2507 * @return atom dependents indexes
2508 */
2509 public int[] getAtomDependents(int index) {
2510 return kernel.getAtomDependents(index);
2511 }
2512
2513 /**
2514 * @return loc check number
2515 */
2516 public int getLocCheckNumber() {
2517 return kernel.getLocCheckNumber();
2518 }
2519
2520 private final class EntityVisitorEx implements OWLEntityVisitorEx<Pointer> {
2521
2522 public EntityVisitorEx() {}
2523
2524 @Override
2525 public Pointer visit(OWLClass cls) {
2526 return toClassPointer(cls);
2527 }
2528
2529 @Override
2530 public Pointer visit(OWLObjectProperty property) {
2531 return toObjectPropertyPointer(property);
2532 }
2533
2534 @Override
2535 public Pointer visit(OWLDataProperty property) {
2536 return toDataPropertyPointer(property);
2537 }
2538
2539 @Override
2540 public Pointer visit(OWLNamedIndividual individual) {
2541 return toIndividualPointer(individual);
2542 }
2543
2544 @Override
2545 public Pointer visit(OWLDatatype datatype) {
2546 return null;
2547 }
2548
2549 @Override
2550 public Pointer visit(OWLAnnotationProperty property) {
2551 return null;
2552 }
2553 }
2554
2555 final EntityVisitorEx entityTranslator = new EntityVisitorEx();
2556
2557 /**
2558 * @param signature
2559 * if true, use semantic locality checking; if false, use syntactic
2560 * one
2561 * @param moduleMethod
2562 * module method
2563 * @param moduleType
2564 * if 0, use \bot modules; if 1, use \top modules; if 2, use STAR
2565 * modules
2566 * @return module
2567 */
2568 public Set<OWLAxiom> getModule(Set<OWLEntity> signature,
2569 ModuleMethod moduleMethod, ModuleType moduleType) {
2570 kernel.initArgList();
2571 for (OWLEntity entity : signature) {
2572 if (entity instanceof OWLLogicalEntity) {
2573 kernel.addArg(entity.accept(entityTranslator));
2574 }
2575 }
2576 final int iModuleMethod = getIndexByModuleMethod(moduleMethod);
2577 final int iModuleType = getIndexByModuleType(moduleType);
2578 AxiomPointer[] axioms = kernel.getModule(iModuleMethod, iModuleType);
2579 return axiomsToSet(axioms);
2580 }
2581
2582 /**
2583 * @param signature
2584 * signature
2585 * @param moduleMethod
2586 * module method
2587 * @param moduleType
2588 * module type
2589 * @return non local axioms
2590 */
2591 public Set<OWLAxiom> getNonLocal(Set<OWLEntity> signature,
2592 ModuleMethod moduleMethod, ModuleType moduleType) {
2593 kernel.initArgList();
2594 for (OWLEntity entity : signature) {
2595 if (entity instanceof OWLLogicalEntity) {
2596 kernel.addArg(entity.accept(entityTranslator));
2597 }
2598 }
2599 final int iModuleMethod = getIndexByModuleMethod(moduleMethod);
2600 final int iModuleType = getIndexByModuleType(moduleType);
2601 AxiomPointer[] axioms = kernel.getNonLocal(iModuleMethod, iModuleType);
2602 return axiomsToSet(axioms);
2603 }
2604
2605 /*
2606 * Save/load support
2607 */
2608 /**
2609 * @param name
2610 * save/load context name
2611 * @return true iff the file exists
2612 */
2613 public boolean checkSaveLoadContext(String name) {
2614 return kernel.checkSaveLoadContext(name);
2615 }
2616
2617 /**
2618 * Set a save/load file to a given name. If the named file doesn't exist,
2619 * then it would be created and the classified taxonomy would be saved
2620 * there. If the file exists, the once classified taxonomy will be loaded
2621 * from there. If the parameter is null, no loading of taxonomy is
2622 * performed.
2623 *
2624 * @param name
2625 * save/load file name. Do not load the pre-classified taxonomy if
2626 * null
2627 * @return true if successful
2628 */
2629 public boolean setSaveLoadContext(String name) {
2630 return kernel.setSaveLoadContext(name);
2631 }
2632
2633 /**
2634 * Clear the saved reasoner state in the file name
2635 *
2636 * @param name
2637 * save/load file name
2638 * @return true if successful
2639 */
2640 public boolean clearSaveLoadContext(String name) {
2641 return kernel.clearSaveLoadContext(name);
2642 }
2643 }