X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;ds=sidebyside;f=helm%2Focaml%2Fmathql_interpreter%2Fuse.ml;h=f5648cab1763c4ee957f9eb450c486d0c5130227;hb=eddba0cc1b08d5d787793095c5fb0d39ee5ec2f7;hp=cb65699e970c3955067b633c0ca4689028ea7213;hpb=8abd42ec1af0d5daef1d026ec550b49b07de8340;p=helm.git diff --git a/helm/ocaml/mathql_interpreter/use.ml b/helm/ocaml/mathql_interpreter/use.ml index cb65699e9..f5648cab1 100644 --- a/helm/ocaml/mathql_interpreter/use.ml +++ b/helm/ocaml/mathql_interpreter/use.ml @@ -20,7 +20,7 @@ * MA 02111-1307, USA. * * For details, see the HELM World-Wide-Web page, - * http://cs.unibo.it/helm/. + * http://www.cs.unibo.it/helm/. *) (* @@ -44,71 +44,47 @@ open Dbconn;; * output: string list list; lista su cui e' stato eseguito il * comando USE/USED BY *) -let use_ex alist asvar usek = +let get_prop_id prop = + if prop="refObj" then "F" + else if prop="backPointer" then "B" + else assert false + ;; + + +let relation_ex rop path rset attl = + let usek = get_prop_id (List.hd path) in + +let _ = print_string ("RELATION "^usek) +and t = Sys.time () in +let result = let c = pgc () in - List.fold_left - (fun parziale xres -> - let r1 = helm_property_id usek - and r2 = helm_property_id "position" - and r3 = helm_property_id "occurrence" - in - let qq = "select distinct t" ^ r3 ^ ".att1, t" ^ r2 ^ ".att1 " ^ - "from t" ^ r3 ^ ", t" ^ r2 ^ ", t" ^ r1 ^ " " ^ - "where " ^ "t" ^ r1 ^ ".att0 = '" ^ (List.hd xres) ^ "' and t" ^ r1 ^ - ".att1 = t" ^ r2 ^ ".att0 and t" ^ r1 ^ ".att1 = t" ^ r3 ^ - ".att0" - in - (*let _ = print_endline ("use: " ^ qq) in*) - let res = c#exec qq in - parziale - @ - if not (List.mem asvar (List.tl (List.hd alist))) then - List.map - (fun l -> [List.hd l] @ List.tl xres @ List.tl l) - res#get_list - else - List.map - (fun l -> - let t = - match xres with - hd::tl -> (List.hd l)::tl - | [] -> [] - in - List.map - snd - (Utility.set_assoc - asvar - (List.hd (List.tl l)) - (List.combine (List.hd alist) t) - ) - ) - (List.find_all - (fun l -> - let currv = - List.hd (List.tl l) - and xresv = - try ( - List.assoc - asvar - (List.combine - (List.tl (List.hd alist)) - (List.tl xres) - ) - ) with - Not_found -> "" - in - xresv = "" or xresv = currv - ) - res#get_list - ) + Sort.list + (fun (uri1-> uri1 < uri2) + (List.fold_left + (fun parziale (uri,aset)-> + print_string uri ; + let tv = + pgresult_to_string + (c#exec ("select id from registry where uri='" ^ uri ^ "'")) + in + let qq = + "select uri, context from t" ^ tv ^ " where prop_id='" ^ usek ^ + "' order by uri asc" + in + let res = c#exec qq in + (List.map + (function + [uri;context] -> {S.uri = uri ; S.attributes = [asvar, context] ; S.extra = ""} + | _ -> assert false + ) res#get_list + ) @ + parziale + ) [] rset ) - [ (List.hd alist) - @ - if not (List.mem asvar (List.tl (List.hd alist))) then - [asvar] - else - [] - ] - (List.tl alist) +in +print_string (" = " ^ string_of_int (List.length result) ^ ": ") ; +print_endline (string_of_float (Sys.time () -. t) ^ "s") ; +flush stdout ; + result ;;