| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
package uk.ac.manchester.cs.factplusplus.owlapiv3; |
| 24 |
|
| 25 |
import java.util.ArrayList; |
| 26 |
import java.util.Collection; |
| 27 |
import java.util.List; |
| 28 |
import java.util.Set; |
| 29 |
|
| 30 |
import org.semanticweb.owlapi.model.AxiomType; |
| 31 |
import org.semanticweb.owlapi.model.OWLAxiom; |
| 32 |
import org.semanticweb.owlapi.model.OWLClass; |
| 33 |
import org.semanticweb.owlapi.model.OWLClassExpression; |
| 34 |
import org.semanticweb.owlapi.model.OWLDataProperty; |
| 35 |
import org.semanticweb.owlapi.model.OWLDataPropertyExpression; |
| 36 |
import org.semanticweb.owlapi.model.OWLDataRange; |
| 37 |
import org.semanticweb.owlapi.model.OWLLiteral; |
| 38 |
import org.semanticweb.owlapi.model.OWLNamedIndividual; |
| 39 |
import org.semanticweb.owlapi.model.OWLObjectProperty; |
| 40 |
import org.semanticweb.owlapi.model.OWLObjectPropertyExpression; |
| 41 |
import org.semanticweb.owlapi.model.OWLOntology; |
| 42 |
import org.semanticweb.owlapi.model.OWLOntologyChange; |
| 43 |
import org.semanticweb.owlapi.reasoner.AxiomNotInProfileException; |
| 44 |
import org.semanticweb.owlapi.reasoner.BufferingMode; |
| 45 |
import org.semanticweb.owlapi.reasoner.ClassExpressionNotInProfileException; |
| 46 |
import org.semanticweb.owlapi.reasoner.FreshEntitiesException; |
| 47 |
import org.semanticweb.owlapi.reasoner.FreshEntityPolicy; |
| 48 |
import org.semanticweb.owlapi.reasoner.InconsistentOntologyException; |
| 49 |
import org.semanticweb.owlapi.reasoner.IndividualNodeSetPolicy; |
| 50 |
import org.semanticweb.owlapi.reasoner.InferenceType; |
| 51 |
import org.semanticweb.owlapi.reasoner.Node; |
| 52 |
import org.semanticweb.owlapi.reasoner.NodeSet; |
| 53 |
import org.semanticweb.owlapi.reasoner.OWLReasonerConfiguration; |
| 54 |
import org.semanticweb.owlapi.reasoner.ReasonerInterruptedException; |
| 55 |
import org.semanticweb.owlapi.reasoner.TimeOutException; |
| 56 |
import org.semanticweb.owlapi.reasoner.UnsupportedEntailmentTypeException; |
| 57 |
import org.semanticweb.owlapi.reasoner.knowledgeexploration.OWLKnowledgeExplorerReasoner; |
| 58 |
import org.semanticweb.owlapi.util.Version; |
| 59 |
|
| 60 |
import uk.ac.manchester.cs.factplusplus.NodePointer; |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
public class OWLKnowledgeExplorationReasonerWrapper implements |
| 67 |
OWLKnowledgeExplorerReasoner { |
| 68 |
|
| 69 |
private class RootNodeImpl implements RootNode { |
| 70 |
|
| 71 |
private final NodePointer pointer; |
| 72 |
|
| 73 |
public RootNodeImpl(NodePointer p) { |
| 74 |
pointer = p; |
| 75 |
} |
| 76 |
|
| 77 |
@SuppressWarnings("unchecked") |
| 78 |
@Override |
| 79 |
public <T> T getNode() { |
| 80 |
return (T) pointer; |
| 81 |
} |
| 82 |
|
| 83 |
@Override |
| 84 |
public int hashCode() { |
| 85 |
return pointer.hashCode(); |
| 86 |
} |
| 87 |
|
| 88 |
@Override |
| 89 |
public boolean equals(Object arg0) { |
| 90 |
if (arg0 == null) { |
| 91 |
return false; |
| 92 |
} |
| 93 |
if (this == arg0) { |
| 94 |
return true; |
| 95 |
} |
| 96 |
if (arg0 instanceof RootNode) { |
| 97 |
return pointer.equals(((RootNode) arg0).getNode()); |
| 98 |
} |
| 99 |
return false; |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
private final FaCTPlusPlusReasoner r; |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
public OWLKnowledgeExplorationReasonerWrapper(FaCTPlusPlusReasoner r) { |
| 110 |
this.r = r; |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
public void ontologiesChanged(List<? extends OWLOntologyChange> changes) { |
| 118 |
r.ontologiesChanged(changes); |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
public OWLReasonerConfiguration getReasonerConfiguration() { |
| 125 |
return r.getReasonerConfiguration(); |
| 126 |
} |
| 127 |
|
| 128 |
@Override |
| 129 |
public BufferingMode getBufferingMode() { |
| 130 |
return r.getBufferingMode(); |
| 131 |
} |
| 132 |
|
| 133 |
@Override |
| 134 |
public long getTimeOut() { |
| 135 |
return r.getTimeOut(); |
| 136 |
} |
| 137 |
|
| 138 |
@Override |
| 139 |
public OWLOntology getRootOntology() { |
| 140 |
return r.getRootOntology(); |
| 141 |
} |
| 142 |
|
| 143 |
@Override |
| 144 |
public List<OWLOntologyChange> getPendingChanges() { |
| 145 |
return r.getPendingChanges(); |
| 146 |
} |
| 147 |
|
| 148 |
@Override |
| 149 |
public Set<OWLAxiom> getPendingAxiomAdditions() { |
| 150 |
return r.getPendingAxiomAdditions(); |
| 151 |
} |
| 152 |
|
| 153 |
@Override |
| 154 |
public Set<OWLAxiom> getPendingAxiomRemovals() { |
| 155 |
return r.getPendingAxiomRemovals(); |
| 156 |
} |
| 157 |
|
| 158 |
@Override |
| 159 |
public FreshEntityPolicy getFreshEntityPolicy() { |
| 160 |
return r.getFreshEntityPolicy(); |
| 161 |
} |
| 162 |
|
| 163 |
@Override |
| 164 |
public IndividualNodeSetPolicy getIndividualNodeSetPolicy() { |
| 165 |
return r.getIndividualNodeSetPolicy(); |
| 166 |
} |
| 167 |
|
| 168 |
@Override |
| 169 |
public String getReasonerName() { |
| 170 |
return r.getReasonerName(); |
| 171 |
} |
| 172 |
|
| 173 |
@Override |
| 174 |
public Version getReasonerVersion() { |
| 175 |
return r.getReasonerVersion(); |
| 176 |
} |
| 177 |
|
| 178 |
@Override |
| 179 |
public void interrupt() { |
| 180 |
r.interrupt(); |
| 181 |
} |
| 182 |
|
| 183 |
@Override |
| 184 |
public void precomputeInferences(InferenceType... inferenceTypes) |
| 185 |
throws ReasonerInterruptedException, TimeOutException, |
| 186 |
InconsistentOntologyException { |
| 187 |
r.precomputeInferences(inferenceTypes); |
| 188 |
} |
| 189 |
|
| 190 |
@Override |
| 191 |
public boolean isPrecomputed(InferenceType inferenceType) { |
| 192 |
return r.isPrecomputed(inferenceType); |
| 193 |
} |
| 194 |
|
| 195 |
@Override |
| 196 |
public Set<InferenceType> getPrecomputableInferenceTypes() { |
| 197 |
return r.getPrecomputableInferenceTypes(); |
| 198 |
} |
| 199 |
|
| 200 |
@Override |
| 201 |
public boolean isConsistent() throws ReasonerInterruptedException, |
| 202 |
TimeOutException { |
| 203 |
return r.isConsistent(); |
| 204 |
} |
| 205 |
|
| 206 |
@Override |
| 207 |
public boolean isSatisfiable(OWLClassExpression classExpression) |
| 208 |
throws ReasonerInterruptedException, TimeOutException, |
| 209 |
ClassExpressionNotInProfileException, FreshEntitiesException, |
| 210 |
InconsistentOntologyException { |
| 211 |
return r.isSatisfiable(classExpression); |
| 212 |
} |
| 213 |
|
| 214 |
@Override |
| 215 |
public Node<OWLClass> getUnsatisfiableClasses() |
| 216 |
throws ReasonerInterruptedException, TimeOutException, |
| 217 |
InconsistentOntologyException { |
| 218 |
return r.getUnsatisfiableClasses(); |
| 219 |
} |
| 220 |
|
| 221 |
@Override |
| 222 |
public boolean isEntailed(OWLAxiom axiom) |
| 223 |
throws ReasonerInterruptedException, |
| 224 |
UnsupportedEntailmentTypeException, TimeOutException, |
| 225 |
AxiomNotInProfileException, FreshEntitiesException, |
| 226 |
InconsistentOntologyException { |
| 227 |
return r.isEntailed(axiom); |
| 228 |
} |
| 229 |
|
| 230 |
@Override |
| 231 |
public boolean isEntailed(Set<? extends OWLAxiom> axioms) |
| 232 |
throws ReasonerInterruptedException, |
| 233 |
UnsupportedEntailmentTypeException, TimeOutException, |
| 234 |
AxiomNotInProfileException, FreshEntitiesException, |
| 235 |
InconsistentOntologyException { |
| 236 |
return r.isEntailed(axioms); |
| 237 |
} |
| 238 |
|
| 239 |
@Override |
| 240 |
public boolean isEntailmentCheckingSupported(AxiomType<?> axiomType) { |
| 241 |
return r.isEntailmentCheckingSupported(axiomType); |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
public Set<OWLAxiom> getTrace(OWLAxiom axiom) { |
| 250 |
return r.getTrace(axiom); |
| 251 |
} |
| 252 |
|
| 253 |
@Override |
| 254 |
public Node<OWLClass> getTopClassNode() { |
| 255 |
return r.getTopClassNode(); |
| 256 |
} |
| 257 |
|
| 258 |
@Override |
| 259 |
public Node<OWLClass> getBottomClassNode() { |
| 260 |
return r.getBottomClassNode(); |
| 261 |
} |
| 262 |
|
| 263 |
@Override |
| 264 |
public NodeSet<OWLClass> |
| 265 |
getSubClasses(OWLClassExpression ce, boolean direct) |
| 266 |
throws ReasonerInterruptedException, TimeOutException, |
| 267 |
FreshEntitiesException, InconsistentOntologyException { |
| 268 |
return r.getSubClasses(ce, direct); |
| 269 |
} |
| 270 |
|
| 271 |
@Override |
| 272 |
public NodeSet<OWLClass> getSuperClasses(OWLClassExpression ce, |
| 273 |
boolean direct) throws InconsistentOntologyException, |
| 274 |
ClassExpressionNotInProfileException, ReasonerInterruptedException, |
| 275 |
TimeOutException { |
| 276 |
return r.getSuperClasses(ce, direct); |
| 277 |
} |
| 278 |
|
| 279 |
@Override |
| 280 |
public Node<OWLClass> getEquivalentClasses(OWLClassExpression ce) |
| 281 |
throws InconsistentOntologyException, |
| 282 |
ClassExpressionNotInProfileException, ReasonerInterruptedException, |
| 283 |
TimeOutException { |
| 284 |
return r.getEquivalentClasses(ce); |
| 285 |
} |
| 286 |
|
| 287 |
@Override |
| 288 |
public Node<OWLObjectPropertyExpression> getTopObjectPropertyNode() { |
| 289 |
return r.getTopObjectPropertyNode(); |
| 290 |
} |
| 291 |
|
| 292 |
@Override |
| 293 |
public Node<OWLObjectPropertyExpression> getBottomObjectPropertyNode() { |
| 294 |
return r.getBottomObjectPropertyNode(); |
| 295 |
} |
| 296 |
|
| 297 |
@Override |
| 298 |
public NodeSet<OWLObjectPropertyExpression> getSubObjectProperties( |
| 299 |
OWLObjectPropertyExpression pe, boolean direct) |
| 300 |
throws InconsistentOntologyException, ReasonerInterruptedException, |
| 301 |
TimeOutException { |
| 302 |
return r.getSubObjectProperties(pe, direct); |
| 303 |
} |
| 304 |
|
| 305 |
@Override |
| 306 |
public NodeSet<OWLObjectPropertyExpression> getSuperObjectProperties( |
| 307 |
OWLObjectPropertyExpression pe, boolean direct) |
| 308 |
throws InconsistentOntologyException, ReasonerInterruptedException, |
| 309 |
TimeOutException { |
| 310 |
return r.getSuperObjectProperties(pe, direct); |
| 311 |
} |
| 312 |
|
| 313 |
@Override |
| 314 |
public Node<OWLObjectPropertyExpression> getEquivalentObjectProperties( |
| 315 |
OWLObjectPropertyExpression pe) |
| 316 |
throws InconsistentOntologyException, ReasonerInterruptedException, |
| 317 |
TimeOutException { |
| 318 |
return r.getEquivalentObjectProperties(pe); |
| 319 |
} |
| 320 |
|
| 321 |
@Override |
| 322 |
public NodeSet<OWLObjectPropertyExpression> getDisjointObjectProperties( |
| 323 |
OWLObjectPropertyExpression pe) |
| 324 |
throws InconsistentOntologyException, ReasonerInterruptedException, |
| 325 |
TimeOutException { |
| 326 |
return r.getDisjointObjectProperties(pe); |
| 327 |
} |
| 328 |
|
| 329 |
@Override |
| 330 |
public Node<OWLObjectPropertyExpression> getInverseObjectProperties( |
| 331 |
OWLObjectPropertyExpression pe) |
| 332 |
throws InconsistentOntologyException, ReasonerInterruptedException, |
| 333 |
TimeOutException { |
| 334 |
return r.getInverseObjectProperties(pe); |
| 335 |
} |
| 336 |
|
| 337 |
@Override |
| 338 |
public NodeSet<OWLClass> getObjectPropertyDomains( |
| 339 |
OWLObjectPropertyExpression pe, boolean direct) |
| 340 |
throws InconsistentOntologyException, ReasonerInterruptedException, |
| 341 |
TimeOutException { |
| 342 |
return r.getObjectPropertyDomains(pe, direct); |
| 343 |
} |
| 344 |
|
| 345 |
@Override |
| 346 |
public NodeSet<OWLClass> getObjectPropertyRanges( |
| 347 |
OWLObjectPropertyExpression pe, boolean direct) |
| 348 |
throws InconsistentOntologyException, ReasonerInterruptedException, |
| 349 |
TimeOutException { |
| 350 |
return r.getObjectPropertyRanges(pe, direct); |
| 351 |
} |
| 352 |
|
| 353 |
@Override |
| 354 |
public Node<OWLDataProperty> getTopDataPropertyNode() { |
| 355 |
return r.getTopDataPropertyNode(); |
| 356 |
} |
| 357 |
|
| 358 |
@Override |
| 359 |
public Node<OWLDataProperty> getBottomDataPropertyNode() { |
| 360 |
return r.getBottomDataPropertyNode(); |
| 361 |
} |
| 362 |
|
| 363 |
@Override |
| 364 |
public NodeSet<OWLDataProperty> getSubDataProperties(OWLDataProperty pe, |
| 365 |
boolean direct) throws InconsistentOntologyException, |
| 366 |
ReasonerInterruptedException, TimeOutException { |
| 367 |
return r.getSubDataProperties(pe, direct); |
| 368 |
} |
| 369 |
|
| 370 |
@Override |
| 371 |
public NodeSet<OWLDataProperty> getSuperDataProperties(OWLDataProperty pe, |
| 372 |
boolean direct) throws InconsistentOntologyException, |
| 373 |
ReasonerInterruptedException, TimeOutException { |
| 374 |
return r.getSuperDataProperties(pe, direct); |
| 375 |
} |
| 376 |
|
| 377 |
@Override |
| 378 |
public Node<OWLDataProperty> |
| 379 |
getEquivalentDataProperties(OWLDataProperty pe) |
| 380 |
throws InconsistentOntologyException, |
| 381 |
ReasonerInterruptedException, TimeOutException { |
| 382 |
return r.getEquivalentDataProperties(pe); |
| 383 |
} |
| 384 |
|
| 385 |
@Override |
| 386 |
public NodeSet<OWLClass> getTypes(OWLNamedIndividual ind, boolean direct) |
| 387 |
throws InconsistentOntologyException, ReasonerInterruptedException, |
| 388 |
TimeOutException { |
| 389 |
return r.getTypes(ind, direct); |
| 390 |
} |
| 391 |
|
| 392 |
@Override |
| 393 |
public NodeSet<OWLNamedIndividual> getInstances(OWLClassExpression ce, |
| 394 |
boolean direct) throws InconsistentOntologyException, |
| 395 |
ClassExpressionNotInProfileException, ReasonerInterruptedException, |
| 396 |
TimeOutException { |
| 397 |
return r.getInstances(ce, direct); |
| 398 |
} |
| 399 |
|
| 400 |
@Override |
| 401 |
public NodeSet<OWLNamedIndividual> getObjectPropertyValues( |
| 402 |
OWLNamedIndividual ind, OWLObjectPropertyExpression pe) |
| 403 |
throws InconsistentOntologyException, ReasonerInterruptedException, |
| 404 |
TimeOutException { |
| 405 |
return r.getObjectPropertyValues(ind, pe); |
| 406 |
} |
| 407 |
|
| 408 |
@Override |
| 409 |
public Node<OWLNamedIndividual> getSameIndividuals(OWLNamedIndividual ind) |
| 410 |
throws InconsistentOntologyException, ReasonerInterruptedException, |
| 411 |
TimeOutException { |
| 412 |
return r.getSameIndividuals(ind); |
| 413 |
} |
| 414 |
|
| 415 |
@Override |
| 416 |
public void dispose() { |
| 417 |
r.dispose(); |
| 418 |
} |
| 419 |
|
| 420 |
@Override |
| 421 |
public void flush() { |
| 422 |
r.flush(); |
| 423 |
} |
| 424 |
|
| 425 |
@Override |
| 426 |
public NodeSet<OWLClass> getDisjointClasses(OWLClassExpression ce) { |
| 427 |
return r.getDisjointClasses(ce); |
| 428 |
} |
| 429 |
|
| 430 |
@Override |
| 431 |
public NodeSet<OWLDataProperty> getDisjointDataProperties( |
| 432 |
OWLDataPropertyExpression pe) throws InconsistentOntologyException, |
| 433 |
ReasonerInterruptedException, TimeOutException { |
| 434 |
return r.getDisjointDataProperties(pe); |
| 435 |
} |
| 436 |
|
| 437 |
@Override |
| 438 |
public NodeSet<OWLClass> getDataPropertyDomains(OWLDataProperty pe, |
| 439 |
boolean direct) throws InconsistentOntologyException, |
| 440 |
ReasonerInterruptedException, TimeOutException { |
| 441 |
return r.getDataPropertyDomains(pe, direct); |
| 442 |
} |
| 443 |
|
| 444 |
@Override |
| 445 |
public Set<OWLLiteral> getDataPropertyValues(OWLNamedIndividual ind, |
| 446 |
OWLDataProperty pe) throws InconsistentOntologyException, |
| 447 |
ReasonerInterruptedException, TimeOutException { |
| 448 |
return r.getDataPropertyValues(ind, pe); |
| 449 |
} |
| 450 |
|
| 451 |
@Override |
| 452 |
public NodeSet<OWLNamedIndividual> getDifferentIndividuals( |
| 453 |
OWLNamedIndividual ind) throws InconsistentOntologyException, |
| 454 |
ReasonerInterruptedException, TimeOutException { |
| 455 |
return r.getDifferentIndividuals(ind); |
| 456 |
} |
| 457 |
|
| 458 |
@Override |
| 459 |
public RootNode getRoot(OWLClassExpression expression) { |
| 460 |
return new RootNodeImpl(r.getRoot(expression)); |
| 461 |
} |
| 462 |
|
| 463 |
@Override |
| 464 |
public Node<? extends OWLObjectPropertyExpression> getObjectNeighbours( |
| 465 |
RootNode object, boolean deterministicOnly) { |
| 466 |
return r.getObjectNeighbours((NodePointer) object.getNode(), |
| 467 |
deterministicOnly); |
| 468 |
} |
| 469 |
|
| 470 |
@Override |
| 471 |
public Node<OWLDataProperty> getDataNeighbours(RootNode object, |
| 472 |
boolean deterministicOnly) { |
| 473 |
return r.getDataNeighbours((NodePointer) object.getNode(), |
| 474 |
deterministicOnly); |
| 475 |
} |
| 476 |
|
| 477 |
@Override |
| 478 |
public Collection<RootNode> getObjectNeighbours(RootNode object, |
| 479 |
OWLObjectProperty property) { |
| 480 |
Collection<RootNode> toReturn = new ArrayList<>(); |
| 481 |
for (NodePointer p : r.getObjectNeighbours( |
| 482 |
(NodePointer) object.getNode(), property)) { |
| 483 |
toReturn.add(new RootNodeImpl(p)); |
| 484 |
} |
| 485 |
return toReturn; |
| 486 |
} |
| 487 |
|
| 488 |
@Override |
| 489 |
public Collection<RootNode> getDataNeighbours(RootNode object, |
| 490 |
OWLDataProperty property) { |
| 491 |
Collection<RootNode> toReturn = new ArrayList<>(); |
| 492 |
for (NodePointer p : r.getDataNeighbours( |
| 493 |
(NodePointer) object.getNode(), property)) { |
| 494 |
toReturn.add(new RootNodeImpl(p)); |
| 495 |
} |
| 496 |
return toReturn; |
| 497 |
} |
| 498 |
|
| 499 |
@Override |
| 500 |
public Node<? extends OWLClassExpression> getObjectLabel(RootNode object, |
| 501 |
boolean deterministicOnly) { |
| 502 |
return r.getObjectLabel((NodePointer) object.getNode(), |
| 503 |
deterministicOnly); |
| 504 |
} |
| 505 |
|
| 506 |
@Override |
| 507 |
public Node<? extends OWLDataRange> getDataLabel(RootNode object, |
| 508 |
boolean deterministicOnly) { |
| 509 |
return r.getDataLabel((NodePointer) object.getNode(), deterministicOnly); |
| 510 |
} |
| 511 |
|
| 512 |
@Override |
| 513 |
public RootNode getBlocker(RootNode object) { |
| 514 |
return new RootNodeImpl(r.getBlocker((NodePointer) object.getNode())); |
| 515 |
} |
| 516 |
} |