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