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

Method
IDg2
010
110
211
311
Observation
IDfg1
480
581
692
790
Patient
IDatt
8xPete
9xJane
Type
IDatt
10xBloodPressure
11xBodyWeight


instance I1

Gender
IDatt
0xM
1xF
ObsType
IDatt
2xBloodPressure
3xBodyWeight
4xHeartRate
Observation
IDfg
582
683
794
Person
IDatth
8xPeter0
9xPaul0


instance I2Fwd

G
IDatt
0?0
1?1
M
IDg2
212
312
413
513
O
IDfg1
6102
7103
8114
9112
P
IDP_att2P_att1h
10xPete?20
11xJane?31
T
IDT_att1T_att2
12?4xBloodPressure
13?5xBodyWeight


instance E

G
IDatt
0?0
M
IDg2
O
IDfg1
P
IDP_att2P_att1h
1?1?20
T
IDT_att1T_att2
2?3?4
3?5?6


instance I1Fwd

G
IDatt
0xM
1xF
M
IDg2
210
311
412
O
IDfg1
582
683
794
P
IDP_att2P_att1h
8?0xPeter0
9?1xPaul0
T
IDT_att1T_att2
10xBloodPressure?2
11xBodyWeight?3
12xHeartRate?4


instance CoProd

G
IDatt
0?0
1?1
2xM
3xF
M
IDg2
422
522
623
723
824
925
1026
O
IDfg1
11184
12185
13196
14194
15208
16209
172110
P
IDP_att2P_att1h
18xPete?20
19xJane?31
20?4xPeter2
21?5xPaul2
T
IDT_att1T_att2
22?6xBloodPressure
23?7xBodyWeight
24xBloodPressure?8
25xBodyWeight?9
26xHeartRate?10


instance answer

G
IDatt
0xM
1?0
2xF
M
IDg2
320
420
521
621
720
821
922
O
IDfg1
10173
11174
12185
13183
14177
15178
16199
P
IDP_att2P_att1h
17xPetexPeter0
18xJane?11
19?2xPaul0
T
IDT_att1T_att2
20xBloodPressurexBloodPressure
21xBodyWeightxBodyWeight
22xHeartRate?3