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
		Observation.S1_Observation_f = Observation.S2_Observation_f
		Observation.g = 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
		Observation -> O
//		Patient__Person -> P  done because of shorted prefix!
		ObsType__Type -> T
		Gender -> G
		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 answer

G
IDatt
0xM
1?0
2xF
M
IDg2
320
421
521
620
721
822
920
O
IDfg1
10173
11175
12176
13186
14187
15198
16179
P
IDP_att1P_att2h
17xPeterxPete0
18?1xJane1
19xPaul?20
T
IDT_att1T_att2
20xBloodPressurexBloodPressure
21xBodyWeightxBodyWeight
22xHeartRate?3


instance I2Fwd

G
IDatt
0?0
1?1
M
IDg2
212
313
412
513
O
IDfg1
6102
7104
8114
9115
P
IDP_att1P_att2h
10?2xPete0
11?3xJane1
T
IDT_att1T_att2
12?4xBloodPressure
13?5xBodyWeight


instance I1Fwd

G
IDatt
0xF
1xM
M
IDg2
211
312
410
O
IDfg1
592
693
784
P
IDP_att1P_att2h
8xPaul?01
9xPeter?11
T
IDT_att1T_att2
10xHeartRate?2
11xBodyWeight?3
12xBloodPressure?4


instance I2

Method
IDg2
010
111
210
311
Observation
IDfg1
480
582
692
793
Patient
IDatt
8xPete
9xJane
Type
IDatt
10xBloodPressure
11xBodyWeight


instance I1

Gender
IDatt
0xF
1xM
ObsType
IDatt
2xBloodPressure
3xHeartRate
4xBodyWeight
Observation
IDfg
592
694
783
Person
IDatth
8xPaul1
9xPeter1


instance CoProd

G
IDatt
0?0
1xM
2?1
3xF
M
IDg2
422
523
625
722
823
924
1026
O
IDfg1
11184
12196
13187
14207
15208
16219
171910
P
IDP_att1P_att2h
18?2xPete0
19xPeter?31
20?4xJane2
21xPaul?51
T
IDT_att1T_att2
22?6xBloodPressure
23?7xBodyWeight
24xHeartRate?8
25xBodyWeight?9
26xBloodPressure?10


instance E

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