PACKAGE = mathql_interpreter
-REQUIRES = helm-urimanager pgocaml
+REQUIRES = helm-urimanager pgocaml unix
PREDICATES =
INTERFACE_FILES = dbconn.mli eval.mli utility.mli func.mli diff.mli \
try
(*match xres_join_context h1 tl1 h2 tl2 with
[] -> aux tll1 tll2
- | t ->*) (l1::(xres_join_context h1 tl1 h2 tl2))::(aux tll1 tll2)
+ | t -> (l1::(xres_join_context h1 tl1 h2 tl2))::(aux tll1 tll2)*)
+ (l1::(tl1 @ tl2))::(aux tll1 tll2)
with
Join_must_be_empty -> aux tll1 tll2
else
* implementazione del comando INTERSECT
*)
let intersect_ex l1 l2 =
+ let _ = print_string ("INTERSECT ")
+ and t = Unix.time () in
+ let result =
match (l1, l2) with
((head1::tail1), (head2::tail2)) ->
(match (head1, head2) with
) (* match *)
)
| _ -> []
+ in
+ let _ = print_endline (string_of_float (Unix.time () -. t)); flush stdout in
+ result
;;
* output: string list list; risultato internto formato da uri + contesto.
*)
let rec execute_ex q =
- match q with
- MQSelect (apvar, alist, abool) ->
- select_ex apvar (execute_ex alist) abool
- | MQUsedBy (alist, asvar) ->
- use_ex (execute_ex alist) asvar "refObj"
- | MQUse (alist, asvar) ->
- use_ex (execute_ex alist) asvar "backPointer"
- | MQPattern (apreamble, apattern, afragid) ->
- (*let _ = print_endline ("*********" ^ apreamble ^ (fi_to_string afragid)); flush stdout in*)
- pattern_ex apreamble apattern afragid
- | MQUnion (l1, l2) ->
- union_ex (execute_ex l1) (execute_ex l2)
- | MQDiff (l1, l2) ->
- diff_ex (execute_ex l1) (execute_ex l2)
- | MQSortedBy (l, o, f) ->
- sortedby_ex (execute_ex l) o f
- | MQIntersect (l1, l2) ->
- intersect_ex (execute_ex l1) (execute_ex l2)
+ match q with
+ MQSelect (apvar, alist, abool) ->
+ select_ex apvar (execute_ex alist) abool
+ | MQUsedBy (alist, asvar) ->
+ use_ex (execute_ex alist) asvar "F" (*"refObj"*)
+ | MQUse (alist, asvar) ->
+ use_ex (execute_ex alist) asvar "B" (*"backPointer"*)
+ | MQPattern (apreamble, apattern, afragid) ->
+ pattern_ex apreamble apattern afragid
+ | MQUnion (l1, l2) ->
+ union_ex (execute_ex l1) (execute_ex l2)
+ | MQDiff (l1, l2) ->
+ diff_ex (execute_ex l1) (execute_ex l2)
+ | MQSortedBy (l, o, f) ->
+ sortedby_ex (execute_ex l) o f
+ | MQIntersect (l1, l2) ->
+ intersect_ex (execute_ex l1) (execute_ex l2)
;;
(*
let pattern_ex apreamble apattern afragid =
let c = pgc () in
- let r1 = helm_class_id "MathResource" in
- let qq = "select att0 from t" ^ r1 ^ " where att0 " ^ (pattern_match apreamble apattern afragid) ^ " order by t" ^ r1 ^ ".att0 asc" in
+ (*let r1 = helm_class_id "MathResource" in*)
+ (*let qq = "select att0 from t" ^ r1 ^ " where att0 " ^ (pattern_match apreamble apattern afragid) ^ " order by t" ^ r1 ^ ".att0 asc" in*)
+ let qq = "select uri from registry where uri " ^ (pattern_match apreamble apattern afragid) ^ " order by registry.uri asc" in
(*let _ = print_endline qq in*)
let res =
c#exec (qq)
* implementazione del comando SELECT
*)
let select_ex avar alist abool =
- let wrt = replace avar "retVal" abool in
- (*let j = print_booltree wrt in*)
- [List.hd alist]
- @
- List.find_all
- (fun l -> is_good (List.combine (List.hd alist) l) wrt)
- (List.tl alist)
+ let _ = print_string ("SELECT ")
+ and t = Unix.time () in
+ let result =
+ let wrt = replace avar "retVal" abool in
+ (*let j = print_booltree wrt in*)
+ [List.hd alist]
+ @
+ List.find_all
+ (fun l -> is_good (List.combine (List.hd alist) l) wrt)
+ (List.tl alist)
+ in
+ let _ = print_endline (string_of_float (Unix.time () -. t)); flush stdout in
+ result
;;
* comando USE/USED BY
*)
let use_ex alist asvar usek =
- 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 order by t" ^ r3 ^ ".att1 asc"
+ 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 _ = 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
+ 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 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
- 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
- )
+ )
+ @
+ parziale
+ )
+ []
+ (List.tl alist)
)
- [ (List.hd alist)
- @
- if not (List.mem asvar (List.tl (List.hd alist))) then
- [asvar]
- else
- []
- ]
- (List.tl alist)
+ in
+ let _ = print_endline (string_of_float (Unix.time () -. t)); flush stdout in
+ result
;;