Skip to content

Method: lambda$addToClassDataIntegrityConstraintSet$1(OWLClass)

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.*;
18: import org.semanticweb.owlapi.model.OWLClass;
19: import org.semanticweb.owlapi.model.OWLDataProperty;
20: import org.semanticweb.owlapi.model.OWLObjectProperty;
21:
22: import java.util.*;
23:
24: public class IntegrityConstraintSet {
25: private Map<OWLClass, List<IntegrityConstraint>> cConstraints = new HashMap<>();
26: private Map<OWLClass, Map<OWLObjectProperty, Collection<IntegrityConstraint>>> opConstraints = new HashMap<>();
27: private Map<OWLClass, Map<OWLDataProperty, Collection<IntegrityConstraint>>> dpConstraints = new HashMap<>();
28:
29: private static <K, V> void addToMap(final K key, final V value, final Map<K, Collection<V>> map) {
30: if (!map.containsKey(key)) {
31: map.put(key, new HashSet<>());
32: }
33: map.get(key).add(value);
34: }
35:
36: public void addIntegrityConstraint(final IntegrityConstraint ic) {
37: ic.accept(new IntegrityConstraintVisitor() {
38: @Override
39: public void visit(AtomicSubClassConstraint cpc) {
40: List<IntegrityConstraint> setC =
41: cConstraints.computeIfAbsent(cpc.getSubClass(), k -> new ArrayList<>());
42: setC.add(cpc);
43: }
44:
45: @Override
46: public void visit(DataParticipationConstraint cpc) {
47: addToClassDataIntegrityConstraintSet(cpc.getSubject(), cpc.getPredicate(), cpc);
48: }
49:
50: @Override
51: public void visit(ObjectParticipationConstraint cpc) {
52: addToClassObjectIntegrityConstraintSet(cpc.getSubject(), cpc.getPredicate(), cpc);
53: }
54:
55: @Override
56: public void visit(ObjectDomainConstraint cpc) {
57: addToClassObjectIntegrityConstraintSet(cpc.getDomain(), cpc.getProperty(), cpc);
58: }
59:
60: @Override
61: public void visit(ObjectRangeConstraint cpc) {
62: addToClassObjectIntegrityConstraintSet(cpc.getOWLClass(), cpc.getProperty(), cpc);
63: }
64:
65: @Override
66: public void visit(DataDomainConstraint cpc) {
67: addToClassDataIntegrityConstraintSet(cpc.getDomain(), cpc.getProperty(), cpc);
68: }
69:
70: @Override
71: public void visit(DataRangeConstraint cpc) {
72: addToClassDataIntegrityConstraintSet(cpc.getOWLClass(), cpc.getProperty(), cpc);
73: }
74: });
75: }
76:
77: private Map<OWLObjectProperty, Collection<IntegrityConstraint>> addToClassObjectIntegrityConstraintSet(
78: final OWLClass subjClass, final OWLObjectProperty p, final IntegrityConstraint ic) {
79: Map<OWLObjectProperty, Collection<IntegrityConstraint>> map = opConstraints
80: .computeIfAbsent(subjClass, k -> new HashMap<>());
81: addToMap(p, ic, map);
82: return map;
83: }
84:
85: private Map<OWLDataProperty, Collection<IntegrityConstraint>> addToClassDataIntegrityConstraintSet(
86: final OWLClass subjClass, final OWLDataProperty p, final IntegrityConstraint ic) {
87: Map<OWLDataProperty, Collection<IntegrityConstraint>> map = dpConstraints
88: .computeIfAbsent(subjClass, k -> new HashMap<>());
89: addToMap(p, ic, map);
90: return map;
91: }
92:
93: public List<IntegrityConstraint> getClassIntegrityConstraints(final OWLClass cls) {
94: if (cConstraints.containsKey(cls)) {
95: return cConstraints.get(cls);
96: } else {
97: return Collections.emptyList();
98: }
99: }
100:
101: public Collection<IntegrityConstraint> getClassObjectIntegrityConstraints(
102: final OWLClass clazz,
103: final OWLObjectProperty prop) {
104:
105: final Map<OWLObjectProperty, Collection<IntegrityConstraint>> constraints = opConstraints
106: .get(clazz);
107:
108: if (constraints != null && constraints.containsKey(prop)) {
109: return constraints.get(prop);
110: } else {
111: return Collections.emptyList();
112: }
113: }
114:
115: public Collection<IntegrityConstraint> getClassDataIntegrityConstraints(
116: final OWLClass clazz,
117: final OWLDataProperty prop) {
118:
119: final Map<OWLDataProperty, Collection<IntegrityConstraint>> constraints = dpConstraints
120: .get(clazz);
121:
122: if (constraints != null && constraints.containsKey(prop)) {
123: return constraints.get(prop);
124: } else {
125: return Collections.emptyList();
126: }
127: }
128: }