]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/mathql_interpreter/relation.ml
Time misurations patched.
[helm.git] / helm / ocaml / mathql_interpreter / relation.ml
index 4776e694c76f3a7610cdbdbb329818df76dbf680..159369ad2b55fe0469dcc41e158f16a1b0619613 100644 (file)
  * http://www.cs.unibo.it/helm/.
  *)
 
-open Union;;
-open Dbconn;;
-open Utility;;
+
 (*
  * implementazione del comando Relation 
  *)
 
 
+
+
+open Union;;
+open Dbconn;;
+open Utility;;
+
+
+
+
 let get_prop_id propl =
- let prop = List.hd propl in
 let prop = List.hd propl in
   if prop="refObj" then "F"
   else if prop="backPointer" then "B"
        else assert false
 ;;
 
 
-
 let relation_ex rop path rset attl =
- if path = [] then []
- else
- let usek = get_prop_id path in
-
-let vvar = if attl = [] then "position"
-           else List.hd attl
-in        
-(*let (uril,atts) = List.split rset in*)
-let _ = print_string ("RELATION "^usek)
-and t = Sys.time () in
-let result =
- let c = pgc () in
-
-let rset_list =  (* lista di singoletti:resource_set di un elemento *)
-(List.fold_left (fun acc (uri,l) ->
-                         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] -> [(uri,[[(vvar,[context])]])]
-                                       | _ -> assert false ) 
-                             res#get_list) @ acc
-                                   )                 
-            [] rset                          
-)
-in                    
-                            let rec edup = function
-                               [] -> []
-                             | rs1::tl -> union_ex rs1 (edup tl) 
-                             in 
-                             edup rset_list 
-                              
-
-in
-print_string (" = " ^ string_of_int (List.length result) ^ ": ") ; 
-print_endline (string_of_float (Sys.time () -. t) ^ "s") ;
-flush stdout ;
-   result
+  if path = [] then []
+  else
+  let usek = get_prop_id path in
+  let vvar = if attl = [] then "position"
+             else List.hd attl
+  in      
+  let c = pgc () in
+  let rset_list =  (* lista di singoletti:resource_set di un elemento *)
+  (List.fold_left (fun acc (uri,l) ->
+    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] -> [(uri,[[(vvar,[context])]])]
+       | _ -> assert false ) 
+       res#get_list) @ acc
+                 )                   
+        [] rset                              
+  )
+  in                
+  let rec edup = function
+      [] -> []
+    | rs1::tl -> union_ex rs1 (edup tl) 
+  in 
+  edup rset_list 
 ;;
-