From: natile Date: Fri, 20 Sep 2002 14:46:32 +0000 (+0000) Subject: Commit of updates in intersect.ml/mli, mqint.ml, Makefile X-Git-Tag: new_mathql_before_first_merge~33 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=e28b32104f8d3b3ce1c44fdde94d64d02f119287;p=helm.git Commit of updates in intersect.ml/mli, mqint.ml, Makefile --- diff --git a/helm/ocaml/mathql_interpreter/.depend b/helm/ocaml/mathql_interpreter/.depend index 462e69e87..722043c03 100644 --- a/helm/ocaml/mathql_interpreter/.depend +++ b/helm/ocaml/mathql_interpreter/.depend @@ -1,2 +1,4 @@ -mqint.cmo: mqint.cmi -mqint.cmx: mqint.cmi +intersect.cmo: intersect.cmi +intersect.cmx: intersect.cmi +mqint.cmo: intersect.cmi mqint.cmi +mqint.cmx: intersect.cmx mqint.cmi diff --git a/helm/ocaml/mathql_interpreter/Makefile b/helm/ocaml/mathql_interpreter/Makefile index a85693fe8..1ef0ab3fc 100644 --- a/helm/ocaml/mathql_interpreter/Makefile +++ b/helm/ocaml/mathql_interpreter/Makefile @@ -2,9 +2,9 @@ PACKAGE = mathql_interpreter REQUIRES = helm-urimanager postgres unix helm-mathql PREDICATES = -INTERFACE_FILES = mqint.mli +INTERFACE_FILES = intersect.mli mqint.mli -IMPLEMENTATION_FILES = mqint.ml +IMPLEMENTATION_FILES = intersect.ml mqint.ml # $(INTERFACE_FILES:%.mli=%.ml) diff --git a/helm/ocaml/mathql_interpreter/intersect.ml b/helm/ocaml/mathql_interpreter/intersect.ml index bf0d05c2c..9a0f408ef 100644 --- a/helm/ocaml/mathql_interpreter/intersect.ml +++ b/helm/ocaml/mathql_interpreter/intersect.ml @@ -25,40 +25,56 @@ exception NotCompatible;; -(* intersect_attributes is successful iff there is no attribute with *) -(* two different values in the two lists. The returned list is the *) -(* union of the two lists. *) -let rec intersect_attributes (attr1, attr2) = - match attr1, attr2 with - [],_ -> attr2 - | _,[] -> attr1 - | (key1,value1)::tl1, (key2,_)::_ when key1 < key2 -> - (key1,value1)::(intersect_attributes (tl1,attr2)) - | (key1,_)::_, (key2,value2)::tl2 when key2 < key1 -> - (key2,value2)::(intersect_attributes (attr1,tl2)) - | entry1::tl1, entry2::tl2 when entry1 = entry2 -> - entry1::(intersect_attributes (tl1,tl2)) - | _, _ -> raise NotCompatible (* same keys, different values *) +(* Catenates two lists preserving order and getting rid of duplicates *) +let rec append (l1,l2) = + match l1,l2 with + [],_ -> l2 + | _,[] -> l1 + | s1::tl1, s2::_ when s1 < s2 -> s1::append (tl1,l2) + | s1::_, s2::tl2 when s2 < s1 -> s2::append (l1,tl2) + | s1::tl1, s2::tl2 -> s1::append (tl1,tl2) + ;; -(* preserves order and gets rid of duplicates *) -let rec intersect_ex l1 l2 = - let module S = Mathql_semantics in - match (l1, l2) with + +(* 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 gropu 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 *) +;; + +(* Intersection between two resource sets, preserves order and gets rid of duplicates *) +let rec intersect_ex rs1 rs2 = + match (rs1, rs2) 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 + | (uri1,as1)::tl1, + (uri2,as2)::_ when uri1 < uri2 -> intersect_ex tl1 rs2 + | (uri1,as1)::_, + (uri2,as2)::tl2 when uri2 < uri1 -> intersect_ex rs1 tl2 + | (uri1,as1)::tl1, + (uri2,as2)::tl2 -> (uri1, prod(as1,as2))::intersect_ex tl1 tl2 ;; let intersect_ex l1 l2 = diff --git a/helm/ocaml/mathql_interpreter/intersect.mli b/helm/ocaml/mathql_interpreter/intersect.mli index 3b721b4f7..956a05922 100644 --- a/helm/ocaml/mathql_interpreter/intersect.mli +++ b/helm/ocaml/mathql_interpreter/intersect.mli @@ -24,4 +24,4 @@ *) val intersect_ex : - Mathql_semantics.result -> Mathql_semantics.result -> Mathql_semantics.result + MathQL.result -> MathQL.result -> MathQL.result diff --git a/helm/ocaml/mathql_interpreter/mqint.ml b/helm/ocaml/mathql_interpreter/mqint.ml index 02055f727..a0c56e384 100644 --- a/helm/ocaml/mathql_interpreter/mqint.ml +++ b/helm/ocaml/mathql_interpreter/mqint.ml @@ -35,9 +35,9 @@ open Eval;; open Utility;; open Dbconn;; open Pattern;; -open Union;; +open Union;;*) open Intersect;; -open Diff;; +(*open Diff;; open Sortedby;; open Use;; open Select;; @@ -276,12 +276,12 @@ let groups = ref [] (* contesto dei gruppi *) let vvars = ref [] (* contesto delle vvar introdotte con let-in *) -(* valuta una MathQL.set_exp e ritorna un MathQL.resource_set *) let rec exec_set_exp = function - | MathQL.Ref x -> [] - - + | MathQL.Ref vexp -> List.map (fun s -> (s,[])) (exec_val_exp vexp) + | MathQL.Intersect sexp1 sexp2 -> intersect_ex (exec_set_exp sexp1) (exec_set_exp sexp2) + | _ -> assert false + (* valuta una MathQL.boole_exp e ritorna un boole *) and exec_boole_exp = function @@ -289,17 +289,19 @@ and exec_boole_exp = function | MathQL.True -> true | MathQL.Not x -> not (exec_boole_exp x) | MathQL.And (x, y) -> (exec_boole_exp x) && (exec_boole_exp y) - | MathQL.Or (x, y) -> (exec_boole_exp x) || (exec_boole_exp y) - + | MathQL.Or (x, y) -> (exec_boole_exp x) || (exec_boole_exp y) + | _ -> assert false (* valuta una MathQL.val_exp e ritorna un MathQL.value *) and exec_val_exp = function - | MathQL.Const l -> [] - + | MathQL.Const x -> x + | _ -> assert false (* valuta una MathQL.set_exp nel contesto vuoto e ritorna un MathQL.resource_set *) +(* valuta una MathQL.set_exp e ritorna un MathQL.resource_set *) let execute x = - svars := []; rvars := []; groups := []; + svars := []; rvars := []; groups := []; vvars := []; exec_set_exp x +