X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Focaml%2Fmathql_interpreter%2Fmqint.ml;h=3a0a5fb310b277a4729a36d5da17e30b144c9209;hb=b6992cac4c9ffa80337e5e11e5017b0b9b17c65e;hp=c78465aa7c5f315346f9ddfca51a9afde1790f8d;hpb=2ef44e8d1a908a08d31e6114c15898ae7dc8109e;p=helm.git diff --git a/helm/ocaml/mathql_interpreter/mqint.ml b/helm/ocaml/mathql_interpreter/mqint.ml index c78465aa7..3a0a5fb31 100644 --- a/helm/ocaml/mathql_interpreter/mqint.ml +++ b/helm/ocaml/mathql_interpreter/mqint.ml @@ -26,7 +26,7 @@ (* * implementazione del'interprete MathQL *) -open Mathql;; +open MathQL;; open Eval;; open Utility;; open Dbconn;; @@ -37,6 +37,9 @@ open Diff;; open Sortedby;; open Use;; open Select;; +open Letin;; + +let prop_pool = ref None;; let fi_to_string fi = match fi with @@ -55,39 +58,83 @@ let fi_to_string fi = ")" ;; +let see_prop_pool () = + let _ = print_endline "eccomi" in + List.iter + (fun elem -> print_endline (fst elem ^ ": " ^ snd elem)) + (match !prop_pool with Some l -> l | _ -> print_endline "ciao"; assert false) +;; + (* * inizializzazione della connessione al database *) -let init () = Dbconn.init ();; +let init () = + let _ = Dbconn.init () in + let c = pgc () in + let res = + c#exec "select name,id from property where ns_id in (select id from namespace where url='http://www.cs.unibo.it/helm/schemas/mattone.rdf#')" + in + prop_pool := Some + ( + List.map + (function + a::b::_ -> (a, b) + | _ -> print_endline "no"; assert false + ) + res#get_list + ) +;; -(* - * esecuzione di una query - * - * parametri: - * q - * - * output: string list list; risultato internto formato da uri + contesto. - *) -let rec execute_ex q = - match q with +let get_prop_id prop = + if prop="refObj" then "F" + else if prop="backPointer" then "B" + else List.assoc prop (match !prop_pool with Some l -> l | _ -> assert false) +;; + +(* execute_ex env q *) +(* [env] is the attributed uri environment in which the query [q] *) +(* must be evaluated *) +(* [q] is the query to evaluate *) +(* It returns a [Mathql_semantics.result] *) +let rec execute_ex env = + function MQSelect (apvar, alist, abool) -> - select_ex apvar (execute_ex alist) abool + select_ex env apvar (execute_ex env alist) abool | MQUsedBy (alist, asvar) -> - use_ex (execute_ex alist) asvar "F" (*"refObj"*) + use_ex (execute_ex env alist) asvar (get_prop_id "refObj") (* "F" (*"refObj"*) *) | MQUse (alist, asvar) -> - use_ex (execute_ex alist) asvar "B" (*"backPointer"*) + use_ex (execute_ex env alist) asvar (get_prop_id "backPointer") (* "B" (*"backPointer"*) *) | MQPattern (apreamble, apattern, afragid) -> - pattern_ex apreamble apattern afragid + pattern_ex (apreamble, apattern, afragid) | MQUnion (l1, l2) -> - union_ex (execute_ex l1) (execute_ex l2) + union_ex (execute_ex env l1) (execute_ex env l2) | MQDiff (l1, l2) -> - diff_ex (execute_ex l1) (execute_ex l2) + diff_ex (execute_ex env l1) (execute_ex env l2) | MQSortedBy (l, o, f) -> - sortedby_ex (execute_ex l) o f + sortedby_ex (execute_ex env l) o f | MQIntersect (l1, l2) -> - intersect_ex (execute_ex l1) (execute_ex l2) + intersect_ex (execute_ex env l1) (execute_ex env l2) + | MQListRVar rvar -> [List.assoc rvar env] + | MQLetIn (lvar, l1, l2) -> + let t = Unix.time () in + let res = + (*CSC: The interesting code *) + let _ = letin_ex lvar (execute_ex env l1) in + execute_ex env l2 + (*CSC: end of the interesting code *) + in + letdispose (); + print_string ("LETIN = " ^ string_of_int (List.length res) ^ ": ") ; + print_endline (string_of_float (Unix.time () -. t) ^ "s") ; + flush stdout ; + res + | MQListLVar lvar -> + letref_ex lvar ;; +(* Let's initialize the execute in Select, creating a cyclical recursion *) +Select.execute := execute_ex;; + (* * converte il risultato interno di una query (uri + contesto) * in un risultato di sole uri @@ -119,57 +166,61 @@ let rec execute_ex q = * la uri puo' far parte del risultato. *) let xres_to_res l = - let tmp = List.map List.hd (List.tl l) in + MQRefs (List.map (function {Mathql_semantics.uri = uri} -> uri) l) +(* + let tmp = List.map (function {Mathql_semantics.uri = uri} -> uri) l in MQRefs (List.map (function l -> - match Str.split (Str.regexp ":\|#\|/") l with - hd::tl -> ( + (*let _ = print_endline ("DEBUG: (mqint.ml: xres_to_res)" ^ l) in*) + match Str.split (Str.regexp ":\|#\|/\|(\|)") l with + hd::""::tl -> ( match List.rev tl with - ")"::n::"xpointer(1"::tail -> + n::"1"::"xpointer"::tail -> ( - hd, + Some hd, List.fold_left (fun par t -> match par with - [] -> [MQString t] - | _ -> (MQString t) :: MQSlash :: par + [] -> [MQBC t] + | _ -> (MQBC t) :: MQBD :: par ) [] tail, - (Some (int_of_string n), None) + [MQFC (int_of_string n)] ) - | ")"::n::m::"xpointer(1"::tail -> + | n::m::"1"::"xpointer"::tail -> ( - hd, + Some hd, List.fold_left (fun par t -> match par with - [] -> [MQString t] - | _ -> (MQString t) :: MQSlash :: par + [] -> [MQBC t] + | _ -> (MQBC t) :: MQBD :: par ) [] tail, - (Some (int_of_string m), Some (int_of_string n)) + [MQFC (int_of_string m); MQFC (int_of_string n)] ) | tail -> ( - hd, + Some hd, List.fold_left (fun par t -> match par with - [] -> [MQString t] - | _ -> (MQString t) :: MQSlash :: par + [] -> [MQBC t] + | _ -> (MQBC t) :: MQBD :: par ) [] tail, - (None, None) + [] ) ) - | [] -> assert false + | _ -> assert false ) tmp ) +*) ;; @@ -178,7 +229,7 @@ let xres_to_res l = *) let execute q = match q with - MQList qq -> xres_to_res (execute_ex qq) + MQList qq -> xres_to_res (execute_ex [] qq) ;; (*