Skip to content

Method: visit(OWLDataPropertyRangeAxiom)

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.owl2java;
14:
15: import cz.cvut.kbss.jopa.owl2java.exception.UnsupportedICException;
16: import org.semanticweb.owlapi.apibinding.OWLManager;
17: import org.semanticweb.owlapi.model.*;
18: import org.slf4j.Logger;
19: import org.slf4j.LoggerFactory;
20:
21: import java.util.HashMap;
22: import java.util.Map;
23:
24: public class IntegrityConstraintParser implements OWLAxiomVisitor {
25:
26: private static final Logger LOG = LoggerFactory.getLogger(OWL2JavaTransformer.class);
27:
28: private final IntegrityConstraintSet integrityConstraintSet = new IntegrityConstraintSet();
29:
30: private final Map<OWLObjectProperty, OWLClass> opRanges = new HashMap<>();
31: private final Map<OWLDataProperty, OWLDatatype> dpRanges = new HashMap<>();
32:
33: @Override
34: public void visit(OWLAnnotationPropertyRangeAxiom axiom) {
35: notSupported(axiom);
36: }
37:
38: @Override
39: public void visit(OWLAnnotationPropertyDomainAxiom axiom) {
40: notSupported(axiom);
41: }
42:
43: @Override
44: public void visit(OWLSubAnnotationPropertyOfAxiom axiom) {
45: notSupported(axiom);
46: }
47:
48: @Override
49: public void visit(OWLAnnotationAssertionAxiom axiom) {
50: notSupported(axiom);
51: }
52:
53: @Override
54: public void visit(SWRLRule axiom) {
55: notSupported(axiom);
56: }
57:
58: @Override
59: public void visit(OWLDatatypeDefinitionAxiom axiom) {
60: notSupported(axiom);
61: }
62:
63: @Override
64: public void visit(OWLHasKeyAxiom axiom) {
65: notSupported(axiom);
66: }
67:
68: @Override
69: public void visit(OWLInverseObjectPropertiesAxiom axiom) {
70: notSupported(axiom);
71: }
72:
73: @Override
74: public void visit(OWLSubPropertyChainOfAxiom axiom) {
75: notSupported(axiom);
76: }
77:
78: @Override
79: public void visit(OWLSameIndividualAxiom axiom) {
80: notSupported(axiom);
81: }
82:
83: @Override
84: public void visit(OWLInverseFunctionalObjectPropertyAxiom axiom) {
85: notSupported(axiom);
86: }
87:
88: @Override
89: public void visit(OWLSubDataPropertyOfAxiom axiom) {
90: notSupported(axiom);
91: }
92:
93: @Override
94: public void visit(OWLIrreflexiveObjectPropertyAxiom axiom) {
95: notSupported(axiom);
96: }
97:
98: @Override
99: public void visit(OWLTransitiveObjectPropertyAxiom axiom) {
100: notSupported(axiom);
101: }
102:
103: @Override
104: public void visit(OWLDataPropertyAssertionAxiom axiom) {
105: notSupported(axiom);
106: }
107:
108: @Override
109: public void visit(OWLEquivalentClassesAxiom axiom) {
110: notSupported(axiom);
111: }
112:
113: @Override
114: public void visit(OWLClassAssertionAxiom axiom) {
115: notSupported(axiom);
116: }
117:
118: @Override
119: public void visit(OWLEquivalentDataPropertiesAxiom axiom) {
120: notSupported(axiom);
121: }
122:
123: @Override
124: public void visit(OWLFunctionalDataPropertyAxiom axiom) {
125: // ic.addAll(processParticipationConstraint(f.getOWLThing(), f
126: // .getOWLDataMaxCardinality(1, axiom.getProperty())));
127:
128: // processParticipationConstraint(f.getOWLThing(), f
129: // .getOWLDataMaxCardinality(1, axiom.getProperty()));
130: notSupported(axiom);
131: }
132:
133: @Override
134: public void visit(OWLDataPropertyRangeAxiom axiom) {
135: try {
136: OWLDataProperty op = Utils.ensureDataProperty(axiom.getProperty());
137: OWLDatatype clz = Utils.ensureDatatype(axiom.getRange());
138:
139: dpRanges.put(op, clz);
140: } catch (UnsupportedICException e) {
141: notSupported(axiom);
142: }
143: }
144:
145: @Override
146: public void visit(OWLSymmetricObjectPropertyAxiom axiom) {
147: notSupported(axiom);
148: }
149:
150: @Override
151: public void visit(OWLDisjointUnionAxiom axiom) {
152: notSupported(axiom);
153: }
154:
155: @Override
156: public void visit(OWLSubObjectPropertyOfAxiom axiom) {
157: notSupported(axiom);
158: }
159:
160: @Override
161: public void visit(OWLFunctionalObjectPropertyAxiom axiom) {
162: // ic.addAll(processParticipationConstraint(f.getOWLThing(), f
163: // .getOWLObjectMaxCardinality(1, axiom.getProperty())));
164:
165: // processParticipationConstraint(f.getOWLThing(), f
166: // .getOWLObjectMaxCardinality(1, axiom.getProperty()));
167: notSupported(axiom);
168: }
169:
170: @Override
171: public void visit(OWLObjectPropertyAssertionAxiom axiom) {
172: notSupported(axiom);
173: }
174:
175: @Override
176: public void visit(OWLObjectPropertyRangeAxiom axiom) {
177: try {
178: OWLObjectProperty op = Utils.ensureObjectProperty(axiom.getProperty());
179: OWLClass clz = Utils.ensureClass(axiom.getRange());
180:
181: opRanges.put(op, clz);
182: // processSubClassConstraintCandidate(f.getOWLThing(),
183: // OWLManager.getOWLDataFactory().getOWLObjectAllValuesFrom(op, clz));
184: } catch (UnsupportedICException e) {
185: notSupported(axiom);
186: }
187: }
188:
189: @Override
190: public void visit(OWLDisjointObjectPropertiesAxiom axiom) {
191: notSupported(axiom);
192: }
193:
194: @Override
195: public void visit(OWLDisjointDataPropertiesAxiom axiom) {
196: notSupported(axiom);
197: }
198:
199: @Override
200: public void visit(OWLDifferentIndividualsAxiom axiom) {
201: notSupported(axiom);
202: }
203:
204: @Override
205: public void visit(OWLNegativeDataPropertyAssertionAxiom axiom) {
206: notSupported(axiom);
207: }
208:
209: @Override
210: public void visit(OWLEquivalentObjectPropertiesAxiom axiom) {
211: notSupported(axiom);
212: }
213:
214: @Override
215: public void visit(OWLObjectPropertyDomainAxiom axiom) {
216: // OWLObjectProperty op = ensureObjectProperty(axiom.getProperty());
217: // OWLClass clz = ensureClass(axiom.getDomain());
218: // Set<ObjectDomainConstraint> c = odConstraints.get(op);
219: // if (c == null) {
220: // c = new HashSet<ObjectDomainConstraint>();
221: // odConstraints.put(op, c);
222: // }
223: //
224: // c.add(IntegrityConstraintFactoryImpl
225: // .ObjectPropertyDomainConstraint(op, clz));
226: notSupported(axiom);
227: }
228:
229: @Override
230: public void visit(OWLDataPropertyDomainAxiom axiom) {
231: // OWLDataProperty op = ensureDataProperty(axiom.getProperty());
232: // OWLClass clz = ensureClass(axiom.getDomain());
233: // Set<DataDomainConstraint> c = ddConstraints.get(op);
234: // if (c == null) {
235: // c = new HashSet<DataDomainConstraint>();
236: // ddConstraints.put(op, c);
237: // }
238: //
239: // c.add(IntegrityConstraintFactoryImpl.DataPropertyDomainConstraint(op,
240: // clz));
241: notSupported(axiom);
242: }
243:
244: @Override
245: public void visit(OWLDisjointClassesAxiom axiom) {
246: notSupported(axiom);
247: }
248:
249: @Override
250: public void visit(OWLReflexiveObjectPropertyAxiom axiom) {
251: notSupported(axiom);
252: }
253:
254: @Override
255: public void visit(OWLAsymmetricObjectPropertyAxiom axiom) {
256: notSupported(axiom);
257: }
258:
259: @Override
260: public void visit(OWLNegativeObjectPropertyAssertionAxiom axiom) {
261: notSupported(axiom);
262: }
263:
264: @Override
265: public void visit(OWLSubClassOfAxiom axiom) {
266: try {
267: if (!axiom.getSubClass().isAnonymous()) {
268: processSubClassConstraintCandidate(axiom.getSubClass().asOWLClass(), axiom.getSuperClass());
269: } else {
270: notSupported(axiom);
271: }
272: } catch (UnsupportedICException e) {
273: notSupported(axiom);
274: }
275: }
276:
277: @Override
278: public void visit(final OWLDeclarationAxiom axiom) {
279: notSupported(axiom);
280: // axiom.getEntity().accept(new OWLEntityVisitor() {
281: //
282: // public void visit(OWLAnnotationProperty property) {
283: // ctx.annotationProperties.add(property);
284: // }
285: //
286: // public void visit(OWLDatatype datatype) {
287: // notSupported(axiom);
288: // }
289: //
290: // public void visit(OWLNamedIndividual individual) {
291: // notSupported(axiom);
292: // }
293: //
294: // public void visit(OWLDataProperty property) {
295: // ctx.dataProperties.add(property);
296: // }
297: //
298: // public void visit(OWLObjectProperty property) {
299: // ctx.objectProperties.add(property);
300: // }
301: //
302: // public void visit(OWLClass cls) {
303: // ctx.classes.add(cls);
304: // }
305: // });
306: }
307:
308: private static void notSupported(final OWLObject o) {
309: LOG.info("Ignoring Unsupported Axiom : {}", o);
310: }
311:
312: private void processSubClassConstraintCandidate(final OWLClass subjClass,
313: final OWLClassExpression superClass) {
314: final IntegrityConstraintClassParser icp = new IntegrityConstraintClassParser(subjClass);
315: superClass.accept(icp);
316:
317: for (Map.Entry<OWLObjectProperty, OWLClass> entry : opRanges.entrySet()) {
318: final OWLObjectProperty property = entry.getKey();
319: if (superClass.signature().anyMatch(e -> e.equals(property))) {
320: OWLManager.getOWLDataFactory().getOWLObjectAllValuesFrom(property, entry.getValue()).accept(icp);
321: }
322: }
323: for (Map.Entry<OWLDataProperty, OWLDatatype> entry : dpRanges.entrySet()) {
324: final OWLDataProperty property = entry.getKey();
325: if (superClass.signature().anyMatch(e -> e.equals(property))) {
326: OWLManager.getOWLDataFactory().getOWLDataAllValuesFrom(property, entry.getValue()).accept(icp);
327: }
328: }
329: icp.getIntegrityConstraints().forEach(integrityConstraintSet::addIntegrityConstraint);
330: }
331:
332: public IntegrityConstraintSet getClassIntegrityConstraintSet() {
333: return integrityConstraintSet;
334: }
335: }