From: Ferruccio Guidi Date: Mon, 18 Nov 2002 12:34:51 +0000 (+0000) Subject: structurated attribute names added X-Git-Tag: V_0_0_5~39 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=856dc227c9781439a31d03f5b68d32a41db63ab9;p=helm.git structurated attribute names added --- diff --git a/helm/ocaml/mathql/mQueryTParser.mly b/helm/ocaml/mathql/mQueryTParser.mly index 1228155e6..7bc2f97bf 100644 --- a/helm/ocaml/mathql/mQueryTParser.mly +++ b/helm/ocaml/mathql/mQueryTParser.mly @@ -53,7 +53,7 @@ and an_boole = function | M.False -> [] | M.True -> [] - | M.Ex _ _ -> [] + | M.Ex _ -> [] | M.Not x -> an_boole x | M.And (x, y) -> join (an_boole x) (an_boole y) | M.Or (x, y) -> join (an_boole x) (an_boole y) @@ -107,28 +107,28 @@ | STR CM strs { $1 :: $3 } | STR { [$1] } ; - vvars: - | vvar CM vvars { $1 :: $3 } - | vvar { [$1] } + subpath: + | STR SL subpath { $1 :: $3 } + | STR { [$1] } ; path: - | STR SL path { $1 :: $3 } - | STR { [$1] } - ; - ref: - | SUB { MathQL.SubOp } - | SUPER { MathQL.SuperOp } - | { MathQL.ExactOp } - ; + | STR SL subpath { ($1, $3) } + | STR { ($1, []) } + ; inv: | INV { true } | { false } ; + ref: + | SUB { MathQL.RefineSub } + | SUPER { MathQL.RefineSuper } + | { MathQL.RefineExact } + ; val_exp: | STR { MathQL.Const [$1] } | FUN STR val_exp { MathQL.Fun ($2, $3) } | ATTRIB inv ref path val_exp { MathQL.Attribute ($2, $3, $4, $5) } - | rvar FS vvar { MathQL.Record ($1, $3) } + | rvar FS path { MathQL.Record ($1, $3) } | vvar { MathQL.VVar $1 } | LC strs RC { MathQL.Const $2 } | LC RC { MathQL.Const [] } @@ -152,7 +152,7 @@ | PAT val_exp { MathQL.Pattern $2 } | LP set_exp RP { $2 } | SELECT rvar IN set_exp WHERE boole_exp { MathQL.Select ($2, $4, $6) } - | REL inv ref path set_exp ATTR vvars { MathQL.Relation ($2, $3, $4, $5, $7) } + | REL inv ref path set_exp ATTR strs { MathQL.Relation ($2, $3, $4, $5, $7) } | REL inv ref path set_exp { MathQL.Relation ($2, $3, $4, $5, []) } | svar { MathQL.SVar $1 } | rvar { MathQL.RVar $1 } @@ -166,8 +166,8 @@ | set_exp EOF { $1 } ; attr: - | STR IS strs { ($1, $3) } - | STR { ($1, []) } + | path IS strs { ($1, $3) } + | path { ($1, []) } ; attrs: | attr SC attrs { $1 :: $3 } @@ -187,7 +187,7 @@ resources: | resource SC resources { $1 :: $3 } | resource { [$1] } - | { [] } + | { [] } ; result: | resources EOF { $1 } diff --git a/helm/ocaml/mathql/mQueryUtil.ml b/helm/ocaml/mathql/mQueryUtil.ml index 09759cc45..75e587229 100644 --- a/helm/ocaml/mathql/mQueryUtil.ml +++ b/helm/ocaml/mathql/mQueryUtil.ml @@ -41,7 +41,10 @@ let rec txt_list f s = function | [a] -> f a | a :: tail -> f a ^ s ^ txt_list f s tail -let txt_qstr s = "\"" ^ s ^ "\"" +let txt_str s = "\"" ^ s ^ "\"" + +let txt_path (p0, p1) = + txt_str p0 ^ (if p1 <> [] then "/" ^ txt_list txt_str "/" p1 else "") let text_of_query x = let module M = MathQL in @@ -50,17 +53,17 @@ let text_of_query x = let txt_vvar vv = "$" ^ vv in let txt_inv i = if i then "inverse " else "" in let txt_ref = function - | M.ExactOp -> "" - | M.SubOp -> "sub " - | M.SuperOp -> "super " + | M.RefineExact -> "" + | M.RefineSub -> "sub " + | M.RefineSuper -> "super " in - let txt_refpath i r p = txt_inv i ^ txt_ref r ^ txt_list txt_qstr "/" p ^ " " in + let txt_refpath i r p = txt_inv i ^ txt_ref r ^ txt_path p ^ " " in let rec txt_val = function - | M.Const [s] -> txt_qstr s - | M.Const l -> "{" ^ txt_list txt_qstr ", " l ^ "}" + | M.Const [s] -> txt_str s + | M.Const l -> "{" ^ txt_list txt_str ", " l ^ "}" | M.VVar vv -> txt_vvar vv - | M.Record (rv, vv) -> txt_rvar rv ^ "." ^ txt_vvar vv - | M.Fun (s, x) -> "fun " ^ txt_qstr s ^ " " ^ txt_val x + | M.Record (rv, p) -> txt_rvar rv ^ "." ^ txt_path p + | M.Fun (s, x) -> "fun " ^ txt_str s ^ " " ^ txt_val x | M.Attribute (i, r, p, x) -> "attribute " ^ txt_refpath i r p ^ txt_val x | M.RefOf x -> "refof " ^ txt_set x and txt_boole = function @@ -78,7 +81,7 @@ let text_of_query x = | M.SVar sv -> txt_svar sv | M.RVar rv -> txt_rvar rv | M.Relation (i, r, p, x, []) -> "relation " ^ txt_refpath i r p ^ txt_set x - | M.Relation (i, r, p, x, l) -> "relation " ^ txt_refpath i r p ^ txt_set x ^ " attr " ^ txt_list txt_vvar ", " l + | M.Relation (i, r, p, x, l) -> "relation " ^ txt_refpath i r p ^ txt_set x ^ " attr " ^ txt_list txt_str ", " l | M.Union (x, y) -> "(" ^ txt_set x ^ " union " ^ txt_set y ^ ")" | M.Intersect (x, y) -> "(" ^ txt_set x ^ " intersect " ^ txt_set y ^ ")" | M.Diff (x, y) -> "(" ^ txt_set x ^ " diff " ^ txt_set y ^ ")" @@ -92,13 +95,13 @@ let text_of_query x = let text_of_result x sep = let txt_attr = function - | (s, []) -> txt_qstr s - | (s, l) -> txt_qstr s ^ "=" ^ txt_list txt_qstr ", " l + | (p, []) -> txt_path p + | (p, l) -> txt_path p ^ " = " ^ txt_list txt_str ", " l in let txt_group l = "{" ^ txt_list txt_attr "; " l ^ "}" in let txt_res = function - | (s, []) -> txt_qstr s - | (s, l) -> txt_qstr s ^ " attr " ^ txt_list txt_group ", " l + | (s, []) -> txt_str s + | (s, l) -> txt_str s ^ " attr " ^ txt_list txt_group ", " l in let txt_set l = txt_list txt_res ("; " ^ sep) l ^ sep in txt_set x diff --git a/helm/ocaml/mathql/mathQL.ml b/helm/ocaml/mathql/mathQL.ml index 71682f2a0..04eb3b32d 100644 --- a/helm/ocaml/mathql/mathQL.ml +++ b/helm/ocaml/mathql/mathQL.ml @@ -35,6 +35,25 @@ (******************************************************************************) +(* output data structures ***************************************************) + +type path = string * (string list) (* the name of an attribute *) + +type value = string list (* the value of an attribute *) + +type attribute = path * value (* an attribute *) + +type attribute_group = attribute list (* a group of attributes *) + +type attribute_set = attribute_group list (* the attributes of an URI *) + +type resource = string * attribute_set (* an attributed URI *) + +type resource_set = resource list (* the query result *) + +type result = resource_set + + (* input data structures ****************************************************) type svar = string (* the name of a variable for a resource set *) @@ -43,19 +62,17 @@ type rvar = string (* the name of a variable for a resource *) type vvar = string (* the name of a variable for an attribute value *) -type refine_op = ExactOp - | SubOp - | SuperOp +type inverse = bool -type path = string list - -type vvar_list = vvar list +type refine = RefineExact + | RefineSub + | RefineSuper type set_exp = SVar of svar | RVar of rvar | Ref of val_exp | Pattern of val_exp - | Relation of bool * refine_op * path * set_exp * vvar_list + | Relation of inverse * refine * path * set_exp * string list | Select of rvar * set_exp * boole_exp | Union of set_exp * set_exp | Intersect of set_exp * set_exp @@ -75,26 +92,9 @@ and boole_exp = False and val_exp = Const of string list | RefOf of set_exp - | Record of rvar * vvar + | Record of rvar * path | VVar of vvar - | Attribute of bool * refine_op * path * val_exp + | Attribute of inverse * refine * path * val_exp | Fun of string * val_exp type query = set_exp - - -(* output data structures ***************************************************) - -type value = string list (* the value of an attribute *) - -type attribute = string * value (* an attribute *) - -type attribute_group = attribute list (* a group of attributes *) - -type attribute_set = attribute_group list (* the attributes of an URI *) - -type resource = string * attribute_set (* an attributed URI *) - -type resource_set = resource list (* the query result *) - -type result = resource_set diff --git a/helm/ocaml/mathql_interpreter/attribute.ml b/helm/ocaml/mathql_interpreter/attribute.ml index 46b8eae9b..1a72f1e81 100644 --- a/helm/ocaml/mathql_interpreter/attribute.ml +++ b/helm/ocaml/mathql_interpreter/attribute.ml @@ -36,7 +36,7 @@ open Intersect;; *) let rec attribute_ex rop path inv = function [] -> [] - | s::tl -> let tab = List.hd path in + | s::tl -> let tab = fst path in if inv then let res = let c = pgc () in diff --git a/helm/ocaml/mathql_interpreter/attribute.mli b/helm/ocaml/mathql_interpreter/attribute.mli index 149d6fcff..841db1b48 100644 --- a/helm/ocaml/mathql_interpreter/attribute.mli +++ b/helm/ocaml/mathql_interpreter/attribute.mli @@ -23,5 +23,5 @@ * http://cs.unibo.it/helm/. *) -val attribute_ex: MathQL.refine_op -> MathQL.path -> bool -> MathQL.value -> MathQL.value +val attribute_ex: MathQL.refine -> MathQL.path -> bool -> MathQL.value -> MathQL.value diff --git a/helm/ocaml/mathql_interpreter/mqint.ml b/helm/ocaml/mathql_interpreter/mqint.ml index c67d11d15..bbaeec0b5 100644 --- a/helm/ocaml/mathql_interpreter/mqint.ml +++ b/helm/ocaml/mathql_interpreter/mqint.ml @@ -125,14 +125,14 @@ let rec exec_set_exp c = function if ! dbname = postgres_db then (let res = relation_ex rop path (exec_set_exp c sexp) attl in if ! stat then - (print_string ("RELATION " ^ (List.hd path) ^ " = " ^ string_of_int(List.length res) ^ ": "); + (print_string ("RELATION " ^ (fst path) ^ " = " ^ string_of_int(List.length res) ^ ": "); print_endline (string_of_float (Sys.time() -. before) ^ "s"); flush stdout); res) else (let res = relation_galax_ex rop path (exec_set_exp c sexp) attl in if !stat then - (print_string ("RELATION-GALAX " ^ (List.hd path) ^ " = " ^ string_of_int(List.length res) ^ ": "); + (print_string ("RELATION-GALAX " ^ (fst path) ^ " = " ^ string_of_int(List.length res) ^ ": "); print_endline (string_of_float (Sys.time() -. before) ^ "s"); flush stdout); res) diff --git a/helm/ocaml/mathql_interpreter/relation.ml b/helm/ocaml/mathql_interpreter/relation.ml index 94dc10870..57b89122e 100644 --- a/helm/ocaml/mathql_interpreter/relation.ml +++ b/helm/ocaml/mathql_interpreter/relation.ml @@ -39,7 +39,7 @@ open Utility;; let get_prop_id propl = - let prop = List.hd propl in + let prop = fst propl in if prop="refObj" then "F" else if prop="backPointer" then "B" else assert false @@ -47,8 +47,6 @@ let get_prop_id propl = let relation_ex rop path rset attl = - if path = [] then [] - else let usek = get_prop_id path in let vvar = if attl = [] then "position" else List.hd attl @@ -61,7 +59,7 @@ let relation_ex rop path rset attl = let res = c#exec qq in (List.map (function - [uri;context] -> [(uri,[[(vvar,[context])]])] + [uri;context] -> [(uri,[[((vvar, []),[context])]])] | _ -> assert false ) res#get_list) @ acc ) @@ -103,20 +101,18 @@ let tofname uri = let rec rsetl uril vvar = match uril with | uri::tl -> let scuri = (*tofname*) uri in - [(scuri, [[(vvar, [(List.hd tl)])]])]::(rsetl (List.tl tl) vvar) + [(scuri, [[((vvar, []), [(List.hd tl)])]])]::(rsetl (List.tl tl) vvar) | [] -> [] (* prende una resource e una vvar e restituisce la lista delle resource in relazione (refObj o backPointer in base al parametro "path") con tale resource e associa alla proprieta' il nome della vvar contenuto in "attl" *) let muse path attl r = - if path = [] then [] - else let vvar = if attl = [] then "position" else List.hd attl in let uri = fst r in let furi = tofname uri in - let dtag = List.hd path in + let dtag = fst path in let dir = match dtag with "refObj" -> "/projects/helm/metadata/create4/forward" diff --git a/helm/ocaml/mathql_interpreter/relation.mli b/helm/ocaml/mathql_interpreter/relation.mli index aa7c75509..4a9d181e1 100644 --- a/helm/ocaml/mathql_interpreter/relation.mli +++ b/helm/ocaml/mathql_interpreter/relation.mli @@ -24,7 +24,7 @@ *) val relation_ex : - MathQL.refine_op -> MathQL.path -> MathQL.resource_set -> MathQL.vvar_list -> MathQL.resource_set + MathQL.refine -> MathQL.path -> MathQL.resource_set -> string list -> MathQL.resource_set val relation_galax_ex : - MathQL.refine_op -> MathQL.path -> MathQL.resource_set -> MathQL.vvar_list -> MathQL.resource_set + MathQL.refine -> MathQL.path -> MathQL.resource_set -> string list -> MathQL.resource_set