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
+++ /dev/null
-(* 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 ()
-;;
-
+++ /dev/null
-(* 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
+++ /dev/null
-(* 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
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
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
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
| 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 =
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 *)
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))
+
+
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
+++ /dev/null
-(* 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
-;;
-
+++ /dev/null
-(* 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