X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Focaml%2Fmathql_interpreter%2Fuse.ml;h=93ed9a8a4a722e1ca329fd803fa57386271d12f3;hb=69ecdb3f3ec94440f1736b5e0247f2ced2e5b2c6;hp=f1ac7c779eff2b3b1771c3c83b71b4efa396bcbc;hpb=6a1d05b388683befc860b48b4f2bbaf42f58a112;p=helm.git diff --git a/helm/ocaml/mathql_interpreter/use.ml b/helm/ocaml/mathql_interpreter/use.ml index f1ac7c779..93ed9a8a4 100644 --- a/helm/ocaml/mathql_interpreter/use.ml +++ b/helm/ocaml/mathql_interpreter/use.ml @@ -1,3 +1,27 @@ +(* Copyright (C) 2000, HELM Team. + * + * This file is part of HELM, an Hypertextual, Electronic + * Library of Mathematics, developed at the Computer Science + * Department, University of Bologna, Italy. + * + * HELM is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * HELM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with HELM; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA. + * + * For details, see the HELM World-Wide-Web page, + * http://www.cs.unibo.it/helm/. + *) (* * implementazione dei comandi USE/USED BY @@ -19,115 +43,89 @@ open Dbconn;; * * output: string list list; lista su cui e' stato eseguito il * comando USE/USED BY - * - * TODO - * USE e USED BY sono identici dal punto di vista algoritmico, per questo - * sono stati accorpati in una sola funzione; stilisticamente, sarebbe meglio - * avere due implementazioni distinte... *) let use_ex alist asvar usek = + (*(*let _ = print_string ("USE ") + and t = Unix.time () in*) + let result = + let c = pgc () + in + [ (List.hd alist) @ [asvar] ] + @ + Sort.list + (fun l m -> List.hd l < List.hd m) + (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 order by t" ^ r3 ^ ".att1 asc"*) + let tv = pgresult_to_string (c#exec ("select id from registry where uri='" ^ (List.hd xres) ^ "'")) in + let _ = print_endline ("DEBUG (use.ml): " ^ tv) in + let qq = "select uri, context from t" ^ tv ^ " where back_for='" ^ usek ^ "'" in + let res = c#exec qq in + (List.map + (fun l -> [List.hd l] @ List.tl xres @ List.tl l) + res#get_list + ) + @ + parziale + ) + [] + (List.tl alist) + ) + in + (*let _ = print_endline (string_of_float (Unix.time () -. t)); flush stdout in*) + + *) +let module S = Mathql_semantics in +let _ = print_string ("USE ") +and t = Unix.time () in +let result = let c = pgc () in - List.fold_left - (fun parziale xres -> - let r1 = pgresult_to_string (c#exec - ("select att0 from property where att2='" ^ usek ^ "'")) - and r2 = pgresult_to_string (c#exec - "select att0 from property where att2='position'") - and r3 = pgresult_to_string (c#exec - "select att0 from property where att2='occurrence'") - in - let res = c#exec ( - "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") + Sort.list + (fun {S.uri = uri1} {S.uri = uri2} -> uri1 < uri2) + (List.fold_left + (fun parziale {S.uri = uri ; S.attributes = attributes} -> + print_string uri ; + (* RSSDB + let r1 = helm_property_id usek + and r2 = helm_property_id "position" + and r3 = helm_property_id "occurrence" 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 - ) + 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 order by t" ^ r3 ^ ".att1 asc" + *) + 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 + ) [] alist ) - [ (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 (Unix.time () -. t) ^ "s") ; +flush stdout ; + result ;; -(** TEST **) - -(* -let use_ex alist asvar = - if (List.find_all asvar (List.tl (List.hd alist))) = [] then - use_ex_nc alist asvar - else - use_ex_co alist asvar -;; - -List.map - (fun l -> - let t = - match xres with - hd::tl -> (List.hd l)::tl - | [] -> [] - in - let hash = List.combine (List.hd alist) t in - snd (set_assoc asvar (snd l) hash) - ) - (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 - ) -;; -*)