Skip to content

Method: visit(OWLDataHasValue)

1: /**
2: * Copyright (C) 2016 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.owl2java;
16:
17: import java.util.HashMap;
18: import java.util.HashSet;
19: import java.util.Map;
20: import java.util.Set;
21:
22: import cz.cvut.kbss.jopa.model.SequencesVocabulary;
23: import org.semanticweb.owlapi.apibinding.OWLManager;
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.OWLAxiomVisitor;
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.OWLClassExpressionVisitor;
35: import org.semanticweb.owlapi.model.OWLDataAllValuesFrom;
36: import org.semanticweb.owlapi.model.OWLDataExactCardinality;
37: import org.semanticweb.owlapi.model.OWLDataFactory;
38: import org.semanticweb.owlapi.model.OWLDataHasValue;
39: import org.semanticweb.owlapi.model.OWLDataMaxCardinality;
40: import org.semanticweb.owlapi.model.OWLDataMinCardinality;
41: import org.semanticweb.owlapi.model.OWLDataProperty;
42: import org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom;
43: import org.semanticweb.owlapi.model.OWLDataPropertyDomainAxiom;
44: import org.semanticweb.owlapi.model.OWLDataPropertyExpression;
45: import org.semanticweb.owlapi.model.OWLDataPropertyRangeAxiom;
46: import org.semanticweb.owlapi.model.OWLDataRange;
47: import org.semanticweb.owlapi.model.OWLDataSomeValuesFrom;
48: import org.semanticweb.owlapi.model.OWLDatatype;
49: import org.semanticweb.owlapi.model.OWLDatatypeDefinitionAxiom;
50: import org.semanticweb.owlapi.model.OWLDeclarationAxiom;
51: import org.semanticweb.owlapi.model.OWLDifferentIndividualsAxiom;
52: import org.semanticweb.owlapi.model.OWLDisjointClassesAxiom;
53: import org.semanticweb.owlapi.model.OWLDisjointDataPropertiesAxiom;
54: import org.semanticweb.owlapi.model.OWLDisjointObjectPropertiesAxiom;
55: import org.semanticweb.owlapi.model.OWLDisjointUnionAxiom;
56: import org.semanticweb.owlapi.model.OWLEntityVisitor;
57: import org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom;
58: import org.semanticweb.owlapi.model.OWLEquivalentDataPropertiesAxiom;
59: import org.semanticweb.owlapi.model.OWLEquivalentObjectPropertiesAxiom;
60: import org.semanticweb.owlapi.model.OWLFunctionalDataPropertyAxiom;
61: import org.semanticweb.owlapi.model.OWLFunctionalObjectPropertyAxiom;
62: import org.semanticweb.owlapi.model.OWLHasKeyAxiom;
63: import org.semanticweb.owlapi.model.OWLInverseFunctionalObjectPropertyAxiom;
64: import org.semanticweb.owlapi.model.OWLInverseObjectPropertiesAxiom;
65: import org.semanticweb.owlapi.model.OWLIrreflexiveObjectPropertyAxiom;
66: import org.semanticweb.owlapi.model.OWLNamedIndividual;
67: import org.semanticweb.owlapi.model.OWLNegativeDataPropertyAssertionAxiom;
68: import org.semanticweb.owlapi.model.OWLNegativeObjectPropertyAssertionAxiom;
69: import org.semanticweb.owlapi.model.OWLObject;
70: import org.semanticweb.owlapi.model.OWLObjectAllValuesFrom;
71: import org.semanticweb.owlapi.model.OWLObjectComplementOf;
72: import org.semanticweb.owlapi.model.OWLObjectExactCardinality;
73: import org.semanticweb.owlapi.model.OWLObjectHasSelf;
74: import org.semanticweb.owlapi.model.OWLObjectHasValue;
75: import org.semanticweb.owlapi.model.OWLObjectIntersectionOf;
76: import org.semanticweb.owlapi.model.OWLObjectMaxCardinality;
77: import org.semanticweb.owlapi.model.OWLObjectMinCardinality;
78: import org.semanticweb.owlapi.model.OWLObjectOneOf;
79: import org.semanticweb.owlapi.model.OWLObjectProperty;
80: import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom;
81: import org.semanticweb.owlapi.model.OWLObjectPropertyDomainAxiom;
82: import org.semanticweb.owlapi.model.OWLObjectPropertyExpression;
83: import org.semanticweb.owlapi.model.OWLObjectPropertyRangeAxiom;
84: import org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom;
85: import org.semanticweb.owlapi.model.OWLObjectUnionOf;
86: import org.semanticweb.owlapi.model.OWLOntology;
87: import org.semanticweb.owlapi.model.OWLReflexiveObjectPropertyAxiom;
88: import org.semanticweb.owlapi.model.OWLSameIndividualAxiom;
89: import org.semanticweb.owlapi.model.OWLSubAnnotationPropertyOfAxiom;
90: import org.semanticweb.owlapi.model.OWLSubClassOfAxiom;
91: import org.semanticweb.owlapi.model.OWLSubDataPropertyOfAxiom;
92: import org.semanticweb.owlapi.model.OWLSubObjectPropertyOfAxiom;
93: import org.semanticweb.owlapi.model.OWLSubPropertyChainOfAxiom;
94: import org.semanticweb.owlapi.model.OWLSymmetricObjectPropertyAxiom;
95: import org.semanticweb.owlapi.model.OWLTransitiveObjectPropertyAxiom;
96: import org.semanticweb.owlapi.model.SWRLRule;
97:
98: import cz.cvut.kbss.jopa.model.ic.DataParticipationConstraint;
99: import cz.cvut.kbss.jopa.model.ic.DataRangeConstraint;
100: import cz.cvut.kbss.jopa.model.ic.IntegrityConstraint;
101: import cz.cvut.kbss.jopa.model.ic.IntegrityConstraintFactory;
102: import cz.cvut.kbss.jopa.model.ic.ObjectParticipationConstraint;
103: import cz.cvut.kbss.jopa.model.ic.ObjectRangeConstraint;
104: import cz.cvut.kbss.jopa.owl2java.OWL2JavaTransformer.Card;
105:
106: public class IntegrityConstraintParserImpl implements OWLAxiomVisitor {
107:
108: private OWLDataFactory f;
109:
110: // private Map<OWLClass, OWLClass> superClasses = new HashMap<OWLClass,
111: // OWLClass>();
112: // private Map<OWLObjectProperty, Set<ObjectDomainConstraint>> odConstraints
113: // = new HashMap<OWLObjectProperty, Set<ObjectDomainConstraint>>();
114: // private Map<OWLDataProperty, Set<DataDomainConstraint>> ddConstraints =
115: // new HashMap<OWLDataProperty, Set<DataDomainConstraint>>();
116: // private Map<OWLObjectProperty, ObjectRangeConstraint> orConstraints = new
117: // HashMap<OWLObjectProperty, ObjectRangeConstraint>();
118: // private Map<OWLObjectProperty, DataRangeConstraint> drConstraints = new
119: // HashMap<OWLObjectProperty, DataRangeConstraint>();
120: // private Map<OWLObjectProperty, ObjectRangeConstraint> orConstraints = new
121: // HashMap<OWLObjectProperty, ObjectRangeConstraint>();
122: // private Map<OWLObjectProperty, DataRangeConstraint> drConstraints = new
123: // HashMap<OWLObjectProperty, DataRangeConstraint>();
124:
125: private Map<OWLClass, Map<OWLObjectProperty, Set<IntegrityConstraint>>> opConstraints = new HashMap<OWLClass, Map<OWLObjectProperty, Set<IntegrityConstraint>>>();
126: private Map<OWLClass, Map<OWLDataProperty, Set<IntegrityConstraint>>> dpConstraints = new HashMap<OWLClass, Map<OWLDataProperty, Set<IntegrityConstraint>>>();
127:
128: // private Map<OWLClass, Map<OWLDataProperty, Set<IntegrityConstraint>>>
129: // dpConstraints = new HashMap<OWLClass, Map<OWLDataProperty,
130: // Set<IntegrityConstraint>>>();
131:
132: // private Map<OWLObjectProperty,Set<OWLObjectProperty>> inverseProperties =
133: // new HashMap<OWLObjectProperty, Set<OWLObjectProperty>>();
134:
135: private ContextDefinition ctx;
136:
137: public IntegrityConstraintParserImpl(final OWLDataFactory f,
138: final ContextDefinition ctx) {
139: this.ctx = ctx;
140: this.f = f;
141: }
142:
143: public void parse() {
144: for (final OWLAxiom a : ctx.axioms) {
145: a.accept(this);
146: }
147: }
148:
149: private void notSupported(String message, final OWLObject o) {
150: System.out.println(message + " : " + o);
151: }
152:
153: private void notSupported(final OWLObject o) {
154: notSupported("Ignoring Unsupported Axiom", o);
155: }
156:
157: public void visit(OWLAnnotationPropertyRangeAxiom axiom) {
158: notSupported(axiom);
159: }
160:
161: public void visit(OWLAnnotationPropertyDomainAxiom axiom) {
162: notSupported(axiom);
163: }
164:
165: public void visit(OWLSubAnnotationPropertyOfAxiom axiom) {
166: notSupported(axiom);
167: }
168:
169: public void visit(OWLAnnotationAssertionAxiom axiom) {
170: notSupported(axiom);
171: }
172:
173: public void visit(SWRLRule axiom) {
174: notSupported(axiom);
175: }
176:
177: public void visit(OWLDatatypeDefinitionAxiom axiom) {
178: notSupported(axiom);
179: }
180:
181: public void visit(OWLHasKeyAxiom axiom) {
182: notSupported(axiom);
183: }
184:
185: public void visit(OWLInverseObjectPropertiesAxiom axiom) {
186: notSupported(axiom);
187: }
188:
189: public void visit(OWLSubPropertyChainOfAxiom axiom) {
190: notSupported(axiom);
191: }
192:
193: public void visit(OWLSameIndividualAxiom axiom) {
194: notSupported(axiom);
195: }
196:
197: public void visit(OWLInverseFunctionalObjectPropertyAxiom axiom) {
198: notSupported(axiom);
199: }
200:
201: public void visit(OWLSubDataPropertyOfAxiom axiom) {
202: notSupported(axiom);
203: }
204:
205: public void visit(OWLIrreflexiveObjectPropertyAxiom axiom) {
206: notSupported(axiom);
207: }
208:
209: public void visit(OWLTransitiveObjectPropertyAxiom axiom) {
210: notSupported(axiom);
211: }
212:
213: public void visit(OWLDataPropertyAssertionAxiom axiom) {
214: notSupported(axiom);
215: }
216:
217: public void visit(OWLEquivalentClassesAxiom axiom) {
218: notSupported(axiom);
219: }
220:
221: public void visit(OWLClassAssertionAxiom axiom) {
222: notSupported(axiom);
223: }
224:
225: public void visit(OWLEquivalentDataPropertiesAxiom axiom) {
226: notSupported(axiom);
227: }
228:
229: public void visit(OWLFunctionalDataPropertyAxiom axiom) {
230: // ic.addAll(processParticipationConstraint(f.getOWLThing(), f
231: // .getOWLDataMaxCardinality(1, axiom.getProperty())));
232:
233: // processParticipationConstraint(f.getOWLThing(), f
234: // .getOWLDataMaxCardinality(1, axiom.getProperty()));
235: notSupported(axiom);
236: }
237:
238: public void visit(OWLDataPropertyRangeAxiom axiom) {
239: notSupported(axiom);
240: }
241:
242: public void visit(OWLSymmetricObjectPropertyAxiom axiom) {
243: notSupported(axiom);
244: }
245:
246: public void visit(OWLDisjointUnionAxiom axiom) {
247: notSupported(axiom);
248: }
249:
250: public void visit(OWLSubObjectPropertyOfAxiom axiom) {
251: notSupported(axiom);
252: }
253:
254: public void visit(OWLFunctionalObjectPropertyAxiom axiom) {
255: // ic.addAll(processParticipationConstraint(f.getOWLThing(), f
256: // .getOWLObjectMaxCardinality(1, axiom.getProperty())));
257:
258: // processParticipationConstraint(f.getOWLThing(), f
259: // .getOWLObjectMaxCardinality(1, axiom.getProperty()));
260: notSupported(axiom);
261: }
262:
263: public void visit(OWLObjectPropertyAssertionAxiom axiom) {
264: notSupported(axiom);
265: }
266:
267: public void visit(OWLObjectPropertyRangeAxiom axiom) {
268: // ic.addAll(processParticipationConstraint(f.getOWLThing(), f
269: // .getOWLObjectMaxCardinality(1, axiom.getProperty())));
270:
271: OWLObjectProperty op = ensureObjectProperty(axiom.getProperty());
272: OWLClass clz = ensureClass(axiom.getRange());
273: // ObjectRangeConstraint c = orConstraints.get(op);
274: // if (c == null) {
275: // orConstraints.put(op, IntegrityConstraintFactory
276: // .ObjectPropertyRangeConstraint(f.getOWLThing(), op, clz));
277: // } else {
278: // notSupported("Multiple ranges not supported", axiom);
279: // }
280:
281: processParticipationConstraint(f.getOWLThing(),
282: f.getOWLObjectAllValuesFrom(op, clz));
283: }
284:
285: public void visit(OWLDisjointObjectPropertiesAxiom axiom) {
286: notSupported(axiom);
287: }
288:
289: public void visit(OWLDisjointDataPropertiesAxiom axiom) {
290: notSupported(axiom);
291: }
292:
293: public void visit(OWLDifferentIndividualsAxiom axiom) {
294: notSupported(axiom);
295: }
296:
297: public void visit(OWLNegativeDataPropertyAssertionAxiom axiom) {
298: notSupported(axiom);
299: }
300:
301: public void visit(OWLEquivalentObjectPropertiesAxiom axiom) {
302: notSupported(axiom);
303: }
304:
305: public void visit(OWLObjectPropertyDomainAxiom axiom) {
306: // OWLObjectProperty op = ensureObjectProperty(axiom.getProperty());
307: // OWLClass clz = ensureClass(axiom.getDomain());
308: // Set<ObjectDomainConstraint> c = odConstraints.get(op);
309: // if (c == null) {
310: // c = new HashSet<ObjectDomainConstraint>();
311: // odConstraints.put(op, c);
312: // }
313: //
314: // c.add(IntegrityConstraintFactory
315: // .ObjectPropertyDomainConstraint(op, clz));
316: notSupported(axiom);
317: }
318:
319: public void visit(OWLDataPropertyDomainAxiom axiom) {
320: // OWLDataProperty op = ensureDataProperty(axiom.getProperty());
321: // OWLClass clz = ensureClass(axiom.getDomain());
322: // Set<DataDomainConstraint> c = ddConstraints.get(op);
323: // if (c == null) {
324: // c = new HashSet<DataDomainConstraint>();
325: // ddConstraints.put(op, c);
326: // }
327: //
328: // c.add(IntegrityConstraintFactory.DataPropertyDomainConstraint(op,
329: // clz));
330: notSupported(axiom);
331: }
332:
333: public void visit(OWLDisjointClassesAxiom axiom) {
334: notSupported(axiom);
335: }
336:
337: public void visit(OWLReflexiveObjectPropertyAxiom axiom) {
338: notSupported(axiom);
339: }
340:
341: public void visit(OWLAsymmetricObjectPropertyAxiom axiom) {
342: notSupported(axiom);
343: }
344:
345: public void visit(OWLNegativeObjectPropertyAssertionAxiom axiom) {
346: notSupported(axiom);
347: }
348:
349: public void visit(OWLSubClassOfAxiom axiom) {
350: if (!axiom.getSubClass().isAnonymous()
351: && !axiom.getSuperClass().isAnonymous()) {
352: // OWLClass supC = superClasses.get(axiom.getSubClass());
353: // if (supC == null) {
354: // superClasses.put(axiom.getSubClass().asOWLClass(), axiom
355: // .getSuperClass().asOWLClass());
356: // } else {
357: // notSupported(
358: // "Multiple inheritance not allowed in Java OO model",
359: // axiom);
360: // }
361: notSupported(axiom);
362: } else if (!axiom.getSubClass().isAnonymous()) {
363: processParticipationConstraint(axiom.getSubClass().asOWLClass(),
364: axiom.getSuperClass());
365: } else {
366: notSupported(axiom);
367: }
368: }
369:
370: public void visit(final OWLDeclarationAxiom axiom) {
371: axiom.getEntity().accept(new OWLEntityVisitor() {
372:
373: public void visit(OWLAnnotationProperty property) {
374: ctx.annotationProperties.add(property);
375: }
376:
377: public void visit(OWLDatatype datatype) {
378: notSupported(axiom);
379: }
380:
381: public void visit(OWLNamedIndividual individual) {
382: notSupported(axiom);
383: }
384:
385: public void visit(OWLDataProperty property) {
386: ctx.dataProperties.add(property);
387: }
388:
389: public void visit(OWLObjectProperty property) {
390: ctx.objectProperties.add(property);
391: }
392:
393: public void visit(OWLClass cls) {
394: ctx.classes.add(cls);
395: }
396: });
397: }
398:
399: private OWLDatatype ensureDatatype(final OWLDataRange r)
400: throws RuntimeException {
401: if (!r.isDatatype()) {
402: throw new RuntimeException("Data ranges not supported: " + r);
403: }
404:
405: if (!r.asOWLDatatype().isBuiltIn()) {
406: throw new RuntimeException(
407: "Only built in datatypes are supported: " + r);
408: }
409:
410: return r.asOWLDatatype();
411: }
412:
413: private OWLClass ensureClass(final OWLClassExpression r) {
414: if (!r.isAnonymous()) {
415: return r.asOWLClass();
416: }
417: throw new RuntimeException("Only named classes are supported: " + r);
418: }
419:
420: // private void ensureNamedIndividual(final OWLIndividual r)
421: // throws RuntimeException {
422: // if (r.isAnonymous()) {
423: // throw new RuntimeException("Anonymous individuals not supported: "
424: // + r);
425: // }
426: // }
427:
428: private OWLDataProperty ensureDataProperty(final OWLDataPropertyExpression e)
429: throws RuntimeException {
430: if (e.isAnonymous()) {
431: throw new RuntimeException(
432: "Data property expressions not supported: " + e);
433: }
434:
435: return e.asOWLDataProperty();
436: }
437:
438: private OWLObjectProperty ensureObjectProperty(
439: final OWLObjectPropertyExpression e) throws RuntimeException {
440: if (e.isAnonymous()) {
441: throw new RuntimeException(
442: "Object property expressions not supported: " + e);
443: }
444:
445: return e.asOWLObjectProperty();
446: }
447:
448: private void processParticipationConstraint(final OWLClass subjClass,
449: final OWLClassExpression superClass) {
450: Map<OWLObjectProperty, Set<IntegrityConstraint>> setOP2 = opConstraints
451: .get(subjClass);
452: if (setOP2 == null) {
453: setOP2 = new HashMap<OWLObjectProperty, Set<IntegrityConstraint>>();
454: opConstraints.put(subjClass, setOP2);
455: }
456: Map<OWLDataProperty, Set<IntegrityConstraint>> setDP2 = dpConstraints
457: .get(subjClass);
458: if (setDP2 == null) {
459: setDP2 = new HashMap<OWLDataProperty, Set<IntegrityConstraint>>();
460: dpConstraints.put(subjClass, setDP2);
461: }
462:
463: // final Map<OWLObjectProperty, Set<ObjectParticipationConstraint>>
464: // mapOP = setOP2;
465: // final Map<OWLDataProperty, Set<DataParticipationConstraint>> mapDP =
466: // setDP2;
467: final Map<OWLObjectProperty, Set<IntegrityConstraint>> mapOP = setOP2;
468: final Map<OWLDataProperty, Set<IntegrityConstraint>> mapDP = setDP2;
469:
470: final OWLClassExpressionVisitor v = new OWLClassExpressionVisitor() {
471:
472: public void visit(OWLDataMaxCardinality arg0) {
473: final OWLDatatype dt = ensureDatatype(arg0.getFiller());
474: final OWLDataProperty dp = ensureDataProperty(arg0
475: .getProperty());
476:
477: Set<IntegrityConstraint> dpc = mapDP.get(dp);
478: if (dpc == null) {
479: dpc = new HashSet<IntegrityConstraint>();
480: mapDP.put(dp, dpc);
481: }
482:
483: dpc.add(IntegrityConstraintFactory
484: .MaxDataParticipationConstraint(subjClass, dp, dt,
485: arg0.getCardinality()));
486: }
487:
488: public void visit(OWLDataExactCardinality arg0) {
489: final OWLDatatype dt = ensureDatatype(arg0.getFiller());
490: final OWLDataProperty dp = ensureDataProperty(arg0
491: .getProperty());
492:
493: Set<IntegrityConstraint> dpc = mapDP.get(dp);
494: if (dpc == null) {
495: dpc = new HashSet<IntegrityConstraint>();
496: mapDP.put(dp, dpc);
497: }
498:
499: dpc.add(IntegrityConstraintFactory.DataParticipationConstraint(
500: subjClass, dp, dt, arg0.getCardinality(),
501: arg0.getCardinality()));
502: }
503:
504: // private void processDataCardinality(final int minCardinality,
505: // final int maxCardinality, OWLDataProperty p,
506: // final OWLDatatype c) {
507: //
508: // final Set<OWLDatatype> validRanges = new HashSet<OWLDatatype>();
509: //
510: // for (final OWLDatatype cc : o.getDatatypesInSignature()) {
511: // if (r.isEntailed(f.getOWLDataPropertyRangeAxiom(p, cc))) {
512: // validRanges.add(cc);
513: // }
514: // }
515: //
516: // if (validRanges.isEmpty()) {
517: // validRanges.add(c);
518: // }
519: //
520: // // infer cardinality
521: // for (final OWLDatatype cc : validRanges) {
522: // if ((maxCardinality > 1)
523: // && r.isEntailed(f.getOWLSubClassOfAxiom(subjClass,
524: // f.getOWLDataMaxCardinality(1, p
525: // .asOWLDataProperty(), cc)))
526: // || r.isEntailed(f
527: // .getOWLFunctionalDataPropertyAxiom(p
528: // .asOWLDataProperty()))) {
529: //
530: // set.add(IntegrityConstraintFactory
531: // .datatypeParticipationConstraint(subjClass, p,
532: // cc, minCardinality, 1));
533: // } else {
534: // // must be consistent
535: //
536: // set.add(IntegrityConstraintFactory
537: // .datatypeParticipationConstraint(subjClass, p,
538: // cc, minCardinality, maxCardinality));
539: // }
540: // }
541: // }
542:
543: public void visit(OWLDataMinCardinality arg0) {
544: final OWLDatatype dt = ensureDatatype(arg0.getFiller());
545: final OWLDataProperty dp = ensureDataProperty(arg0
546: .getProperty());
547:
548: Set<IntegrityConstraint> dpc = mapDP.get(dp);
549: if (dpc == null) {
550: dpc = new HashSet<IntegrityConstraint>();
551: mapDP.put(dp, dpc);
552: }
553:
554: dpc.add(IntegrityConstraintFactory
555: .MinDataParticipationConstraint(subjClass, dp, dt,
556: arg0.getCardinality()));
557: }
558:
559: public void visit(OWLDataHasValue arg0) {
560: notSupported(arg0);
561: // ensureDataProperty(arg0.getProperty());
562: //
563: // set.add(IntegrityConstraintFactory
564: // .datatypeParticipationConstraint(subjClass, arg0
565: // .getProperty().asOWLDataProperty(), f
566: // .getOWLDataOneOf(arg0.getValue()), 1, 1));
567: }
568:
569: public void visit(OWLDataAllValuesFrom arg0) {
570: OWLDataProperty op = ensureDataProperty(arg0.getProperty());
571: OWLDatatype clz = ensureDatatype(arg0.getFiller());
572:
573: Set<IntegrityConstraint> opc = mapDP.get(op);
574: if (opc == null) {
575: opc = new HashSet<IntegrityConstraint>();
576: mapDP.put(op, opc);
577: }
578: opc.add(IntegrityConstraintFactory.DataPropertyRangeConstraint(
579: subjClass, op, clz));
580: }
581:
582: public void visit(OWLDataSomeValuesFrom arg0) {
583: final OWLDatatype dt = ensureDatatype(arg0.getFiller());
584: final OWLDataProperty dp = ensureDataProperty(arg0
585: .getProperty());
586:
587: Set<IntegrityConstraint> dpc = mapDP.get(dp);
588: if (dpc == null) {
589: dpc = new HashSet<IntegrityConstraint>();
590: mapDP.put(dp, dpc);
591: }
592:
593: dpc.add(IntegrityConstraintFactory
594: .MinDataParticipationConstraint(subjClass, dp, dt, 1));
595: }
596:
597: public void visit(OWLObjectOneOf arg0) {
598: notSupported(arg0);
599: }
600:
601: public void visit(OWLObjectHasSelf arg0) {
602: notSupported(arg0);
603: }
604:
605: public void visit(OWLObjectMaxCardinality arg0) {
606: OWLClass c = ensureClass(arg0.getFiller());
607: OWLObjectProperty p = ensureObjectProperty(arg0.getProperty());
608:
609: Set<IntegrityConstraint> opc = mapOP.get(p);
610: if (opc == null) {
611: opc = new HashSet<IntegrityConstraint>();
612: mapOP.put(p, opc);
613: }
614:
615: opc.add(IntegrityConstraintFactory
616: .MaxObjectParticipationConstraint(subjClass, p, c,
617: arg0.getCardinality()));
618: }
619:
620: public void visit(OWLObjectExactCardinality arg0) {
621: OWLClass c = ensureClass(arg0.getFiller());
622: OWLObjectProperty p = ensureObjectProperty(arg0.getProperty());
623:
624: Set<IntegrityConstraint> opc = mapOP.get(p);
625: if (opc == null) {
626: opc = new HashSet<IntegrityConstraint>();
627: mapOP.put(p, opc);
628: }
629:
630: opc.add(IntegrityConstraintFactory
631: .ObjectParticipationConstraint(subjClass, p, c,
632: arg0.getCardinality(), arg0.getCardinality()));
633: }
634:
635: // private void processObjectMinCardinality(final int cardinality,
636: // OWLObjectProperty p, final OWLClass c) {
637: //
638: // // infer range
639: // final NodeSet<OWLClass> nSet = r.getObjectPropertyRanges(p,
640: // false);
641: //
642: // final Set<OWLClass> validRanges = new HashSet<OWLClass>();
643: //
644: // for (final OWLClass cc : nSet.getFlattened()) {
645: // if (r.isEntailed(f.getOWLSubClassOfAxiom(cc, c))) {
646: // validRanges.add(cc);
647: // }
648: // }
649: //
650: // if (validRanges.isEmpty()) {
651: // validRanges.add(c);
652: // }
653: //
654: // // infer cardinality
655: // for (final OWLClass cc : validRanges) {
656: // if (r.isEntailed(f.getOWLSubClassOfAxiom(subjClass, f
657: // .getOWLObjectMaxCardinality(cardinality, p
658: // .asOWLObjectProperty(), cc)))
659: // || r.isEntailed(f
660: // .getOWLFunctionalObjectPropertyAxiom(p
661: // .asOWLObjectProperty()))) {
662: // set.add(IntegrityConstraintFactory
663: // .classParticipationConstraint(subjClass, p, cc,
664: // cardinality, cardinality));
665: // } else {
666: // // must be consistent
667: // set.add(IntegrityConstraintFactory
668: // .classParticipationConstraint(subjClass, p, cc,
669: // cardinality, Integer.MAX_VALUE));
670: // }
671: // }
672: // }
673:
674: public void visit(OWLObjectMinCardinality arg0) {
675: OWLClass c = ensureClass(arg0.getFiller());
676: OWLObjectProperty p = ensureObjectProperty(arg0.getProperty());
677:
678: Set<IntegrityConstraint> opc = mapOP.get(p);
679: if (opc == null) {
680: opc = new HashSet<IntegrityConstraint>();
681: mapOP.put(p, opc);
682: }
683:
684: opc.add(IntegrityConstraintFactory
685: .MinObjectParticipationConstraint(subjClass, p, c,
686: arg0.getCardinality()));
687: }
688:
689: public void visit(OWLObjectHasValue arg0) {
690: notSupported(arg0);
691: // ensureObjectProperty(arg0.getProperty());
692: // ensureNamedIndividual(arg0.getValue());
693: //
694: // set.add(IntegrityConstraintFactory
695: // .classParticipationConstraint(subjClass, arg0
696: // .getProperty().asOWLObjectProperty(), f
697: // .getOWLObjectOneOf(arg0.getValue()
698: // .asOWLNamedIndividual()), 1, 1));
699: }
700:
701: public void visit(OWLObjectAllValuesFrom arg0) {
702: // System.out.println("Found ICX: " + c);
703: OWLObjectProperty op = ensureObjectProperty(arg0.getProperty());
704: OWLClass clz = ensureClass(arg0.getFiller());
705:
706: Set<IntegrityConstraint> opc = mapOP.get(op);
707: if (opc == null) {
708: opc = new HashSet<IntegrityConstraint>();
709: mapOP.put(op, opc);
710: }
711: opc.add(IntegrityConstraintFactory
712: .ObjectPropertyRangeConstraint(subjClass, op, clz));
713: }
714:
715: public void visit(OWLObjectSomeValuesFrom arg0) {
716: OWLClass c = ensureClass(arg0.getFiller());
717: OWLObjectProperty p = ensureObjectProperty(arg0.getProperty());
718:
719: Set<IntegrityConstraint> opc = mapOP.get(p);
720: if (opc == null) {
721: opc = new HashSet<IntegrityConstraint>();
722: mapOP.put(p, opc);
723: }
724:
725: opc.add(IntegrityConstraintFactory
726: .MinObjectParticipationConstraint(subjClass, p, c, 1));
727: }
728:
729: public void visit(OWLObjectComplementOf arg0) {
730: notSupported(arg0);
731: }
732:
733: public void visit(OWLObjectUnionOf arg0) {
734: notSupported(arg0);
735: }
736:
737: public void visit(OWLObjectIntersectionOf arg0) {
738: for (final OWLClassExpression e : arg0.getOperands()) {
739: e.accept(this);
740: }
741: }
742:
743: public void visit(OWLClass arg0) {
744: notSupported(arg0);
745: }
746: };
747: superClass.accept(v);
748: }
749:
750: // public OWLClass getSuperClass(final OWLClass subClass) {
751: // OWLClass superClass = superClasses.get(subClass);
752: // // if (superClass == null) {
753: // // superClass = f.getOWLThing();
754: // // }
755: // return superClass;
756: // }
757:
758: interface ClassDataPropertyComputer {
759:
760: public Card getCard();
761:
762: public OWLDatatype getFiller();
763:
764: public Set<DataParticipationConstraint> getParticipationConstraints();
765: }
766:
767:
768: public ClassDataPropertyComputer getClassDataPropertyComputer(
769: final OWLClass clazz, final OWLDataProperty prop,
770: final OWLOntology merged) {
771: final Set<IntegrityConstraint> ics = new HashSet<IntegrityConstraint>();
772:
773: final Map<OWLDataProperty, Set<IntegrityConstraint>> constraints = dpConstraints
774: .get(clazz);
775: if (constraints != null && constraints.containsKey(prop)) {
776: ics.addAll(constraints.get(prop));
777: }
778:
779: return new ClassDataPropertyComputer() {
780:
781: public Card getCard() {
782: if (ics.isEmpty()) {
783: return Card.NO;
784: }
785:
786: for (DataParticipationConstraint opc : getParticipationConstraints()) {
787: if (!(clazz.equals(opc.getSubject()) && prop.equals(opc
788: .getPredicate()))) {
789: continue;
790: }
791:
792: OWLDatatype dt1 = getFiller();
793: OWLDatatype dt2 = opc.getObject();
794: if (dt1.equals(dt2)
795: || dt2.equals(OWLManager.getOWLDataFactory()
796: .getTopDatatype())) {
797: if (opc.getMax() == 1) {
798: return Card.ONE;
799: }
800: }
801: }
802: return Card.MULTIPLE;
803: }
804:
805: public OWLDatatype getFiller() {
806: for (final IntegrityConstraint ic : ics) {
807: if (ic instanceof DataRangeConstraint) {
808: return ((DataRangeConstraint) ic).getRange();
809: }
810: }
811:
812: return f.getRDFPlainLiteral(); // f.getTopDatatype();
813: }
814:
815: public Set<DataParticipationConstraint> getParticipationConstraints() {
816: Set<DataParticipationConstraint> set = new HashSet<DataParticipationConstraint>();
817: for (final IntegrityConstraint ic : ics) {
818: if (ic instanceof DataParticipationConstraint) {
819: set.add((DataParticipationConstraint) ic);
820: }
821: }
822:
823: return set;
824: }
825: };
826:
827: }
828:
829: class ClassObjectPropertyComputer {
830:
831: private Card card;
832:
833: private OWLClass object;
834:
835: private Set<ObjectParticipationConstraint> ics;
836:
837: ClassObjectPropertyComputer(final OWLClass clazz, final OWLObjectProperty prop,
838: final OWLOntology merged) {
839: final Map<OWLObjectProperty, Set<IntegrityConstraint>> constraints = opConstraints
840: .get(clazz);
841: ics = new HashSet<>();
842: if (constraints != null && constraints.containsKey(prop)) {
843: OWLClass filler = null;
844: for (final IntegrityConstraint ic : constraints.get(prop)) {
845:
846: if (ic instanceof ObjectParticipationConstraint) {
847: ics.add((ObjectParticipationConstraint) ic);
848: } else if (ic instanceof ObjectRangeConstraint) {
849: filler = ((ObjectRangeConstraint) ic).getRange();
850: }
851: }
852:
853: if (filler == null) {
854: filler = f.getOWLThing();
855: }
856:
857: object = filler;
858:
859: final OWLDataFactory f = merged.getOWLOntologyManager().getOWLDataFactory();
860:
861: if (filler.getSuperClasses(merged).contains(f.getOWLClass(org.semanticweb.owlapi.model.IRI.create(SequencesVocabulary.c_List)))) {
862: object = new ClassObjectPropertyComputer(filler, f.getOWLObjectProperty(org.semanticweb.owlapi.model.IRI.create(SequencesVocabulary.p_element)), merged).getObject();
863: card = Card.LIST;
864: } else if (filler.getSuperClasses(merged).contains(f.getOWLClass(org.semanticweb.owlapi.model.IRI.create(SequencesVocabulary.c_OWLSimpleList)))) {
865: object = new ClassObjectPropertyComputer(filler, f.getOWLObjectProperty(org.semanticweb.owlapi.model.IRI.create(SequencesVocabulary.p_hasNext)), merged).getObject();
866: card = Card.SIMPLELIST; // TODO referenced
867: } else {
868: card = Card.MULTIPLE;
869: for (ObjectParticipationConstraint opc : ics) {
870: OWLClass dt2 = opc.getObject();
871: if (filler.equals(dt2)
872: || dt2.equals(OWLManager.getOWLDataFactory()
873: .getOWLThing())) {
874: if (opc.getMax() == 1) {
875: card = Card.ONE;
876: break;
877: }
878: }
879: }
880: }
881: } else {
882: card = Card.NO;
883: }
884: }
885:
886: public Card getCard() {
887: return card;
888: }
889:
890: public OWLClass getObject() {
891: return object;
892: }
893:
894: public Set<ObjectParticipationConstraint> getParticipationConstraints() {
895: return ics;
896: }
897: }
898: }
899:
900: