Skip to content

Method: visit(OWLSubClassOfAxiom)

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