]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/mathql_interpreter/relation.ml
Merge of the new_mathql branch with the main branch:
[helm.git] / helm / ocaml / mathql_interpreter / relation.ml
diff --git a/helm/ocaml/mathql_interpreter/relation.ml b/helm/ocaml/mathql_interpreter/relation.ml
new file mode 100644 (file)
index 0000000..159369a
--- /dev/null
@@ -0,0 +1,76 @@
+(* 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 del comando Relation 
+ *)
+
+
+
+
+open Union;;
+open Dbconn;;
+open Utility;;
+
+
+
+
+let get_prop_id propl =
+  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 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 
+;;