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