-(* preserves order and gets rid of duplicates *)
-let rec intersect_ex l1 l2 =
- let module S = Mathql_semantics in
- match (l1, l2) with
- [],_
- | _,[] -> []
- | {S.uri = uri1}::tl1,
- {S.uri = uri2}::_ when uri1 < uri2 -> intersect_ex tl1 l2
- | {S.uri = uri1}::_,
- {S.uri = uri2}::tl2 when uri2 < uri1 -> intersect_ex l1 tl2
- | {S.uri = uri1 ; S.attributes = attributes1}::tl1,
- {S.uri = uri2 ; S.attributes = attributes2}::tl2 ->
- try
- let attributes' = intersect_attributes (attributes1,attributes2) in
- {S.uri = uri1 ; S.attributes = attributes' ; S.extra = ""}::(intersect_ex tl1 tl2)
- with
- NotCompatible ->
- intersect_ex tl1 tl2
+
+(* Sums two attribute groups preserving order *)
+let rec sum_groups(gr1, gr2) =
+ match gr1, gr2 with
+ [],_ -> gr2
+ | _,[] -> gr1
+ | (key1,l1)::tl1, (key2,l2)::_ when key1 < key2 -> (key1,l1)::(sum_groups (tl1,gr2))
+ | (key1,l1)::_, (key2,l2)::tl2 when key2 < key1 -> (key2,l2)::(sum_groups (gr1,tl2))
+ | (key1,l1)::tl1, (key2,l2)::tl2 -> (key1,(append (l1,l2)))::(sum_groups (tl1,tl2))
+
+;;
+
+(* Product between an attribute set and a group of attributes *)
+let rec sub_prod (aset, gr) = (*prende un aset e un gr e fa la somma tra tutti i gruppi di aset e gr *)
+ match aset with
+ [] -> []
+ | gr1::tl1 -> sum_groups (gr1, gr)::(sub_prod(tl1, gr))
+;;
+
+
+(* Cartesian product between two attribute sets*)
+let rec prod (as1, as2) =
+ match as1, as2 with
+ [],_ -> as2
+ | _,[] -> as1
+ | gr1::tl1, _ -> (sub_prod (as2, gr1))@(prod (tl1, as2)) (* chiamo la sub_prod con un el. as1 e as2 *)