From cef7b3b104313195d378890cd79656e5640eebec Mon Sep 17 00:00:00 2001 From: natile Date: Mon, 21 Oct 2002 16:54:47 +0000 Subject: [PATCH] Switching interpreter. --- helm/ocaml/mathql_interpreter/Makefile | 2 +- helm/ocaml/mathql_interpreter/letin.ml | 65 -------------- helm/ocaml/mathql_interpreter/letin.mli | 28 ------ .../mathql_interpreter/mathql_semantics.ml | 34 ------- helm/ocaml/mathql_interpreter/mqint.ml | 37 +++++--- helm/ocaml/mathql_interpreter/mqint.mli | 2 +- helm/ocaml/mathql_interpreter/relation.ml | 73 +++++++++++++++ helm/ocaml/mathql_interpreter/relation.mli | 3 + helm/ocaml/mathql_interpreter/use.ml | 90 ------------------- helm/ocaml/mathql_interpreter/use.mli | 27 ------ 10 files changed, 105 insertions(+), 256 deletions(-) delete mode 100644 helm/ocaml/mathql_interpreter/letin.ml delete mode 100644 helm/ocaml/mathql_interpreter/letin.mli delete mode 100644 helm/ocaml/mathql_interpreter/mathql_semantics.ml delete mode 100644 helm/ocaml/mathql_interpreter/use.ml delete mode 100644 helm/ocaml/mathql_interpreter/use.mli diff --git a/helm/ocaml/mathql_interpreter/Makefile b/helm/ocaml/mathql_interpreter/Makefile index cd63e8ab4..5328d04d2 100644 --- a/helm/ocaml/mathql_interpreter/Makefile +++ b/helm/ocaml/mathql_interpreter/Makefile @@ -1,5 +1,5 @@ PACKAGE = mathql_interpreter -REQUIRES = helm-urimanager postgres unix helm-mathql +REQUIRES = helm-urimanager postgres unix natile-galax helm-mathql PREDICATES = INTERFACE_FILES = dbconn.mli utility.mli union.mli relation.mli diff.mli meet.mli sub.mli intersect.mli func.mli mqint.mli diff --git a/helm/ocaml/mathql_interpreter/letin.ml b/helm/ocaml/mathql_interpreter/letin.ml deleted file mode 100644 index 160a7a164..000000000 --- a/helm/ocaml/mathql_interpreter/letin.ml +++ /dev/null @@ -1,65 +0,0 @@ -(* 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 LETIN e REF - *) - -open MathQL;; - -let letin_pool = ref None;; - -let see_pool () = - match !letin_pool with - None -> print_endline "None" - | Some c -> List.iter (fun elem -> print_endline (fst elem)) c -;; - -let letin_ex rvar alist = - let _ = - match !letin_pool with - Some pool -> letin_pool := Some ((rvar,alist)::(List.remove_assoc rvar pool)) - | None -> letin_pool := Some ([(rvar,alist)]) - in -(* let _ = see_pool () in*) - [] -;; - -let letref_ex rvar = - match !letin_pool with - None -> [] - | Some pool -> - ( - try - List.assoc rvar pool - with - Not_found -> [] - ) -;; - -let letdispose () = - let _ = letin_pool = ref None in () -;; - diff --git a/helm/ocaml/mathql_interpreter/letin.mli b/helm/ocaml/mathql_interpreter/letin.mli deleted file mode 100644 index d221ddd2e..000000000 --- a/helm/ocaml/mathql_interpreter/letin.mli +++ /dev/null @@ -1,28 +0,0 @@ -(* 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/. - *) - -val letin_ex : MathQL.mqlvar -> Mathql_semantics.result -> Mathql_semantics.result -val letref_ex : MathQL.mqlvar -> Mathql_semantics.result -val letdispose : unit -> unit diff --git a/helm/ocaml/mathql_interpreter/mathql_semantics.ml b/helm/ocaml/mathql_interpreter/mathql_semantics.ml deleted file mode 100644 index 49896a220..000000000 --- a/helm/ocaml/mathql_interpreter/mathql_semantics.ml +++ /dev/null @@ -1,34 +0,0 @@ -(* 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/. - *) - -(* attributes are sorted w.r.t. their name in increasing order *) -type attributed_uri = - { uri: string ; attributes : (MathQL.mqsvar * string) list ; extra : string} - -type attributed_uri_env = - (MathQL.mqrvar * attributed_uri) list - -(* invariant: the result is ordered on the uri component of every item *) -type result = attributed_uri list diff --git a/helm/ocaml/mathql_interpreter/mqint.ml b/helm/ocaml/mathql_interpreter/mqint.ml index e1dc6f8d9..01fbc1de1 100644 --- a/helm/ocaml/mathql_interpreter/mqint.ml +++ b/helm/ocaml/mathql_interpreter/mqint.ml @@ -43,13 +43,16 @@ open Diff;; open Relation;; open Func;; + +exception BooleExpTrue + let init connection_param = Dbconn.init connection_param let close () = Dbconn.close () -let check () = Dbconn.pgc () - -exception BooleExpTrue +let check () = + let status = Dbconn.pgc () + in () let stat = ref false @@ -57,6 +60,10 @@ let set_stat b = stat := b let get_stat () = ! stat +let dbname = ref "db-postgres" + +let set_database db = dbname := db + (* valuta una MathQL.set_exp e ritorna un MathQL.resource_set *) let rec exec_set_exp c = function @@ -106,12 +113,22 @@ let rec exec_set_exp c = function res | MathQL.Relation (rop, path, sexp, attl) -> let before = Sys.time() in - 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_endline (string_of_float (Sys.time() -. before) ^ "s"); - flush stdout); - res + if !dbname = "db-postgres" 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_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_endline (string_of_float (Sys.time() -. before) ^ "s"); + flush stdout); + res) + + | MathQL.Select (rvar, sexp, bexp) -> let before = Sys.time() in let rset = (exec_set_exp c sexp) in @@ -181,7 +198,7 @@ and exec_val_exp c = function | MathQL.VVar s -> List.assoc s c.vvars | MathQL.RefOf sexp -> List.map (fun (s,_) -> s) (exec_set_exp c sexp) | MathQL.Fun (s, vexp) -> fun_ex s (exec_val_exp c vexp) - | _ -> assert false + | MathQL.Attribute (rop, path, vexp) -> [] (* valuta una MathQL.set_exp nel contesto vuoto e ritorna un MathQL.resource_set *) and execute x = diff --git a/helm/ocaml/mathql_interpreter/mqint.mli b/helm/ocaml/mathql_interpreter/mqint.mli index e969e5c66..f6f8827c6 100644 --- a/helm/ocaml/mathql_interpreter/mqint.mli +++ b/helm/ocaml/mathql_interpreter/mqint.mli @@ -29,7 +29,7 @@ val execute : MathQL.query -> MathQL.result (* execute query *) val close : unit -> unit (* close database *) -val check : unit -> Postgres.connection (* check connection *) +val check : unit -> unit (* check connection *) val set_stat : bool -> unit (* set stat emission *) diff --git a/helm/ocaml/mathql_interpreter/relation.ml b/helm/ocaml/mathql_interpreter/relation.ml index 159369ad2..94dc10870 100644 --- a/helm/ocaml/mathql_interpreter/relation.ml +++ b/helm/ocaml/mathql_interpreter/relation.ml @@ -74,3 +74,76 @@ let relation_ex rop path rset attl = in edup rset_list ;; + + + +(**** IMPLEMENTAZIONE DELLA RELATION PER GALAX ****) + + +(* trasforma un uri in un filename *) +let tofname uri = + if String.contains uri ':' then + (let len = String.length uri in + let scuri = String.sub uri 4 (len-4) in (*tolgo cic:*) + if String.contains scuri '#' then + (let pos = String.index scuri '#' in + let s1 = Str.string_before scuri pos in + let xp = Str.string_after scuri pos in + let xp = Str.global_replace (Str.regexp "#xpointer(1") "" xp in + let xp = Str.global_replace (Str.regexp "\/") "," xp in + let xp = Str.global_replace (Str.regexp ")") "" xp in + let fname = (s1 ^ xp) in + fname) + else + scuri) + else uri + + +(* prende una lista di uri (contenente alternativamente uri e pos) e costruisce una lista di resource *) +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) + | [] -> [] + + +(* 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 dir = + match dtag with + "refObj" -> "/projects/helm/metadata/create4/forward" + | _ -> "/projects/helm/metadata/create4/backward" + in + let xq ="namespace h=\"http://www.cs.unibo.it/helm/schemas/mattone.rdf#\" + namespace rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" + for $i in document(" ^ "\"" ^ dir ^ furi ^ ".xml" ^ "\"" ^ + ")/rdf:RDF/h:Object/h:" ^ dtag ^ "/h:Occurrence + return ($i/h:occurrence, $i/h:position)" + + in + let uril = Toputils.eval_query_string xq in (* e' una lista di liste di stringhe*) + let hd_uril = List.hd uril in(*prendo la testa che contiene altern. lista di uri e pos. *) + let rset_list = rsetl hd_uril vvar in (* da hd_uril costruisco una lista di resource_set(singoletti)*) + let rec edup = function + [] -> [] + | rs1::tl -> union_ex rs1 (edup tl) + in + edup rset_list + + + + +(* prende un resource_set, una vvar (primo el. di attl) a cui associare la posizione, e la relazione (refObj o backPointer) e per ogni resource chiama la muse +NOTA: "rop" per ora non viene usato perche' vale sempre "ExactOp" *) +let relation_galax_ex rop path rset attl = + List.stable_sort (fun (uri1,l1) (uri2,l2) -> compare uri1 uri2) (List.concat (List.map (muse path attl) rset)) + + diff --git a/helm/ocaml/mathql_interpreter/relation.mli b/helm/ocaml/mathql_interpreter/relation.mli index 392d670cf..aa7c75509 100644 --- a/helm/ocaml/mathql_interpreter/relation.mli +++ b/helm/ocaml/mathql_interpreter/relation.mli @@ -25,3 +25,6 @@ val relation_ex : MathQL.refine_op -> MathQL.path -> MathQL.resource_set -> MathQL.vvar_list -> MathQL.resource_set + +val relation_galax_ex : + MathQL.refine_op -> MathQL.path -> MathQL.resource_set -> MathQL.vvar_list -> MathQL.resource_set diff --git a/helm/ocaml/mathql_interpreter/use.ml b/helm/ocaml/mathql_interpreter/use.ml deleted file mode 100644 index f5648cab1..000000000 --- a/helm/ocaml/mathql_interpreter/use.ml +++ /dev/null @@ -1,90 +0,0 @@ -(* 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 - *) - -open Utility;; -open Dbconn;; - -(* - * implementazione dei comandi USE/USED BY - * - * parametri: - * alist: string list list; lista su cui eseguire il comando USE/USED BY - * asvar: string; nome della variabile del comando use - * usek: string; nome della tabella in cui ricercare le occorrenze; - * la distinzione fra l'esecuzione del comando USE e USED BY - * sta nell'utilizzo della tabella 'backPointer' per USE - * e 'refObj' per USED BY - * - * output: string list list; lista su cui e' stato eseguito il - * comando USE/USED BY - *) -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 - 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 - ) -in -print_string (" = " ^ string_of_int (List.length result) ^ ": ") ; -print_endline (string_of_float (Sys.time () -. t) ^ "s") ; -flush stdout ; - result -;; - diff --git a/helm/ocaml/mathql_interpreter/use.mli b/helm/ocaml/mathql_interpreter/use.mli deleted file mode 100644 index 0572ad5ac..000000000 --- a/helm/ocaml/mathql_interpreter/use.mli +++ /dev/null @@ -1,27 +0,0 @@ -(* 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://cs.unibo.it/helm/. - *) - -val use_ex : - Mathql_semantics.result -> MathQL.mqsvar -> string -> Mathql_semantics.result -- 2.39.2