Skip to content

Method: isPrecomputed(InferenceType)

1: /**
2: * Copyright (C) 2020 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.jopa.owlapi.identityreasoner;
16:
17: import org.semanticweb.owlapi.model.*;
18: import org.semanticweb.owlapi.reasoner.*;
19: import org.semanticweb.owlapi.reasoner.impl.*;
20: import org.semanticweb.owlapi.search.EntitySearcher;
21: import org.semanticweb.owlapi.util.Version;
22:
23: import javax.annotation.Nonnull;
24: import java.util.Collections;
25: import java.util.HashSet;
26: import java.util.List;
27: import java.util.Set;
28:
29: @Deprecated
30: class OWLAPIIdentityReasoner implements OWLReasoner {
31:
32: private final OWLOntology o;
33:
34: public OWLAPIIdentityReasoner(final OWLOntology o) {
35: this.o = o;
36: }
37:
38:
39: public void dispose() {
40: // do nothing
41: }
42:
43:
44: public void flush() {
45: // do nothing
46: }
47:
48:
49: @Nonnull
50: public Node<OWLClass> getBottomClassNode() {
51: return new OWLClassNode(o.getOWLOntologyManager().getOWLDataFactory()
52: .getOWLNothing());
53: }
54:
55:
56: @Nonnull
57: public Node<OWLDataProperty> getBottomDataPropertyNode() {
58: return new OWLDataPropertyNode(o.getOWLOntologyManager()
59: .getOWLDataFactory().getOWLBottomDataProperty());
60: }
61:
62:
63: @Nonnull
64: public Node<OWLObjectPropertyExpression> getBottomObjectPropertyNode() {
65: return new OWLObjectPropertyNode(o.getOWLOntologyManager()
66: .getOWLDataFactory().getOWLBottomObjectProperty());
67: }
68:
69:
70: @Nonnull
71: public BufferingMode getBufferingMode() {
72: return BufferingMode.NON_BUFFERING;
73: }
74:
75:
76: @Nonnull
77: public NodeSet<OWLClass> getDataPropertyDomains(@Nonnull OWLDataProperty pe,
78: boolean direct) throws InconsistentOntologyException,
79: ReasonerInterruptedException,
80: TimeOutException {
81: final OWLClassNodeSet s = new OWLClassNodeSet();
82:
83: for (final OWLDataPropertyDomainAxiom a : o
84: .getAxioms(AxiomType.DATA_PROPERTY_DOMAIN)) {
85: if (a.getProperty().equals(pe) && !a.getDomain().isAnonymous()) {
86: s.addEntity(a.getDomain().asOWLClass());
87: }
88: }
89:
90: return s;
91: }
92:
93:
94: @Nonnull
95: public Set<OWLLiteral> getDataPropertyValues(@Nonnull OWLNamedIndividual ind,
96: @Nonnull OWLDataProperty pe) throws InconsistentOntologyException,
97: ReasonerInterruptedException,
98: TimeOutException {
99: final Set<OWLLiteral> literals = new HashSet<>();
100:
101: for (final OWLDataPropertyAssertionAxiom a : o
102: .getAxioms(AxiomType.DATA_PROPERTY_ASSERTION)) {
103: if (a.getProperty().equals(pe) && a.getSubject().equals(ind)) {
104: // if (a.getObject().isNamed()) {
105: // pn.addEntity(a.getObject().asOWLNamedIndividual());
106: // }
107: literals.add(a.getObject());
108: }
109: }
110:
111: return literals;
112: }
113:
114:
115: @Nonnull
116: public NodeSet<OWLNamedIndividual> getDifferentIndividuals(
117: @Nonnull OWLNamedIndividual ind) throws InconsistentOntologyException,
118: ReasonerInterruptedException, TimeOutException {
119: final OWLNamedIndividualNodeSet pn = new OWLNamedIndividualNodeSet();
120:
121: for (final OWLDifferentIndividualsAxiom a : o
122: .getAxioms(AxiomType.DIFFERENT_INDIVIDUALS)) {
123: if (a.getIndividuals().contains(ind)) {
124: for (OWLIndividual e : a.getIndividuals()) {
125: if (e.isNamed()) {
126: pn.addEntity(e.asOWLNamedIndividual());
127: }
128: }
129: }
130: }
131:
132: return pn;
133: }
134:
135: //        
136: //        public NodeSet<OWLClass> getDisjointClasses(OWLClassExpression ce,
137: //                        boolean direct) {
138: //                final OWLClassNodeSet pn = new OWLClassNodeSet();
139: //
140: //                for (final OWLDisjointClassesAxiom a : o
141: //                                .getAxioms(AxiomType.DISJOINT_CLASSES)) {
142: //                        if (a.getClassExpressions().contains(ce)) {
143: //                                for (OWLClassExpression e : a.getClassExpressions()) {
144: //                                        if (!e.isAnonymous()) {
145: //                                                pn.addEntity(e.asOWLClass());
146: //                                        }
147: //                                }
148: //                        }
149: //                }
150: //
151: //                return pn;
152: //        }
153: //
154: //        
155: //        public NodeSet<OWLDataProperty> getDisjointDataProperties(
156: //                        OWLDataPropertyExpression pe, boolean direct)
157: //                        throws InconsistentOntologyException, ReasonerInterruptedException,
158: //                        TimeOutException {
159: //                final OWLDataPropertyNodeSet pn = new OWLDataPropertyNodeSet();
160: //
161: //                for (final OWLDisjointDataPropertiesAxiom a : o
162: //                                .getAxioms(AxiomType.DISJOINT_DATA_PROPERTIES)) {
163: //                        if (a.getProperties().contains(pe)) {
164: //                                for (OWLDataPropertyExpression e : a.getProperties()) {
165: //                                        if (!e.isAnonymous()) {
166: //                                                pn.addEntity(e.asOWLDataProperty());
167: //                                        }
168: //                                }
169: //                        }
170: //                }
171: //
172: //                return pn;
173: //        }
174: //
175: //        
176: //        public NodeSet<OWLObjectProperty> getDisjointObjectProperties(
177: //                        OWLObjectPropertyExpression pe, boolean direct)
178: //                        throws InconsistentOntologyException, ReasonerInterruptedException,
179: //                        TimeOutException {
180: //                final OWLObjectPropertyNodeSet pn = new OWLObjectPropertyNodeSet();
181: //
182: //                for (final OWLDisjointObjectPropertiesAxiom a : o
183: //                                .getAxioms(AxiomType.DISJOINT_OBJECT_PROPERTIES)) {
184: //                        if (a.getProperties().contains(pe)) {
185: //                                for (OWLObjectPropertyExpression e : a.getProperties()) {
186: //                                        if (!e.isAnonymous()) {
187: //                                                pn.addEntity(e.asOWLObjectProperty());
188: //                                        }
189: //                                }
190: //                        }
191: //                }
192: //
193: //                return pn;
194: //        }
195:
196:
197: @Nonnull
198: public Node<OWLClass> getEquivalentClasses(@Nonnull OWLClassExpression ce)
199: throws InconsistentOntologyException,
200: ClassExpressionNotInProfileException, ReasonerInterruptedException,
201: TimeOutException {
202: final OWLClassNode pn = new OWLClassNode();
203:
204: for (final OWLEquivalentClassesAxiom a : o
205: .getAxioms(AxiomType.EQUIVALENT_CLASSES)) {
206: if (a.getClassExpressions().contains(ce)) {
207: for (OWLClassExpression e : a.getClassExpressions()) {
208: if (!e.isAnonymous()) {
209: pn.add(e.asOWLClass());
210: }
211: }
212: }
213: }
214:
215: return pn;
216: }
217:
218:
219: @Nonnull
220: public Node<OWLDataProperty> getEquivalentDataProperties(@Nonnull OWLDataProperty pe)
221: throws InconsistentOntologyException, ReasonerInterruptedException,
222: TimeOutException {
223: final OWLDataPropertyNode pn = new OWLDataPropertyNode(pe);
224:
225: EntitySearcher.getEquivalentProperties(pe, o).filter(p -> !p.isAnonymous())
226: .forEach(p -> pn.add(p.asOWLDataProperty()));
227:
228: pn.add(pe);
229:
230: return pn;
231: }
232:
233:
234: @Nonnull
235: public Node<OWLObjectPropertyExpression> getEquivalentObjectProperties(
236: @Nonnull OWLObjectPropertyExpression pe)
237: throws InconsistentOntologyException, ReasonerInterruptedException,
238: TimeOutException {
239: final OWLObjectPropertyNode pn = new OWLObjectPropertyNode();
240:
241: for (final OWLEquivalentObjectPropertiesAxiom a : o
242: .getAxioms(AxiomType.EQUIVALENT_OBJECT_PROPERTIES)) {
243: if (a.getProperties().contains(pe)) {
244: for (OWLObjectPropertyExpression e : a.getProperties()) {
245: if (!e.isAnonymous()) {
246: pn.add(e.asOWLObjectProperty());
247: }
248: }
249: }
250: }
251:
252: return pn;
253: }
254:
255:
256: @Nonnull
257: public IndividualNodeSetPolicy getIndividualNodeSetPolicy() {
258: return IndividualNodeSetPolicy.BY_NAME;
259: }
260:
261:
262: @Nonnull
263: public NodeSet<OWLNamedIndividual> getInstances(@Nonnull OWLClassExpression ce,
264: boolean direct) throws InconsistentOntologyException,
265: ClassExpressionNotInProfileException,
266: ReasonerInterruptedException,
267: TimeOutException {
268: final OWLNamedIndividualNodeSet s = new OWLNamedIndividualNodeSet();
269:
270: for (final OWLClassAssertionAxiom a : o
271: .getAxioms(AxiomType.CLASS_ASSERTION)) {
272: if (a.getClassExpression().equals(ce)
273: && a.getIndividual().isNamed()) {
274: s.addEntity(a.getIndividual().asOWLNamedIndividual());
275: }
276: }
277:
278: return s;
279: }
280:
281:
282: @Nonnull
283: public Node<OWLObjectPropertyExpression> getInverseObjectProperties(
284: @Nonnull OWLObjectPropertyExpression pe)
285: throws InconsistentOntologyException, ReasonerInterruptedException,
286: TimeOutException {
287: final OWLObjectPropertyNode s = new OWLObjectPropertyNode();
288:
289: for (final OWLInverseObjectPropertiesAxiom a : o
290: .getAxioms(AxiomType.INVERSE_OBJECT_PROPERTIES)) {
291: if (a.getFirstProperty().equals(pe)) {
292: if (!a.getSecondProperty().isAnonymous()) {
293: s.add(a.getSecondProperty().asOWLObjectProperty());
294: }
295: } else if (a.getSecondProperty().equals(pe)) {
296: if (!a.getFirstProperty().isAnonymous()) {
297: s.add(a.getFirstProperty().asOWLObjectProperty());
298: }
299: }
300: }
301:
302: return s;
303: }
304:
305:
306: @Nonnull
307: public NodeSet<OWLClass> getObjectPropertyDomains(
308: @Nonnull OWLObjectPropertyExpression pe, boolean direct)
309: throws InconsistentOntologyException, ReasonerInterruptedException,
310: TimeOutException {
311: final OWLClassNodeSet s = new OWLClassNodeSet();
312:
313: for (final OWLObjectPropertyDomainAxiom a : o
314: .getAxioms(AxiomType.OBJECT_PROPERTY_DOMAIN)) {
315: if (a.getProperty().equals(pe) && !a.getDomain().isAnonymous()) {
316: s.addEntity(a.getDomain().asOWLClass());
317: }
318: }
319:
320: return s;
321: }
322:
323:
324: @Nonnull
325: public NodeSet<OWLClass> getObjectPropertyRanges(
326: @Nonnull OWLObjectPropertyExpression pe, boolean direct)
327: throws InconsistentOntologyException, ReasonerInterruptedException,
328: TimeOutException {
329: final OWLClassNodeSet s = new OWLClassNodeSet();
330:
331: for (final OWLObjectPropertyRangeAxiom a : o
332: .getAxioms(AxiomType.OBJECT_PROPERTY_RANGE)) {
333: if (a.getProperty().equals(pe) && !a.getRange().isAnonymous()) {
334: s.addEntity(a.getRange().asOWLClass());
335: }
336: }
337:
338: return s;
339: }
340:
341:
342: @Nonnull
343: public NodeSet<OWLNamedIndividual> getObjectPropertyValues(@Nonnull OWLNamedIndividual ind, @Nonnull
344: OWLObjectPropertyExpression pe)
345: throws InconsistentOntologyException, ReasonerInterruptedException,
346: TimeOutException {
347: final OWLNamedIndividualNodeSet pn = new OWLNamedIndividualNodeSet();
348:
349: EntitySearcher.getObjectPropertyValues(ind, pe, o).filter(OWLIndividual::isNamed)
350: .forEach(i -> pn.addEntity(i.asOWLNamedIndividual()));
351: //
352: // o.getOWLOntologyManager().getOWLDataFactory().getOWLNamedIndividual(iri)
353: //
354: // for (final OWLObjectPropertyAssertionAxiom a : o
355: // .getAxioms(AxiomType.OBJECT_PROPERTY_ASSERTION)) {
356: // if (a.getProperty().equals(pe) && a.getSubject().equals(ind)) {
357: // if (a.getObject().isNamed()) {
358: // pn.addEntity(a.getObject().asOWLNamedIndividual());
359: // }
360: // }
361: // }
362:
363: return pn;
364: }
365:
366:
367: @Nonnull
368: public Set<OWLAxiom> getPendingAxiomAdditions() {
369: return Collections.emptySet();
370: }
371:
372:
373: @Nonnull
374: public Set<OWLAxiom> getPendingAxiomRemovals() {
375: return Collections.emptySet();
376: }
377:
378:
379: @Nonnull
380: public List<OWLOntologyChange> getPendingChanges() {
381: return Collections.emptyList();
382: }
383:
384:
385: @Nonnull
386: public String getReasonerName() {
387: return "identity reasoner";
388: }
389:
390:
391: @Nonnull
392: public Version getReasonerVersion() {
393: return new Version(0, 1, 0, 1);
394: }
395:
396:
397: @Nonnull
398: public OWLOntology getRootOntology() {
399: return o;
400: }
401:
402:
403: @Nonnull
404: public Node<OWLNamedIndividual> getSameIndividuals(@Nonnull OWLNamedIndividual ind)
405: throws InconsistentOntologyException, ReasonerInterruptedException,
406: TimeOutException {
407: final OWLNamedIndividualNode pn = new OWLNamedIndividualNode();
408:
409: for (final OWLSameIndividualAxiom a : o
410: .getAxioms(AxiomType.SAME_INDIVIDUAL)) {
411: if (a.getIndividuals().contains(ind)) {
412: for (OWLIndividual e : a.getIndividuals()) {
413: if (e.isNamed()) {
414: pn.add(e.asOWLNamedIndividual());
415: }
416: }
417: }
418: }
419:
420: return pn;
421: }
422:
423:
424: @Nonnull
425: public NodeSet<OWLClass> getSubClasses(@Nonnull OWLClassExpression ce, boolean direct) {
426: final OWLClassNodeSet pn = new OWLClassNodeSet();
427:
428: for (final OWLSubClassOfAxiom a : o.getAxioms(AxiomType.SUBCLASS_OF)) {
429: if (a.getSuperClass().equals(ce)) {
430: if (!a.getSubClass().isAnonymous()) {
431: pn.addEntity(a.getSubClass().asOWLClass());
432: }
433: }
434: }
435:
436: return pn;
437: }
438:
439:
440: @Nonnull
441: public NodeSet<OWLDataProperty> getSubDataProperties(@Nonnull OWLDataProperty pe,
442: boolean direct) throws InconsistentOntologyException,
443: ReasonerInterruptedException,
444: TimeOutException {
445: final OWLDataPropertyNodeSet pn = new OWLDataPropertyNodeSet();
446:
447: for (final OWLSubDataPropertyOfAxiom a : o
448: .getAxioms(AxiomType.SUB_DATA_PROPERTY)) {
449: if (a.getSuperProperty().equals(pe)) {
450: if (!a.getSubProperty().isAnonymous()) {
451: pn.addEntity(a.getSubProperty().asOWLDataProperty());
452: }
453: }
454: }
455:
456: return pn;
457: }
458:
459:
460: @Nonnull
461: public NodeSet<OWLObjectPropertyExpression> getSubObjectProperties(
462: @Nonnull OWLObjectPropertyExpression pe, boolean direct)
463: throws InconsistentOntologyException, ReasonerInterruptedException,
464: TimeOutException {
465: final OWLObjectPropertyNodeSet pn = new OWLObjectPropertyNodeSet();
466:
467: for (final OWLSubObjectPropertyOfAxiom a : o
468: .getAxioms(AxiomType.SUB_OBJECT_PROPERTY)) {
469: if (a.getSuperProperty().equals(pe)) {
470: if (!a.getSubProperty().isAnonymous()) {
471: pn.addEntity(a.getSubProperty().asOWLObjectProperty());
472: }
473: }
474: }
475:
476: return pn;
477: }
478:
479:
480: @Nonnull
481: public NodeSet<OWLClass> getSuperClasses(@Nonnull OWLClassExpression ce,
482: boolean direct) throws InconsistentOntologyException,
483: ClassExpressionNotInProfileException,
484: ReasonerInterruptedException,
485: TimeOutException {
486: final OWLClassNodeSet pn = new OWLClassNodeSet();
487:
488: for (final OWLSubClassOfAxiom a : o.getAxioms(AxiomType.SUBCLASS_OF)) {
489: if (a.getSubClass().equals(ce)) {
490: if (!a.getSuperClass().isAnonymous()) {
491: pn.addEntity(a.getSuperClass().asOWLClass());
492: }
493: }
494: }
495:
496: return pn;
497: }
498:
499:
500: @Nonnull
501: public NodeSet<OWLDataProperty> getSuperDataProperties(@Nonnull OWLDataProperty pe,
502: boolean direct) throws InconsistentOntologyException,
503: ReasonerInterruptedException,
504: TimeOutException {
505: final OWLDataPropertyNodeSet pn = new OWLDataPropertyNodeSet();
506:
507: for (final OWLSubDataPropertyOfAxiom a : o
508: .getAxioms(AxiomType.SUB_DATA_PROPERTY)) {
509: if (a.getSubProperty().equals(pe)) {
510: if (!a.getSuperProperty().isAnonymous()) {
511: pn.addEntity(a.getSuperProperty().asOWLDataProperty());
512: }
513: }
514: }
515:
516: return pn;
517: }
518:
519:
520: @Nonnull
521: public NodeSet<OWLObjectPropertyExpression> getSuperObjectProperties(
522: @Nonnull OWLObjectPropertyExpression pe, boolean direct)
523: throws InconsistentOntologyException, ReasonerInterruptedException,
524: TimeOutException {
525: final OWLObjectPropertyNodeSet pn = new OWLObjectPropertyNodeSet();
526:
527: for (final OWLSubObjectPropertyOfAxiom a : o
528: .getAxioms(AxiomType.SUB_OBJECT_PROPERTY)) {
529: if (a.getSubProperty().equals(pe)) {
530: if (!a.getSuperProperty().isAnonymous()) {
531: pn.addEntity(a.getSuperProperty().asOWLObjectProperty());
532: }
533: }
534: }
535:
536: return pn;
537: }
538:
539:
540: public long getTimeOut() {
541: return Long.MAX_VALUE;
542: }
543:
544:
545: @Nonnull
546: public Node<OWLClass> getTopClassNode() {
547: return new OWLClassNode(o.getOWLOntologyManager().getOWLDataFactory()
548: .getOWLThing());
549: }
550:
551:
552: @Nonnull
553: public Node<OWLDataProperty> getTopDataPropertyNode() {
554: return new OWLDataPropertyNode(o.getOWLOntologyManager()
555: .getOWLDataFactory().getOWLTopDataProperty());
556: }
557:
558:
559: @Nonnull
560: public Node<OWLObjectPropertyExpression> getTopObjectPropertyNode() {
561: return new OWLObjectPropertyNode(o.getOWLOntologyManager()
562: .getOWLDataFactory().getOWLTopObjectProperty());
563:
564: }
565:
566:
567: @Nonnull
568: public NodeSet<OWLClass> getTypes(@Nonnull OWLNamedIndividual ind, boolean direct)
569: throws InconsistentOntologyException, ReasonerInterruptedException,
570: TimeOutException {
571: final OWLClassNodeSet s = new OWLClassNodeSet();
572:
573: // for (final OWLClassAssertionAxiom a : o
574: // .getAxioms(AxiomType.CLASS_ASSERTION)) {
575: // if (a.getIndividual().equals(ce)
576: // && a.getIndividual().isNamed()) {
577: // s.addEntity(a.getIndividual().asOWLNamedIndividual());
578: // }
579: // }
580:
581: EntitySearcher.getTypes(ind, o).filter(ce -> !ce.isAnonymous()).forEach(ce -> s.addEntity(ce.asOWLClass()));
582:
583: return s;
584: }
585:
586:
587: @Nonnull
588: public Node<OWLClass> getUnsatisfiableClasses()
589: throws ReasonerInterruptedException, TimeOutException {
590: return new OWLClassNode();
591: }
592:
593:
594: public void interrupt() {
595: // do nothing
596: }
597:
598:
599: public boolean isConsistent() throws ReasonerInterruptedException,
600: TimeOutException {
601: return true;
602: }
603:
604:
605: public boolean isEntailed(@Nonnull OWLAxiom axiom)
606: throws ReasonerInterruptedException,
607: UnsupportedEntailmentTypeException, TimeOutException,
608: AxiomNotInProfileException {
609: return o.containsAxiom(axiom);
610: }
611:
612:
613: public boolean isEntailed(@Nonnull Set<? extends OWLAxiom> axioms)
614: throws ReasonerInterruptedException,
615: UnsupportedEntailmentTypeException, TimeOutException,
616: AxiomNotInProfileException {
617: for (final OWLAxiom a : axioms) {
618: if (!o.containsAxiom(a)) {
619: return false;
620: }
621: }
622: return true;
623: }
624:
625:
626: public boolean isEntailmentCheckingSupported(@Nonnull AxiomType<?> axiomType) {
627: return true;
628: }
629:
630:
631: public boolean isSatisfiable(@Nonnull OWLClassExpression classExpression)
632: throws ReasonerInterruptedException, TimeOutException,
633: ClassExpressionNotInProfileException, InconsistentOntologyException {
634: return true;
635: }
636:
637:
638: @Nonnull
639: public FreshEntityPolicy getFreshEntityPolicy() {
640: return FreshEntityPolicy.DISALLOW;
641: }
642:
643:
644: @Nonnull
645: public NodeSet<OWLClass> getDisjointClasses(@Nonnull OWLClassExpression arg0)
646: throws ReasonerInterruptedException, TimeOutException,
647: FreshEntitiesException, InconsistentOntologyException {
648: // TODO Auto-generated method stub
649: return null;
650: }
651:
652:
653: @Nonnull
654: public NodeSet<OWLDataProperty> getDisjointDataProperties(
655: @Nonnull OWLDataPropertyExpression arg0)
656: throws InconsistentOntologyException, FreshEntitiesException,
657: ReasonerInterruptedException, TimeOutException {
658: // TODO Auto-generated method stub
659: return null;
660: }
661:
662:
663: @Nonnull
664: public NodeSet<OWLObjectPropertyExpression> getDisjointObjectProperties(
665: @Nonnull OWLObjectPropertyExpression arg0)
666: throws InconsistentOntologyException, FreshEntitiesException,
667: ReasonerInterruptedException, TimeOutException {
668: // TODO Auto-generated method stub
669: return null;
670: }
671:
672:
673: @Nonnull
674: public Set<InferenceType> getPrecomputableInferenceTypes() {
675: // TODO Auto-generated method stub
676: return null;
677: }
678:
679:
680: public boolean isPrecomputed(@Nonnull InferenceType arg0) {
681: // TODO Auto-generated method stub
682: return false;
683: }
684:
685:
686: public void precomputeInferences(@Nonnull InferenceType... arg0)
687: throws ReasonerInterruptedException, TimeOutException,
688: InconsistentOntologyException {
689: // TODO Auto-generated method stub
690:
691: }
692: }