example PharmaColim2
schema S1 = literal : sql {
entities
Observation Person Gender ObsType
foreign_keys
f: Observation -> Person
h: Person -> Gender
g: Observation -> ObsType
attributes
att: Person -> String
att: Gender -> String
att: ObsType -> String
}
schema S2 = literal : sql {
entities
Observation Patient Method Type
foreign_keys
f : Observation -> Patient
g1: Observation -> Method
g2: Method -> Type
attributes
att: Patient -> String
att: Type -> String
}
#####################################/
#compute the canonical schema colimit
schema_colimit ColimAuto = quotient S1 + S2 : sql {
entity_equations
S1.Observation = S2.Observation
S1.Person = S2.Patient
S1.ObsType = S2.Type
path_equations
S1_Observation.S1_Observation_f = S1_Observation.S2_Observation_f
S1_Observation.g = S1_Observation.g1.g2
options
simplify_names = true
}
#just for fun
schema_colimit Coproduct = coproduct S1 + S2 : sql
#####################################/
#use a different, less verbose colimit constructed manually
schema_colimit Colim = modify ColimAuto {
rename entities
S1_Observation -> O
Person -> P
ObsType -> T
S1_Gender -> G
S2_Method -> M
rename foreign_keys
O.S1_Observation_f -> f
rename attributes
T.ObsType_att -> T_att1
#G.Gender_att -> G_att
P.Person_att -> P_att1
T.Type_att -> T_att2
P.Patient_att -> P_att2
remove foreign_keys
O.S2_Observation_f -> f
O.g -> g1.g2
# e.g. remove attributes
# B_att -> lambda x. x.T_att1
}
#####################################/
instance I1 = literal : S1 {
generators
one two three : Observation
Peter Paul : Person
M F :Gender
BloodPressure BodyWeight HeartRate: ObsType
equations
Peter.att = xPeter Paul.att = xPaul
M.att = xM F.att = xF
BloodPressure.att = xBloodPressure
BodyWeight.att = xBodyWeight
HeartRate.att = xHeartRate
one.f = Peter two.f = Peter three.f = Paul
Peter.h = M Paul.h = M
one.g = BloodPressure two.g = BodyWeight three.g = HeartRate
}
instance I2 = literal : S2 {
generators
o1 o2 o3 o4 : Observation
Pete Jane : Patient
m1 m2 m3 m4 : Method
BP Wt : Type
equations
Pete.att = xPete Jane.att = xJane
BP.att = xBloodPressure Wt.att = xBodyWeight
o1.f = Pete o2.f = Pete o3.f = Jane o4.f = Jane
o1.g1 = m1 o2.g1 = m2 o3.g1 = m3 o4.g1 = m1
m1.g2 = BP m2.g2 = BP m3.g2 = Wt m4.g2 = Wt
}
instance I1Fwd = sigma (getMapping Colim S1) I1
instance I2Fwd = sigma (getMapping Colim S2) I2
instance CoProd = literal : getSchema Colim {
imports I1Fwd I2Fwd
}
instance E = literal : getSchema Colim {
generators
P : P
B W : T
}
transform a1 = literal : E -> CoProd {
generators
P -> Peter
B -> BloodPressure
W -> BodyWeight
}
transform a2 = literal : E -> CoProd {
generators
P -> Pete
B -> BP
W -> Wt
}
instance answer = coequalize a1 a2
Keywords:
modify
schema_literal
quotient
sigma
instance_literal
coequalize
transform_literal
Options:
simplify_names
instance I2
ObservationID | f | g1 |
---|
4 | 8 | 0 |
5 | 8 | 1 |
6 | 9 | 2 |
7 | 9 | 0 |
TypeID | att |
---|
10 | xBloodPressure |
11 | xBodyWeight |
instance I1
ObsTypeID | att |
---|
2 | xBloodPressure |
3 | xBodyWeight |
4 | xHeartRate |
PersonID | att | h |
---|
8 | xPeter | 0 |
9 | xPaul | 0 |
instance I2Fwd
PID | P_att2 | P_att1 | h |
---|
10 | xPete | ?2 | 0 |
11 | xJane | ?3 | 1 |
TID | T_att1 | T_att2 |
---|
12 | ?4 | xBloodPressure |
13 | ?5 | xBodyWeight |
instance E
TID | T_att1 | T_att2 |
---|
2 | ?3 | ?4 |
3 | ?5 | ?6 |
instance I1Fwd
PID | P_att2 | P_att1 | h |
---|
8 | ?0 | xPeter | 0 |
9 | ?1 | xPaul | 0 |
TID | T_att1 | T_att2 |
---|
10 | xBloodPressure | ?2 |
11 | xBodyWeight | ?3 |
12 | xHeartRate | ?4 |
instance CoProd
MID | g2 |
---|
4 | 22 |
5 | 22 |
6 | 23 |
7 | 23 |
8 | 24 |
9 | 25 |
10 | 26 |
OID | f | g1 |
---|
11 | 18 | 4 |
12 | 18 | 5 |
13 | 19 | 6 |
14 | 19 | 4 |
15 | 20 | 8 |
16 | 20 | 9 |
17 | 21 | 10 |
PID | P_att2 | P_att1 | h |
---|
18 | xPete | ?2 | 0 |
19 | xJane | ?3 | 1 |
20 | ?4 | xPeter | 2 |
21 | ?5 | xPaul | 2 |
TID | T_att1 | T_att2 |
---|
22 | ?6 | xBloodPressure |
23 | ?7 | xBodyWeight |
24 | xBloodPressure | ?8 |
25 | xBodyWeight | ?9 |
26 | xHeartRate | ?10 |
instance answer
MID | g2 |
---|
3 | 20 |
4 | 20 |
5 | 21 |
6 | 21 |
7 | 20 |
8 | 21 |
9 | 22 |
OID | f | g1 |
---|
10 | 17 | 3 |
11 | 17 | 4 |
12 | 18 | 5 |
13 | 18 | 3 |
14 | 17 | 7 |
15 | 17 | 8 |
16 | 19 | 9 |
PID | P_att2 | P_att1 | h |
---|
17 | xPete | xPeter | 0 |
18 | xJane | ?1 | 1 |
19 | ?2 | xPaul | 0 |
TID | T_att1 | T_att2 |
---|
20 | xBloodPressure | xBloodPressure |
21 | xBodyWeight | xBodyWeight |
22 | xHeartRate | ?3 |