Skip to content

Package: IntegrityConstraintParserImpl$ClassObjectPropertyComputer

IntegrityConstraintParserImpl$ClassObjectPropertyComputer

nameinstructionbranchcomplexitylinemethod
IntegrityConstraintParserImpl.ClassObjectPropertyComputer(IntegrityConstraintParserImpl, OWLClass, OWLObjectProperty, OWLOntology)
M: 44 C: 117
73%
M: 8 C: 16
67%
M: 7 C: 6
46%
M: 8 C: 27
77%
M: 0 C: 1
100%
getCard()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getObject()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getParticipationConstraints()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

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