]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/mathql_interpreter/use.ml
diff and sortedby implemented
[helm.git] / helm / ocaml / mathql_interpreter / use.ml
index ecc12f01d7a6ab4d0384638ca30fa18b6cd72b53..ed8a855ec1f86b994bd184f0d1736bb71061c079 100644 (file)
@@ -20,7 +20,7 @@
  * MA  02111-1307, USA.
  * 
  * For details, see the HELM World-Wide-Web page,
- * http://cs.unibo.it/helm/.
+ * http://www.cs.unibo.it/helm/.
  *)
 
 (*
@@ -45,6 +45,44 @@ open Dbconn;;
  *                           comando USE/USED BY
  *)
 let use_ex alist asvar usek =
+ (*(*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 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 _ = print_endline ("DEBUG (use.ml): " ^ tv) 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
+          )
+          @
+          parziale
+     )
+     []
+     (List.tl alist)
+    )
+  in
+   (*let _ = print_endline (string_of_float (Unix.time () -. t)); flush stdout in*)
+
+ *)
 let module S = Mathql_semantics in
 let _ = print_string ("USE ")
 and t = Unix.time () in
@@ -55,7 +93,8 @@ let result =
    (List.fold_left
     (fun parziale {S.uri = uri ; S.attributes = attributes} ->
      print_string uri ;
-     (*let r1 = helm_property_id usek
+     (* RSSDB
+     let r1 = helm_property_id usek
      and r2 = helm_property_id "position"
      and r3 = helm_property_id "occurrence"
      in
@@ -63,7 +102,8 @@ let result =
        "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"*)
+       ".att0 order by t" ^ r3 ^ ".att1 asc"
+      *)
       let tv =
        pgresult_to_string
         (c#exec ("select id from registry where uri='" ^ uri ^ "'"))
@@ -75,7 +115,7 @@ let result =
       let res = c#exec qq in
        (List.map
         (function
-            [uri;context] -> {S.uri = uri ; S.attributes = [asvar, context]}
+            [uri;context] -> {S.uri = uri ; S.attributes = [asvar, context] ; S.extra = ""}
           | _ -> assert false
         ) res#get_list
        ) @