1
////////////////////////////////////////////////////////////////////////////////
3
// This file is part of Toolkit for Conceptual Modeling (TCM).
4
// (c) copyright 1995, Vrije Universiteit Amsterdam.
5
// Author: Frank Dehne (frank@cs.vu.nl).
7
// TCM is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License as published by
9
// the Free Software Foundation; either version 2 of the License, or
10
// (at your option) any later version.
12
// TCM is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License for more details.
17
// You should have received a copy of the GNU General Public License
18
// along with TCM; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21
////////////////////////////////////////////////////////////////////////////////
26
ERGraph::ERGraph(): Graph() {
29
nodeTypes[i++] = Code::COMMENT;
30
nodeTypes[i++] = Code::ENTITY_TYPE;
31
nodeTypes[i++] = Code::VALUE_TYPE;
32
nodeTypes[i++] = Code::TAXONOMY_JUNCTION;
33
nodeTypes[i++] = Code::RELATIONSHIP_NODE;
36
edgeTypes[j++] = Code::BINARY_RELATIONSHIP;
37
edgeTypes[j++] = Code::FUNCTION;
38
edgeTypes[j++] = Code::EMPTY_EDGE;
39
edgeTypes[j++] = Code::ISA_RELATIONSHIP;
43
Subject *ERGraph::GetGeneralization(Subject *subj) {
44
for (edges->first(); !edges->done(); edges->next()) {
45
Edge *edge = edges->cur();
46
if (edge->GetClassType()==Code::ISA_RELATIONSHIP) {
47
if (edge->GetSubject1() == subj)
48
return edge->GetSubject2();
50
else if (edge->GetClassType()==Code::EMPTY_EDGE) {
51
Subject *junction = 0;
52
if (edge->GetSubject1() == subj)
53
junction = edge->GetSubject2();
54
else if (edge->GetSubject2() == subj)
55
junction = edge->GetSubject1();
57
List<Edge *> edges2 = *edges;
58
for (edges2.first(); !edges2.done(); edges2.next()) {
59
Edge *edge2 = edges2.cur();
60
if (edge2->GetClassType()==Code::ISA_RELATIONSHIP) {
61
if (edge2->GetSubject1() == junction)
62
return edge2->GetSubject2();
71
bool ERGraph::IsaLeaves(Subject *subj) {
72
for (edges->first(); !edges->done(); edges->next()) {
73
Edge *edge = edges->cur();
74
Subject *n1 = edge->GetSubject1();
75
if (n1 == subj && edge->GetClassType()==Code::ISA_RELATIONSHIP) {
82
bool ERGraph::IsaPathExists(Subject *subj1, Subject *subj2) {
84
return IsaPathExists(subj1, subj2, &path);
87
bool ERGraph::IsaPathExists(Subject *subj1, Subject *subj2, List<Edge *> *path) {
88
// should be made more generic !!!
89
for (edges->first(); !edges->done(); edges->next()) {
90
Edge *edge = edges->cur();
91
Subject *n1 = edge->GetSubject1();
92
Subject *n2 = edge->GetSubject2();
95
// is_a: only n1 -> n2.
96
int edgetype = edge->GetClassType();
97
int subj1type = subj1->GetClassType();
98
if (n1 == subj1 && edgetype==Code::ISA_RELATIONSHIP) {
101
else if (edgetype==Code::EMPTY_EDGE &&
102
(subj1type==Code::ENTITY_TYPE||subj1type==Code::CLASS_NODE) &&
103
(n1 == subj1 || n2 == subj1)) {
117
else if (path->find(edge) == -1) {
119
if (IsaPathExists(n2, subj2, path))
122
if (!edges->setcur(edge))
123
error("%s %d: internal graph error\n",
132
void ERGraph::InitConnections () {
133
int ENT = Code::GetIndex(Code::ENTITY_TYPE, nodeTypes);
134
int TAX = Code::GetIndex(Code::TAXONOMY_JUNCTION, nodeTypes);
135
int VAL = Code::GetIndex(Code::VALUE_TYPE, nodeTypes);
136
int REL = Code::GetIndex(Code::RELATIONSHIP_NODE, nodeTypes);
137
int FUN = Code::GetIndex(Code::FUNCTION, edgeTypes);
138
int MAN = Code::GetIndex(Code::BINARY_RELATIONSHIP, edgeTypes);
139
int EMP = Code::GetIndex(Code::EMPTY_EDGE, edgeTypes);
140
int ISA = Code::GetIndex(Code::ISA_RELATIONSHIP, edgeTypes);
142
connections[ENT][ENT][FUN] = True;
143
connections[ENT][ENT][MAN] = True;
144
connections[ENT][ENT][ISA] = True;
146
connections[ENT][VAL][FUN] = True;
147
connections[ENT][TAX][EMP] = True;
149
connections[TAX][ENT][EMP] = True;
150
connections[TAX][ENT][ISA] = True;
152
connections[REL][ENT][FUN] = True;
153
connections[REL][VAL][FUN] = True;