Skip to content

Method: getCard()

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.ObjectParticipationConstraint;
18: import cz.cvut.kbss.jopa.ic.api.ObjectRangeConstraint;
19: import cz.cvut.kbss.jopa.model.SequencesVocabulary;
20: import java.util.Collection;
21: import java.util.HashSet;
22: import org.semanticweb.owlapi.apibinding.OWLManager;
23: import org.semanticweb.owlapi.model.IRI;
24: import org.semanticweb.owlapi.model.OWLClass;
25: import org.semanticweb.owlapi.model.OWLDataFactory;
26: import org.semanticweb.owlapi.model.OWLObjectProperty;
27: import org.semanticweb.owlapi.model.OWLOntology;
28:
29: public class ClassObjectPropertyComputer {
30:
31: private Collection<ObjectParticipationConstraint> constraints = new HashSet<>();
32: private OWLClass filler;
33: private Card card;
34:
35: public ClassObjectPropertyComputer(final OWLClass clazz,
36: final OWLObjectProperty prop,
37: final IntegrityConstraintSet set,
38: final OWLOntology merged
39: ) {
40: set.getClassObjectIntegrityConstraints(clazz, prop).forEach(ic -> {
41: if (ic instanceof ObjectParticipationConstraint) {
42: constraints.add((ObjectParticipationConstraint) ic);
43: } else if (ic instanceof ObjectRangeConstraint) {
44: filler = ((ObjectRangeConstraint) ic).getRange();
45: }
46: });
47:
48: if (filler == null) {
49: filler = merged.getOWLOntologyManager().getOWLDataFactory().getOWLThing();
50: }
51:
52: if (constraints.isEmpty()) {
53: card = Card.NO;
54: } else {
55: final OWLDataFactory f = merged.getOWLOntologyManager().getOWLDataFactory();
56:
57: final OWLClass object = filler;
58:
59: if (object.getSuperClasses(merged).contains(
60: f.getOWLClass(IRI.create(SequencesVocabulary.c_List)))) {
61: this.filler = new ClassObjectPropertyComputer(object,
62: f.getOWLObjectProperty(IRI.create(SequencesVocabulary.p_element)),
63: set,
64: merged
65: )
66: .getFiller();
67: card = Card.LIST;
68: } else if (filler.getSuperClasses(merged).contains(
69: f.getOWLClass(IRI.create(SequencesVocabulary.c_OWLSimpleList)))) {
70: this.filler = new ClassObjectPropertyComputer(object,
71: f.getOWLObjectProperty(IRI.create(SequencesVocabulary.p_hasNext)),
72: set,
73: merged
74: )
75: .getFiller();
76: card = Card.SIMPLELIST; // TODO referenced
77: } else {
78: card = Card.MULTIPLE;
79: for (ObjectParticipationConstraint opc : constraints) {
80: OWLClass dt2 = opc.getObject();
81: if (filler.equals(dt2)
82: || dt2.equals(OWLManager.getOWLDataFactory()
83: .getOWLThing())) {
84: if (opc.getMax() == 1) {
85: card = Card.ONE;
86: break;
87: }
88: }
89: }
90: }
91: }
92: }
93:
94: public Card getCard() {
95: return card;
96: }
97:
98: public OWLClass getFiller() {
99: return filler;
100: }
101:
102: public Collection<ObjectParticipationConstraint> getParticipationConstraints() {
103: return constraints;
104: }
105: }