Skip to content

Method: visit(OWLObjectMaxCardinality)

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 cz.cvut.kbss.jopa.ic.api.IntegrityConstraint;
18: import cz.cvut.kbss.jopa.ic.api.IntegrityConstraintFactory;
19: import cz.cvut.kbss.jopa.ic.impl.IntegrityConstraintFactoryImpl;
20: import java.util.HashSet;
21: import java.util.Set;
22: import org.semanticweb.owlapi.model.OWLClass;
23: import org.semanticweb.owlapi.model.OWLClassExpression;
24: import org.semanticweb.owlapi.model.OWLClassExpressionVisitor;
25: import org.semanticweb.owlapi.model.OWLDataAllValuesFrom;
26: import org.semanticweb.owlapi.model.OWLDataExactCardinality;
27: import org.semanticweb.owlapi.model.OWLDataHasValue;
28: import org.semanticweb.owlapi.model.OWLDataMaxCardinality;
29: import org.semanticweb.owlapi.model.OWLDataMinCardinality;
30: import org.semanticweb.owlapi.model.OWLDataProperty;
31: import org.semanticweb.owlapi.model.OWLDataSomeValuesFrom;
32: import org.semanticweb.owlapi.model.OWLDatatype;
33: import org.semanticweb.owlapi.model.OWLObject;
34: import org.semanticweb.owlapi.model.OWLObjectAllValuesFrom;
35: import org.semanticweb.owlapi.model.OWLObjectComplementOf;
36: import org.semanticweb.owlapi.model.OWLObjectExactCardinality;
37: import org.semanticweb.owlapi.model.OWLObjectHasSelf;
38: import org.semanticweb.owlapi.model.OWLObjectHasValue;
39: import org.semanticweb.owlapi.model.OWLObjectIntersectionOf;
40: import org.semanticweb.owlapi.model.OWLObjectMaxCardinality;
41: import org.semanticweb.owlapi.model.OWLObjectMinCardinality;
42: import org.semanticweb.owlapi.model.OWLObjectOneOf;
43: import org.semanticweb.owlapi.model.OWLObjectProperty;
44: import org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom;
45: import org.semanticweb.owlapi.model.OWLObjectUnionOf;
46: import org.slf4j.Logger;
47: import org.slf4j.LoggerFactory;
48:
49: public class IntegrityConstraintClassParser implements OWLClassExpressionVisitor {
50:
51: private static final Logger log = LoggerFactory.getLogger(IntegrityConstraintClassParser.class);
52:
53: private final Set<IntegrityConstraint> integrityConstraints = new HashSet<>();
54:
55: private OWLClass subjClass;
56:
57: private IntegrityConstraintFactory integrityConstraintFactory = new IntegrityConstraintFactoryImpl();
58:
59: public IntegrityConstraintClassParser(final OWLClass subjClass) {
60: this.subjClass = subjClass;
61: }
62:
63: private static void notSupported(final OWLObject o) {
64: log.info("Ignoring Unsupported Axiom : {}", o);
65: }
66:
67: public Set<IntegrityConstraint> getIntegrityConstraints() {
68: return integrityConstraints;
69: }
70:
71: public void visit(OWLDataMaxCardinality arg0) {
72: try {
73: final OWLDatatype dt = Utils.ensureDatatype(arg0.getFiller());
74: final OWLDataProperty dp = Utils.ensureDataProperty(arg0
75: .getProperty());
76:
77: integrityConstraints.add(integrityConstraintFactory
78: .MaxDataParticipationConstraint(subjClass, dp, dt,
79: arg0.getCardinality()));
80: } catch (UnsupportedICException e) {
81: notSupported(arg0);
82: }
83: }
84:
85: public void visit(OWLDataExactCardinality arg0) {
86: try {
87: final OWLDatatype dt = Utils.ensureDatatype(arg0.getFiller());
88: final OWLDataProperty dp = Utils.ensureDataProperty(arg0
89: .getProperty());
90:
91: integrityConstraints.add(integrityConstraintFactory.DataParticipationConstraint(
92: subjClass, dp, dt, arg0.getCardinality(),
93: arg0.getCardinality()));
94: } catch (UnsupportedICException e) {
95: notSupported(arg0);
96: }
97: }
98:
99: public void visit(OWLDataMinCardinality arg0) {
100: try {
101: final OWLDatatype dt = Utils.ensureDatatype(arg0.getFiller());
102: final OWLDataProperty dp = Utils.ensureDataProperty(arg0
103: .getProperty());
104:
105: integrityConstraints.add(integrityConstraintFactory
106: .MinDataParticipationConstraint(subjClass, dp, dt,
107: arg0.getCardinality()));
108: } catch (UnsupportedICException e) {
109: notSupported(arg0);
110: }
111: }
112:
113: public void visit(OWLDataHasValue arg0) {
114: notSupported(arg0);
115: //IntegrityConstraintParser.ensureDataProperty(arg0.getProperty());
116: //
117: // set.add(IntegrityConstraintFactoryImpl
118: // .datatypeParticipationConstraint(subjClass, arg0
119: // .getProperty().asOWLDataProperty(), f
120: // .getOWLDataOneOf(arg0.getValue()), 1, 1));
121: }
122:
123: public void visit(OWLDataAllValuesFrom arg0) {
124: try {
125: OWLDataProperty op = Utils.ensureDataProperty(arg0.getProperty());
126: OWLDatatype clz = Utils.ensureDatatype(arg0.getFiller());
127:
128: integrityConstraints.add(integrityConstraintFactory.DataPropertyRangeConstraint(
129: subjClass, op, clz));
130: } catch (UnsupportedICException e) {
131: notSupported(arg0);
132: }
133: }
134:
135: public void visit(OWLDataSomeValuesFrom arg0) {
136: try {
137: final OWLDatatype dt = Utils.ensureDatatype(arg0.getFiller());
138: final OWLDataProperty dp = Utils.ensureDataProperty(arg0
139: .getProperty());
140:
141: integrityConstraints.add(integrityConstraintFactory
142: .MinDataParticipationConstraint(subjClass, dp, dt, 1));
143: } catch (UnsupportedICException e) {
144: notSupported(arg0);
145: }
146: }
147:
148: public void visit(OWLObjectOneOf arg0) {
149: notSupported(arg0);
150: }
151:
152: public void visit(OWLObjectHasSelf arg0) {
153: notSupported(arg0);
154: }
155:
156: public void visit(OWLObjectMaxCardinality arg0) {
157: try {
158: OWLClass c = Utils.ensureClass(arg0.getFiller());
159: OWLObjectProperty p = Utils.ensureObjectProperty(arg0.getProperty());
160:
161: integrityConstraints.add(integrityConstraintFactory
162: .MaxObjectParticipationConstraint(subjClass, p, c,
163: arg0.getCardinality()));
164: } catch (UnsupportedICException e) {
165: notSupported(arg0);
166: }
167: }
168:
169: public void visit(OWLObjectExactCardinality arg0) {
170: try {
171: OWLClass c = Utils.ensureClass(arg0.getFiller());
172: OWLObjectProperty p = Utils.ensureObjectProperty(arg0.getProperty());
173:
174: integrityConstraints.add(integrityConstraintFactory
175: .ObjectParticipationConstraint(subjClass, p, c,
176: arg0.getCardinality(), arg0.getCardinality()));
177: } catch (UnsupportedICException e) {
178: notSupported(arg0);
179: }
180: }
181:
182: public void visit(OWLObjectMinCardinality arg0) {
183: try {
184: OWLClass c = Utils.ensureClass(arg0.getFiller());
185: OWLObjectProperty p = Utils.ensureObjectProperty(arg0.getProperty());
186:
187: integrityConstraints.add(integrityConstraintFactory
188: .MinObjectParticipationConstraint(subjClass, p, c,
189: arg0.getCardinality()));
190: } catch (UnsupportedICException e) {
191: notSupported(arg0);
192: }
193: }
194:
195: public void visit(OWLObjectHasValue arg0) {
196: notSupported(arg0);
197: }
198:
199: public void visit(OWLObjectAllValuesFrom arg0) {
200: try {
201: OWLObjectProperty op = Utils.ensureObjectProperty(arg0.getProperty());
202: OWLClass clz = Utils.ensureClass(arg0.getFiller());
203:
204: integrityConstraints.add(integrityConstraintFactory
205: .ObjectPropertyRangeConstraint(subjClass, op, clz));
206: } catch (UnsupportedICException e) {
207: notSupported(arg0);
208: }
209: }
210:
211: public void visit(OWLObjectSomeValuesFrom arg0) {
212: try {
213: OWLClass c = Utils.ensureClass(arg0.getFiller());
214: OWLObjectProperty p = Utils.ensureObjectProperty(arg0.getProperty());
215:
216: integrityConstraints.add(integrityConstraintFactory
217: .MinObjectParticipationConstraint(subjClass, p, c, 1));
218: } catch (UnsupportedICException e) {
219: notSupported(arg0);
220: }
221: }
222:
223: public void visit(OWLObjectComplementOf arg0) {
224: notSupported(arg0);
225: }
226:
227: public void visit(OWLObjectUnionOf arg0) {
228: notSupported(arg0);
229: }
230:
231: public void visit(OWLObjectIntersectionOf arg0) {
232: for (final OWLClassExpression e : arg0.getOperands()) {
233: e.accept(this);
234: }
235: }
236:
237: public void visit(OWLClass arg0) {
238: integrityConstraints.add(integrityConstraintFactory.SubClassConstraint(subjClass, arg0));
239: }
240: }