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
820
922
O
IDfg1
10173
11174
12185
13184
14188
15187
16199
P
IDP_att1P_att2h
17?1xJane1
18xPeterxPete0
19xPaul?20
T
IDT_att1T_att2
20xBodyWeightxBodyWeight
21xBloodPressurexBloodPressure
22xHeartRate?3


instance I2Fwd

G
IDatt
0?0
1?1
M
IDg2
212
313
412
513
O
IDfg1
6102
7103
8113
9115
P
IDP_att1P_att2h
10?2xJane0
11?3xPete1
T
IDT_att1T_att2
12?4xBodyWeight
13?5xBloodPressure


instance I1Fwd

G
IDatt
0xM
1xF
M
IDg2
210
311
412
O
IDfg1
592
683
794
P
IDP_att1P_att2h
8xPaul?00
9xPeter?10
T
IDT_att1T_att2
10xBodyWeight?2
11xHeartRate?3
12xBloodPressure?4


instance I2

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


instance I1

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


instance CoProd

G
IDatt
0xM
1?0
2xF
3?1
M
IDg2
422
523
626
722
823
925
1024
O
IDfg1
11184
12185
13196
14205
15199
16208
172110
P
IDP_att1P_att2h
18?2xJane1
19xPeter?30
20?4xPete3
21xPaul?50
T
IDT_att1T_att2
22?6xBodyWeight
23?7xBloodPressure
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