Skip to content

Method: visit(OWLDataSomeValuesFrom)

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