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