Skip to content

Method: getParticipationConstraints()

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.DataParticipationConstraint;
18: import cz.cvut.kbss.jopa.ic.api.DataRangeConstraint;
19: import java.util.HashSet;
20: import java.util.Set;
21: import org.semanticweb.owlapi.apibinding.OWLManager;
22: import org.semanticweb.owlapi.model.OWLClass;
23: import org.semanticweb.owlapi.model.OWLDataProperty;
24: import org.semanticweb.owlapi.model.OWLDatatype;
25: import org.semanticweb.owlapi.model.OWLOntology;
26:
27: public class ClassDataPropertyComputer {
28:
29: private Set<DataParticipationConstraint> constraints = new HashSet<>();
30: private OWLDatatype filler;
31: private Card card;
32:
33: public ClassDataPropertyComputer(
34: final OWLClass clazz,
35: final OWLDataProperty prop,
36: final IntegrityConstraintSet set,
37: final OWLOntology ontology
38: ) {
39: set.getClassDataIntegrityConstraints(clazz, prop).forEach(integrityConstraint -> {
40: if (integrityConstraint instanceof DataParticipationConstraint) {
41: this.constraints.add((DataParticipationConstraint) integrityConstraint);
42: } else if (integrityConstraint instanceof DataRangeConstraint) {
43: this.filler = ((DataRangeConstraint) integrityConstraint).getRange();
44: }
45: });
46:
47: if (filler == null) {
48: filler = ontology.getOWLOntologyManager().getOWLDataFactory().getRDFPlainLiteral();
49: }
50:
51: if (constraints.isEmpty()) {
52: card = Card.NO;
53: } else {
54: card = Card.MULTIPLE;
55: for (final DataParticipationConstraint opc : getParticipationConstraints()) {
56: final OWLDatatype dt2 = opc.getObject();
57: if (getFiller().equals(dt2)
58: || dt2.equals(OWLManager.getOWLDataFactory()
59: .getTopDatatype())) {
60: if (opc.getMax() == 1) {
61: card = Card.ONE;
62: return;
63: }
64: }
65: }
66: }
67: }
68:
69: public Card getCard() {
70: return card;
71: }
72:
73: public OWLDatatype getFiller() {
74: return filler;
75: }
76:
77: public Set<DataParticipationConstraint> getParticipationConstraints() {
78: return constraints;
79: }
80:
81: }