From eef875893d96b25d1b685fc9865b46c4267a31a6 Mon Sep 17 00:00:00 2001
From: natile ?>
Date: Thu, 19 Sep 2002 17:45:22 +0000
Subject: [PATCH] commit of galax mathql interpreter
---
helm/ocaml/.cvsignore | 1 +
.../META.helm-mathql_interpreter_galax.src | 4 +
helm/ocaml/Makefile.in | 2 +-
helm/ocaml/mathql_interpreter/mqint.ml | 1 -
.../ocaml/mathql_interpreter_galax/.cvsignore | 1 +
helm/ocaml/mathql_interpreter_galax/.depend | 32 +
.../mathql_interpreter_galax/2test_use.ml | 27 +
helm/ocaml/mathql_interpreter_galax/2use.ml | 62 +
helm/ocaml/mathql_interpreter_galax/Makefile | 17 +
helm/ocaml/mathql_interpreter_galax/diff.ml | 84 +
helm/ocaml/mathql_interpreter_galax/diff.mli | 27 +
helm/ocaml/mathql_interpreter_galax/eval.ml | 98 +
helm/ocaml/mathql_interpreter_galax/eval.mli | 27 +
helm/ocaml/mathql_interpreter_galax/func.ml | 113 +
helm/ocaml/mathql_interpreter_galax/func.mli | 26 +
.../getallrdfuris.xml | 14882 ++++++++++++++++
.../mathql_interpreter_galax/intersect.ml | 127 +
.../mathql_interpreter_galax/intersect.mli | 27 +
helm/ocaml/mathql_interpreter_galax/letin.ml | 65 +
helm/ocaml/mathql_interpreter_galax/letin.mli | 28 +
.../mathql_semantics.ml | 33 +
helm/ocaml/mathql_interpreter_galax/mqint.ml | 252 +
helm/ocaml/mathql_interpreter_galax/mqint.mli | 45 +
.../ocaml/mathql_interpreter_galax/pattern.ml | 236 +
.../mathql_interpreter_galax/pattern.mli | 28 +
.../mathql_interpreter_galax/pervasive.xq | 192 +
.../mathql_interpreter_galax/pervasive.xqp | 192 +
helm/ocaml/mathql_interpreter_galax/select.ml | 145 +
.../ocaml/mathql_interpreter_galax/select.mli | 34 +
.../mathql_interpreter_galax/sortedby.ml | 62 +
.../mathql_interpreter_galax/sortedby.mli | 27 +
.../test_intersect.ml | 69 +
.../mathql_interpreter_galax/test_pattern.ml | 28 +
.../mathql_interpreter_galax/test_select.ml | 55 +
.../mathql_interpreter_galax/test_select2.ml | 55 +
.../mathql_interpreter_galax/test_union.ml | 69 +
.../mathql_interpreter_galax/test_use.ml | 29 +
helm/ocaml/mathql_interpreter_galax/tools.ml | 98 +
helm/ocaml/mathql_interpreter_galax/union.ml | 139 +
helm/ocaml/mathql_interpreter_galax/union.mli | 27 +
helm/ocaml/mathql_interpreter_galax/use.ml | 69 +
helm/ocaml/mathql_interpreter_galax/use.mli | 4 +
.../ocaml/mathql_interpreter_galax/utility.ml | 119 +
.../mathql_interpreter_galax/utility.mli | 30 +
44 files changed, 17686 insertions(+), 2 deletions(-)
create mode 100644 helm/ocaml/META.helm-mathql_interpreter_galax.src
create mode 100644 helm/ocaml/mathql_interpreter_galax/.cvsignore
create mode 100644 helm/ocaml/mathql_interpreter_galax/.depend
create mode 100755 helm/ocaml/mathql_interpreter_galax/2test_use.ml
create mode 100644 helm/ocaml/mathql_interpreter_galax/2use.ml
create mode 100644 helm/ocaml/mathql_interpreter_galax/Makefile
create mode 100644 helm/ocaml/mathql_interpreter_galax/diff.ml
create mode 100644 helm/ocaml/mathql_interpreter_galax/diff.mli
create mode 100644 helm/ocaml/mathql_interpreter_galax/eval.ml
create mode 100644 helm/ocaml/mathql_interpreter_galax/eval.mli
create mode 100644 helm/ocaml/mathql_interpreter_galax/func.ml
create mode 100644 helm/ocaml/mathql_interpreter_galax/func.mli
create mode 100644 helm/ocaml/mathql_interpreter_galax/getallrdfuris.xml
create mode 100644 helm/ocaml/mathql_interpreter_galax/intersect.ml
create mode 100644 helm/ocaml/mathql_interpreter_galax/intersect.mli
create mode 100644 helm/ocaml/mathql_interpreter_galax/letin.ml
create mode 100644 helm/ocaml/mathql_interpreter_galax/letin.mli
create mode 100644 helm/ocaml/mathql_interpreter_galax/mathql_semantics.ml
create mode 100644 helm/ocaml/mathql_interpreter_galax/mqint.ml
create mode 100644 helm/ocaml/mathql_interpreter_galax/mqint.mli
create mode 100644 helm/ocaml/mathql_interpreter_galax/pattern.ml
create mode 100644 helm/ocaml/mathql_interpreter_galax/pattern.mli
create mode 100644 helm/ocaml/mathql_interpreter_galax/pervasive.xq
create mode 100644 helm/ocaml/mathql_interpreter_galax/pervasive.xqp
create mode 100644 helm/ocaml/mathql_interpreter_galax/select.ml
create mode 100644 helm/ocaml/mathql_interpreter_galax/select.mli
create mode 100644 helm/ocaml/mathql_interpreter_galax/sortedby.ml
create mode 100644 helm/ocaml/mathql_interpreter_galax/sortedby.mli
create mode 100755 helm/ocaml/mathql_interpreter_galax/test_intersect.ml
create mode 100755 helm/ocaml/mathql_interpreter_galax/test_pattern.ml
create mode 100755 helm/ocaml/mathql_interpreter_galax/test_select.ml
create mode 100644 helm/ocaml/mathql_interpreter_galax/test_select2.ml
create mode 100755 helm/ocaml/mathql_interpreter_galax/test_union.ml
create mode 100644 helm/ocaml/mathql_interpreter_galax/test_use.ml
create mode 100644 helm/ocaml/mathql_interpreter_galax/tools.ml
create mode 100644 helm/ocaml/mathql_interpreter_galax/union.ml
create mode 100644 helm/ocaml/mathql_interpreter_galax/union.mli
create mode 100644 helm/ocaml/mathql_interpreter_galax/use.ml
create mode 100644 helm/ocaml/mathql_interpreter_galax/use.mli
create mode 100644 helm/ocaml/mathql_interpreter_galax/utility.ml
create mode 100644 helm/ocaml/mathql_interpreter_galax/utility.mli
diff --git a/helm/ocaml/.cvsignore b/helm/ocaml/.cvsignore
index 18745fc01..04c50217e 100644
--- a/helm/ocaml/.cvsignore
+++ b/helm/ocaml/.cvsignore
@@ -10,6 +10,7 @@ META.helm-cic_proof_checking
META.helm-cic_textual_parser
META.helm-cic_unification
META.helm-mathql_interpreter
+META.helm-mathql_interpreter_galax
META.helm-mathql
Makefile
Makefile.common
diff --git a/helm/ocaml/META.helm-mathql_interpreter_galax.src b/helm/ocaml/META.helm-mathql_interpreter_galax.src
new file mode 100644
index 000000000..41c999cee
--- /dev/null
+++ b/helm/ocaml/META.helm-mathql_interpreter_galax.src
@@ -0,0 +1,4 @@
+requires="helm-urimanager num natile-galax"
+version="0.0.1"
+archive(byte)="mathql_interpreter_galax.cma"
+archive(native)="mathql_interpreter_galax.cmxa"
diff --git a/helm/ocaml/Makefile.in b/helm/ocaml/Makefile.in
index 9ebef2422..06a314961 100644
--- a/helm/ocaml/Makefile.in
+++ b/helm/ocaml/Makefile.in
@@ -1,7 +1,7 @@
# Warning: the modules must be in compilation order
MODULES = xml urimanager getter pxp cic cic_annotations cic_annotations_cache \
cic_cache cic_proof_checking cic_textual_parser cic_unification \
- mathql mathql_interpreter
+ mathql mathql_interpreter mathql_interpreter_galax
OCAMLFIND_DEST_DIR = @OCAMLFIND_DEST_DIR@
OCAMLFIND_META_DIR = @OCAMLFIND_META_DIR@
diff --git a/helm/ocaml/mathql_interpreter/mqint.ml b/helm/ocaml/mathql_interpreter/mqint.ml
index cf453c6f6..ed6b515c7 100644
--- a/helm/ocaml/mathql_interpreter/mqint.ml
+++ b/helm/ocaml/mathql_interpreter/mqint.ml
@@ -243,4 +243,3 @@ let execute q =
* chiusura della connessione al database
*)
let close () = Dbconn.close ();;
-
diff --git a/helm/ocaml/mathql_interpreter_galax/.cvsignore b/helm/ocaml/mathql_interpreter_galax/.cvsignore
new file mode 100644
index 000000000..6b3eba302
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/.cvsignore
@@ -0,0 +1 @@
+*.cm[iaox] *.cmxa
diff --git a/helm/ocaml/mathql_interpreter_galax/.depend b/helm/ocaml/mathql_interpreter_galax/.depend
new file mode 100644
index 000000000..a4f0ecccc
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/.depend
@@ -0,0 +1,32 @@
+diff.cmi: mathql_semantics.cmo
+sortedby.cmi: mathql_semantics.cmo
+select.cmi: mathql_semantics.cmo
+intersect.cmi: mathql_semantics.cmo
+union.cmi: mathql_semantics.cmo
+pattern.cmi: mathql_semantics.cmo
+use.cmi: mathql_semantics.cmo
+letin.cmi: mathql_semantics.cmo
+eval.cmo: eval.cmi
+eval.cmx: eval.cmi
+func.cmo: func.cmi
+func.cmx: func.cmi
+diff.cmo: mathql_semantics.cmo diff.cmi
+diff.cmx: mathql_semantics.cmx diff.cmi
+sortedby.cmo: func.cmi mathql_semantics.cmo sortedby.cmi
+sortedby.cmx: func.cmx mathql_semantics.cmx sortedby.cmi
+select.cmo: func.cmi mathql_semantics.cmo select.cmi
+select.cmx: func.cmx mathql_semantics.cmx select.cmi
+intersect.cmo: mathql_semantics.cmo intersect.cmi
+intersect.cmx: mathql_semantics.cmx intersect.cmi
+union.cmo: mathql_semantics.cmo union.cmi
+union.cmx: mathql_semantics.cmx union.cmi
+pattern.cmo: mathql_semantics.cmo pattern.cmi
+pattern.cmx: mathql_semantics.cmx pattern.cmi
+use.cmo: mathql_semantics.cmo use.cmi
+use.cmx: mathql_semantics.cmx use.cmi
+letin.cmo: letin.cmi
+letin.cmx: letin.cmi
+mqint.cmo: diff.cmi eval.cmi intersect.cmi letin.cmi mathql_semantics.cmo \
+ pattern.cmi select.cmi sortedby.cmi union.cmi use.cmi mqint.cmi
+mqint.cmx: diff.cmx eval.cmx intersect.cmx letin.cmx mathql_semantics.cmx \
+ pattern.cmx select.cmx sortedby.cmx union.cmx use.cmx mqint.cmi
diff --git a/helm/ocaml/mathql_interpreter_galax/2test_use.ml b/helm/ocaml/mathql_interpreter_galax/2test_use.ml
new file mode 100755
index 000000000..5ce9f637c
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/2test_use.ml
@@ -0,0 +1,27 @@
+
+
+open Mathql_semantics;;
+open MathQL;;
+
+(* stampa tutti i documenti che fanno match con un pattern di input *)
+List.iter
+ (function atturi -> print_endline ("output: " ^ atturi))
+ (match Mqint.execute
+ (MQList
+ (MQUse
+ (MQPattern
+ (
+ Some "cic",
+ [MQBD;MQBC "Algebra"; MQBD; MQBC "Basics"; MQBD; MQBC"NEG_anti_convert.con"],
+ (* [MQBSS; MQBC ".con"],*)
+ []
+ ),
+ "pippo")
+ )
+ ) with MQRefs l -> l
+ );
+
+
+
+;;
+
diff --git a/helm/ocaml/mathql_interpreter_galax/2use.ml b/helm/ocaml/mathql_interpreter_galax/2use.ml
new file mode 100644
index 000000000..9a69db2f9
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/2use.ml
@@ -0,0 +1,62 @@
+open Mathql_semantics;;
+
+
+(* prende una lista di uri (contenente alternativamente uri e pos) e costruisce una lista di attributed_uri *)
+let rec attl uril svar =
+
+ match uril with
+ | head::tail ->
+ let suri = List.hd uril in
+
+ let uril_tl = List.tl uril in
+
+
+ {uri = suri; attributes = [(svar, (List.hd
+ uril_tl))]; extra = ""} :: attl (List.tl uril_tl) svar (*
+ NON SONO SICURO DI AVER COSTRUITO BENE LA STRUTTURA DATI!!!!*)
+ | [] -> []
+
+
+
+
+
+(* prende un attributed_uri e una svar e restituisce la lista degli
+attributed_uri (backward o forward in base al parametro "d") associando
+la posizione alla var passata *)
+
+let muse svar d path =
+ let dir =
+ match d with
+ "F" -> "/home/projects/helm/metadata/create4/forward"
+ | _ -> "/home/projects/helm/metadata/create4/backward"
+ in
+ let dtag =
+ match d with
+ "F" -> "refObj"
+ | _ -> "backPointer" in
+
+ let xq ="namespace h=\"http://www.cs.unibo.it/helm/schemas/mattone.rdf#\"
+ namespace rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"
+ for $i in document(" ^ "\"" ^ dir ^ path.uri ^ "\"" ^
+ ")//rdf:RDF//h:Object//h:" ^ dtag ^ "//h:Occurrence
+ return ($i//h:occurrence, $i//h:position)"
+
+ in
+ print_endline xq;
+ let uril = Toputils.eval_query_string xq in (* e' una lista di liste di stringhe*)
+ let hd_uril = List.hd uril in(*prendo l'elemento in testa che e' quello
+ che contiene la lista di uri*)
+
+ attl hd_uril svar (* adesso dalla lista di uri(hd_uril) costruisco una lista di attributed_uri*)
+
+
+
+
+(* prende una lista di uri (Mathql_semantics.result), una variabile (a cui
+associare la posizione), e la direzione (forward o backward) e per ogni uri chiama la muse *)
+let use_ex ulist svar d =
+ List.concat (List.map (muse svar d) ulist)
+;;
+
+
+
diff --git a/helm/ocaml/mathql_interpreter_galax/Makefile b/helm/ocaml/mathql_interpreter_galax/Makefile
new file mode 100644
index 000000000..8ea6fafae
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/Makefile
@@ -0,0 +1,17 @@
+PACKAGE = mathql_interpreter_galax
+REQUIRES = helm-urimanager unix helm-mathql natile-galax
+PREDICATES =
+
+INTERFACE_FILES = eval.mli func.mli diff.mli \
+ sortedby.mli select.mli intersect.mli union.mli \
+ pattern.mli use.mli letin.mli mqint.mli
+
+IMPLEMENTATION_FILES = mathql_semantics.ml \
+ $(INTERFACE_FILES:%.mli=%.ml)
+
+EXTRA_OBJECTS_TO_INSTALL = mathql_semantics.ml mathql_semantics.cmi
+
+EXTRA_OBJECTS_TO_CLEAN =
+
+
+include ../Makefile.common
diff --git a/helm/ocaml/mathql_interpreter_galax/diff.ml b/helm/ocaml/mathql_interpreter_galax/diff.ml
new file mode 100644
index 000000000..b32468e40
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/diff.ml
@@ -0,0 +1,84 @@
+(* 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://cs.unibo.it/helm/.
+ *)
+
+(*
+ * implementazione del comando DIFF
+ *)
+
+exception NotCompatible;;
+
+(* intersect_attributes is successful iff there is no attribute with *)
+(* two different values in the two lists. The returned list is the *)
+(* union of the two lists. *)
+let rec intersect_attributes (attr1, attr2) =
+ match attr1, attr2 with
+ [],_ -> attr2
+ | _,[] -> attr1
+ | (key1,value1)::tl1, (key2,_)::_ when key1 < key2 ->
+ (key1,value1)::(intersect_attributes (tl1,attr2))
+ | (key1,_)::_, (key2,value2)::tl2 when key2 < key1 ->
+ (key2,value2)::(intersect_attributes (attr1,tl2))
+ | entry1::tl1, entry2::tl2 when entry1 = entry2 ->
+ entry1::(intersect_attributes (tl1,tl2))
+ | _, _ -> raise NotCompatible (* same keys, different values *)
+;;
+
+(*
+ * implementazione del comando DIFF
+ *)
+let rec diff_ex l1 l2 =
+ let module S = Mathql_semantics in
+ match (l1, l2) with
+ [],_ -> []
+ | l,[] -> l
+ | {S.uri = uri1}::_, {S.uri = uri2}::tl2 when uri2 < uri1 ->
+ (diff_ex l1 tl2)
+ | {S.uri = uri1 ; S.attributes = attributes1}::tl1,
+ {S.uri = uri2}::_ when uri1 < uri2 ->
+ {S.uri = uri1 ; S.attributes = attributes1 ; S.extra = ""}::(diff_ex tl1 l2)
+ | {S.uri = uri1 ; S.attributes = attributes1}::tl1,
+ {S.uri = uri2 ; S.attributes = attributes2}::tl2 ->
+ try
+ let attributes' = intersect_attributes (attributes1, attributes2) in
+ diff_ex tl1 tl2
+ with
+ NotCompatible ->
+ {S.uri = uri1 ; S.attributes = attributes1 ; S.extra = ""}::(diff_ex tl1 tl2)
+;;
+
+let diff_ex l1 l2 =
+ let before = Unix.time () in
+ let res = diff_ex l1 l2 in
+ let after = Unix.time () in
+ let ll1 = string_of_int (List.length l1) in
+ let ll2 = string_of_int (List.length l2) in
+ let diff = string_of_float (after -. before) in
+ prerr_endline
+ ("DIFF(" ^ ll1 ^ ", " ^ ll2 ^ ") = " ^ string_of_int (List.length res) ^
+ ": " ^ diff ^ "s") ;
+ flush stderr ;
+ res
+;;
+
diff --git a/helm/ocaml/mathql_interpreter_galax/diff.mli b/helm/ocaml/mathql_interpreter_galax/diff.mli
new file mode 100644
index 000000000..8c247687f
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/diff.mli
@@ -0,0 +1,27 @@
+(* 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://cs.unibo.it/helm/.
+ *)
+
+val diff_ex :
+ Mathql_semantics.result -> Mathql_semantics.result -> Mathql_semantics.result
diff --git a/helm/ocaml/mathql_interpreter_galax/eval.ml b/helm/ocaml/mathql_interpreter_galax/eval.ml
new file mode 100644
index 000000000..43296cd07
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/eval.ml
@@ -0,0 +1,98 @@
+(* 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://cs.unibo.it/helm/.
+ *)
+
+(*
+ *
+ *)
+
+open MathQL;;
+
+(*
+ * conversione di un pattern
+ *)
+let rec patterneval p =
+ match p with
+ [] -> ""
+ | head::tail ->
+ let h = match head with
+ MQBC s -> Str.global_replace (Str.regexp "\.") "\\\\\." s
+ | MQBD -> "/"
+ | MQBQ -> "[^/#]?"
+ | MQBS -> "[^/#]*"
+ | MQBSS -> "[^#]*"
+ in
+ h ^ (patterneval tail)
+;;
+
+let rec fieval fi =
+ match fi with
+ [] -> ""
+ | MQFC i :: tail -> "/" ^ (string_of_int i) ^ (fieval tail)
+ | MQFS :: tail -> "[^/]*" ^ (fieval tail)
+ | MQFSS :: tail -> ".*" ^ (fieval tail)
+;;
+
+(*
+ * conversione di un fragment identifier
+ *)
+let fieval fi =
+ if fi = [] then
+ ""
+ else
+ "#xpointer\\\\(1" ^ fieval fi ^ "\\\\)"
+;;
+
+(*
+ * valuta l'estensione
+ *
+ * 20/05/2002: non piu' necessario: l'estensione fa eventualmente
+ * parte del pattern precedente
+ *)
+let exteval ext =
+ match ext with
+ "" -> ""
+ | _ -> ("\." ^ ext)
+;;
+
+(*
+ * valuta il preambolo
+ *)
+let preeval p =
+ match p with
+ Some s -> s
+ | None -> "[^/]*"
+;;
+
+(*
+ * trasforma un pattern MathQL in un pattern postgresql
+ *
+ * si utilizzano espressioni regolari POSIX anziche' l'operatore
+ * SQL standard LIKE perche' MathQL prevede esperssioni con "*"
+ * e con "**".
+ *)
+let pattern_match (preamble, pattern, fragid) =
+ " ~ '^" ^ (preeval preamble) ^ ":/" ^ (patterneval pattern) ^ (fieval fragid) ^ "$'"
+;;
+
diff --git a/helm/ocaml/mathql_interpreter_galax/eval.mli b/helm/ocaml/mathql_interpreter_galax/eval.mli
new file mode 100644
index 000000000..00b64ed95
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/eval.mli
@@ -0,0 +1,27 @@
+(* 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://cs.unibo.it/helm/.
+ *)
+
+val pattern_match :
+ MathQL.mqtref -> string
diff --git a/helm/ocaml/mathql_interpreter_galax/func.ml b/helm/ocaml/mathql_interpreter_galax/func.ml
new file mode 100644
index 000000000..ff2476df1
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/func.ml
@@ -0,0 +1,113 @@
+(* 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://cs.unibo.it/helm/.
+ *)
+
+(*
+ *
+ *)
+
+open MathQL;;
+
+(*
+ * implementazione della funzione NAME
+ *
+ * esempio:
+ * name "cic:/Algebra/CC_Props/CC_CauchySeq.ind#xpointer(1/1/1)" = CC_CauchySeq
+ *)
+let func_name value =
+ try (
+ let i = Str.search_forward (Str.regexp "[^/]*\.") value 0 in
+ let s = Str.matched_string value in
+ let retVal = Str.string_before s ((String.length s) - 1) in
+ retVal
+ ) with
+ Not_found -> ""
+;;
+
+(*
+ *
+ *)
+let func_theory value =
+ ""
+;;
+
+(*
+ * implementazione delle funzioni dublin core
+ *)
+let func_dc (value, name) =
+ let pathv = ("\"" ^ "/home/lorenzo/helm/metadata/dc" ^ value ^ "\"") in
+ let xq ="namespace rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"
+ namespace rdfs=\"http://www.w3.org/2000/01/rdf-schema#\"
+ namespace dc=\"http://purl.org/metadata/dublin_core#\"
+ namespace dcq=\"http://purl.org/metadata/dublin_core_qualifiers#\"
+ namespace h=\"http:/www.cs.unibo.it/helm/schemas/schema-h.rdf#\"
+ namespace hth=\"http://www.cs.unibo.it/helm/schemas/schema-hth.rdf#\"
+
+ for $i in document(" ^ pathv ^ ")//rdf:RDF//h:DirectoryOfObjects
+ return $i//dc:" ^ name
+ in
+ let uril = Toputils.eval_query_string xq in (* e' una lista di liste di stringhe*)
+ let hd_uril = List.hd uril in (*prendo l'elemento in testa che e' quello che contiene la lista
+ di uri, IN REALTA' ORA CONTIENE ALTERNATIVAMENTE UN URI E LA SUA POSIZIONE!! *)
+ List.hd hd_uril
+
+
+
+(*print_string (( List.hd hd_uril) ^ "NEW!");
+ print_endline " [FINE]";*)
+
+
+
+ (*List.iter (List.iter print_string) uril;*)
+
+ ;;
+
+(*
+ *
+ *)
+let apply_func f value =
+ match f with
+ MQName -> func_name value
+ | MQTheory -> func_theory value
+ | MQTitle -> func_dc (value, "title")
+ | MQContributor -> func_dc (value, "contributor")
+ | MQCreator -> func_dc (value, "creator")
+ | MQPublisher -> func_dc (value, "publisher")
+ | MQSubject -> func_dc (value, "subject")
+ | MQDescription -> func_dc (value, "description")
+ | MQDate -> func_dc (value, "date")
+ | MQType -> func_dc (value, "type")
+ | MQFormat -> func_dc (value, "format")
+ | MQIdentifier -> func_dc (value, "identifier")
+ | MQLanguage -> func_dc (value, "language")
+ | MQRelation -> func_dc (value, "relation")
+ | MQSource -> func_dc (value, "source")
+ | MQCoverage -> func_dc (value, "coverage")
+ | MQRights -> func_dc (value, "rights")
+ | MQInstitution -> func_dc (value, "institution")
+ | MQContact -> func_dc (value, "contact")
+ | MQFirstVersion -> func_dc (value, "firstversion")
+ | MQModified -> func_dc (value, "modified")
+;;
+
diff --git a/helm/ocaml/mathql_interpreter_galax/func.mli b/helm/ocaml/mathql_interpreter_galax/func.mli
new file mode 100644
index 000000000..fb68df82a
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/func.mli
@@ -0,0 +1,26 @@
+(* 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://cs.unibo.it/helm/.
+ *)
+
+val apply_func: MathQL.mqfunc -> string -> string
diff --git a/helm/ocaml/mathql_interpreter_galax/getallrdfuris.xml b/helm/ocaml/mathql_interpreter_galax/getallrdfuris.xml
new file mode 100644
index 000000000..ce378cc34
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/getallrdfuris.xml
@@ -0,0 +1,14882 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/helm/ocaml/mathql_interpreter_galax/intersect.ml b/helm/ocaml/mathql_interpreter_galax/intersect.ml
new file mode 100644
index 000000000..4152a280d
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/intersect.ml
@@ -0,0 +1,127 @@
+(* 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://cs.unibo.it/helm/.
+ *)
+
+exception NotCompatible;;
+
+(* intersect_attributes is successful iff there is no attribute with *)
+(* two different values in the two lists. The returned list is the *)
+(* union of the two lists. *)
+let rec intersect_attributes (attr1, attr2) =
+ match attr1, attr2 with
+ [],_ -> attr2
+ | _,[] -> attr1
+ | (key1,value1)::tl1, (key2,_)::_ when key1 < key2 ->
+ (key1,value1)::(intersect_attributes (tl1,attr2))
+ | (key1,_)::_, (key2,value2)::tl2 when key2 < key1 ->
+ (key2,value2)::(intersect_attributes (attr1,tl2))
+ | entry1::tl1, entry2::tl2 when entry1 = entry2 ->
+ entry1::(intersect_attributes (tl1,tl2))
+ | _, _ -> raise NotCompatible (* same keys, different values *)
+;;
+
+(* preserves order and gets rid of duplicates *)
+let rec intersect_ex l1 l2 =
+ let module S = Mathql_semantics in
+ match (l1, l2) with
+ [],_
+ | _,[] -> []
+ | {S.uri = uri1}::tl1,
+ {S.uri = uri2}::_ when uri1 < uri2 -> intersect_ex tl1 l2
+ | {S.uri = uri1}::_,
+ {S.uri = uri2}::tl2 when uri2 < uri1 -> intersect_ex l1 tl2
+ | {S.uri = uri1 ; S.attributes = attributes1}::tl1,
+ {S.uri = uri2 ; S.attributes = attributes2}::tl2 ->
+ try
+ let attributes' = intersect_attributes (attributes1,attributes2) in
+ {S.uri = uri1 ; S.attributes = attributes' ; S.extra = ""}::(intersect_ex tl1 tl2)
+ with
+ NotCompatible ->
+ intersect_ex tl1 tl2
+;;
+
+let intersect_ex l1 l2 =
+ (* PRE-CLAUDIO
+ (*let _ = print_string ("INTERSECT ")
+ and t = Unix.time () in*)
+ let result =
+ match (l1, l2) with
+ ((head1::tail1), (head2::tail2)) ->
+ (match (head1, head2) with
+ ([], _) -> assert false (* gli header non devono mai essere vuoti *)
+ | (_, []) -> assert false (* devono contenere almeno [retVal] *)
+ | (_, _) ->
+ (match (tail1, tail2) with
+ ([], _) -> [["retVal"]] (* se una delle due code e' vuota... *)
+ | (_, []) -> [["retVal"]] (* ... l'intersezione e' vuota *)
+ | (_, _) ->
+ [head2 @
+ (List.find_all
+ (function t -> not (List.mem t head2))
+ head1
+ )
+ ] (* header del risultato finale *)
+ @
+ intersect_tails (List.tl head1) tail1 (List.tl head2) tail2
+ (*
+ List.fold_left
+ (fun par1 elem1 -> par1 @
+ List.map
+ (fun elem2 ->
+ [(List.hd elem1)] @
+ (xres_join_context (List.tl head1) (List.tl elem1)
+ (List.tl head2) (List.tl elem2)
+ )
+ )
+ (List.find_all (* *)
+ (fun elem2 -> (* trova tutti gli elementi della lista tail2 *)
+ ((List.hd elem1) = (List.hd elem2)) && (* che stanno in tail1 *)
+ not ((xres_join_context (List.tl head1) (List.tl elem1)
+ (List.tl head2) (List.tl elem2)) = [])
+ (* e per i quali la xres_join_context non sia vuota *)
+ )
+ tail2 (* List.find_all *)
+ )
+ )
+ []
+ tail1 (* per ogni elemento di tail1 applica la List.fold_left *)
+ *)
+ ) (* match *)
+ )
+ | _ -> []
+ in
+ (*let _ = print_endline (string_of_float (Unix.time () -. t)); flush stdout in*)
+ result*)
+ let before = Unix.time () in
+ let res = intersect_ex l1 l2 in
+ let after = Unix.time () in
+ let ll1 = string_of_int (List.length l1) in
+ let ll2 = string_of_int (List.length l2) in
+ let diff = string_of_float (after -. before) in
+ prerr_endline
+ ("INTERSECT(" ^ ll1 ^ "," ^ ll2 ^ ") = " ^ string_of_int (List.length res) ^
+ ": " ^ diff ^ "s") ;
+ flush stderr ;
+ res
+;;
diff --git a/helm/ocaml/mathql_interpreter_galax/intersect.mli b/helm/ocaml/mathql_interpreter_galax/intersect.mli
new file mode 100644
index 000000000..3b721b4f7
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/intersect.mli
@@ -0,0 +1,27 @@
+(* 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://cs.unibo.it/helm/.
+ *)
+
+val intersect_ex :
+ Mathql_semantics.result -> Mathql_semantics.result -> Mathql_semantics.result
diff --git a/helm/ocaml/mathql_interpreter_galax/letin.ml b/helm/ocaml/mathql_interpreter_galax/letin.ml
new file mode 100644
index 000000000..160a7a164
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/letin.ml
@@ -0,0 +1,65 @@
+(* 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 dei comandi LETIN e REF
+ *)
+
+open MathQL;;
+
+let letin_pool = ref None;;
+
+let see_pool () =
+ match !letin_pool with
+ None -> print_endline "None"
+ | Some c -> List.iter (fun elem -> print_endline (fst elem)) c
+;;
+
+let letin_ex rvar alist =
+ let _ =
+ match !letin_pool with
+ Some pool -> letin_pool := Some ((rvar,alist)::(List.remove_assoc rvar pool))
+ | None -> letin_pool := Some ([(rvar,alist)])
+ in
+(* let _ = see_pool () in*)
+ []
+;;
+
+let letref_ex rvar =
+ match !letin_pool with
+ None -> []
+ | Some pool ->
+ (
+ try
+ List.assoc rvar pool
+ with
+ Not_found -> []
+ )
+;;
+
+let letdispose () =
+ let _ = letin_pool = ref None in ()
+;;
+
diff --git a/helm/ocaml/mathql_interpreter_galax/letin.mli b/helm/ocaml/mathql_interpreter_galax/letin.mli
new file mode 100644
index 000000000..d221ddd2e
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/letin.mli
@@ -0,0 +1,28 @@
+(* 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/.
+ *)
+
+val letin_ex : MathQL.mqlvar -> Mathql_semantics.result -> Mathql_semantics.result
+val letref_ex : MathQL.mqlvar -> Mathql_semantics.result
+val letdispose : unit -> unit
diff --git a/helm/ocaml/mathql_interpreter_galax/mathql_semantics.ml b/helm/ocaml/mathql_interpreter_galax/mathql_semantics.ml
new file mode 100644
index 000000000..2af88a63c
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/mathql_semantics.ml
@@ -0,0 +1,33 @@
+(* 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/.
+ *)
+
+(* attributes are sorted w.r.t. their name in increasing order *)
+type attributed_uri =
+ { uri: string ; attributes : (MathQL.mqsvar * string) list ; extra : string}
+
+type attributed_uri_env =
+ (MathQL.mqrvar * attributed_uri) list
+
+type result = attributed_uri list
diff --git a/helm/ocaml/mathql_interpreter_galax/mqint.ml b/helm/ocaml/mathql_interpreter_galax/mqint.ml
new file mode 100644
index 000000000..10e1b81e5
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/mqint.ml
@@ -0,0 +1,252 @@
+(* 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://cs.unibo.it/helm/.
+ *)
+
+(*
+ * implementazione del'interprete MathQL
+ *)
+open MathQL;;
+open Eval;;
+(*open Utility;;*)
+open Union;;
+open Intersect;;
+open Diff;;
+open Sortedby;;
+open Select;;
+open Letin;;
+open Mathql_semantics;;
+open Pattern;;
+open Use;;
+
+
+
+let prop_pool = ref None;;
+
+let fi_to_string fi =
+ match fi with
+ (None, _) ->
+ ""
+ | (Some i, y) ->
+ "#xpointer(1/" ^
+ string_of_int i ^
+ (
+ match y with
+ None ->
+ ""
+ | Some j ->
+ "/" ^ (string_of_int j)
+ ) ^
+ ")"
+;;
+
+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)
+;;
+
+
+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 env apvar (execute_ex env alist) abool
+ | MQUsedBy (alist, asvar) -> use_ex (execute_ex env alist) asvar (get_prop_id "refObj") (* "F"
+ (*"refObj"*) *)
+ | MQUse (alist, asvar) -> use_ex (execute_ex env alist) asvar (get_prop_id "backPointer") (* "B"
+ (*"backPointer"*) *)
+ | MQPattern (apreamble, apattern, afragid) ->
+ pattern_ex (apreamble, apattern, afragid)
+ | MQUnion (l1, l2) -> union_ex (execute_ex env l1) (execute_ex env l2)
+ | MQDiff (l1, l2) -> diff_ex (execute_ex env l1) (execute_ex env l2)
+ | MQSortedBy (l, o, f) -> sortedby_ex (execute_ex env l) o f
+ | MQIntersect (l1, 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
+ | MQReference l ->
+ let rec build_result = function
+ | [] -> []
+ | s :: tail ->
+
+ let len = String.length s in
+ let s = (String.sub s 4 (len-4))(*^".xml"*) in
+ if String.contains s '#' then
+ let pos = String.index s '#' in
+ let s1 = Str.string_before s pos in
+ let xp = Str.string_after s pos in
+ let xp = Str.global_replace (Str.regexp "#xpointer(1") "" xp in
+ let xp = Str.global_replace (Str.regexp "\/") "," xp in
+ let xp = Str.global_replace (Str.regexp ")") "" xp in
+ let s = (s1 ^ xp) in
+ {uri = s ; attributes = [] ; extra = ""} :: build_result tail
+ else
+ {uri = s ; attributes = [] ; extra = ""} :: build_result tail
+ in build_result (List.sort compare l)
+;;
+
+(* Let's initialize the execute in Select, creating a cyclical recursion *)
+Select.execute := execute_ex;;
+
+
+
+(*exception ExecuteFunctionNotInitialized;;
+let execute =
+ ref
+ (function _ -> raise ExecuteFunctionNotInitialized)
+;;
+
+
+
+execute := execute_ex;;*)
+
+
+
+(*
+ * converte il risultato interno di una query (uri + contesto)
+ * in un risultato di sole uri
+ *
+ * parametri:
+ * l: string list list;
+ *
+ * output: mqresult;
+ *
+ * note:
+ * il tipo del risultato mantenuto internamente e' diverso dal tipo di risultato
+ * restituito in output poiche', mentre chi effettua le query vuole come risultato
+ * solo le eventuali uri che soddisfano le query stesse, internamente ad una uri
+ * sono associati anche i valori delle variabili che ancora non sono state valutate
+ * perche', ad esempio, si trovano in altri rami dell'albero.
+ *
+ * Esempio:
+ * SELECT x IN USE PATTERN "cic:/**.con" POSITION $a WHERE $a IS MainConclusion
+ * L'albero corrispondente a questa query e':
+ *
+ * SELECT
+ * / | \
+ * x USE IS
+ * / \ /\
+ * PATTERN $a $a MainConclusion
+ *
+ * Nel momento in cui si esegue il ramo USE non sono noti i vincoli sullla variabile $a
+ * percui e' necessario considerare, oltre alle uri, i valori della variabile per i quali
+ * la uri puo' far parte del risultato.
+ *)
+
+ (* L.N.: prende una lista di attributed_uri e la trasforma in lista di
+ uri(stringhe) costruendola con il costruttore MQRefs *)
+let xres_to_res l =
+ 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 ->
+ (*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::"1"::"xpointer"::tail ->
+ (
+ Some hd,
+ List.fold_left
+ (fun par t ->
+ match par with
+ [] -> [MQBC t]
+ | _ -> (MQBC t) :: MQBD :: par
+ )
+ []
+ tail,
+ [MQFC (int_of_string n)]
+ )
+ | n::m::"1"::"xpointer"::tail ->
+ (
+ Some hd,
+ List.fold_left
+ (fun par t ->
+ match par with
+ [] -> [MQBC t]
+ | _ -> (MQBC t) :: MQBD :: par
+ )
+ []
+ tail,
+ [MQFC (int_of_string m); MQFC (int_of_string n)]
+ )
+ | tail ->
+ (
+ Some hd,
+ List.fold_left
+ (fun par t ->
+ match par with
+ [] -> [MQBC t]
+ | _ -> (MQBC t) :: MQBD :: par
+ )
+ []
+ tail,
+ []
+ )
+ )
+ | _ -> assert false
+ )
+ tmp
+ )
+*)
+;;
+
+
+(*
+ *
+ *)
+let execute q =
+
+ match q with
+ MQList qq -> try xres_to_res (execute_ex [] qq) with e -> Error.print_exn e; raise e
+;;
+
+let init () = ();;
+let close () = ();;
diff --git a/helm/ocaml/mathql_interpreter_galax/mqint.mli b/helm/ocaml/mathql_interpreter_galax/mqint.mli
new file mode 100644
index 000000000..60f00f50c
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/mqint.mli
@@ -0,0 +1,45 @@
+(* 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://cs.unibo.it/helm/.
+ *)
+
+(*
+ * interfaccia dell'interprete MathQL
+ *)
+
+open MathQL;;
+
+(*
+ * inizializzazione del database
+ *)
+val init: unit -> unit
+
+(*
+ * esecuzione di query
+ *)
+val execute: mquery -> mqresult;;
+
+(*
+ * chiusura del database
+ *)
+val close: unit -> unit
diff --git a/helm/ocaml/mathql_interpreter_galax/pattern.ml b/helm/ocaml/mathql_interpreter_galax/pattern.ml
new file mode 100644
index 000000000..1d4731ec4
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/pattern.ml
@@ -0,0 +1,236 @@
+
+ (* ATTENZIONE: ci sono problemi con i .ind e i .var!!!! *)
+
+
+
+open MathQL;;
+open Mathql_semantics;;
+
+(* estrae il fid dalla uri(str) e toglie le virgole, es: ",1,1,1,1" -> "1111" *)
+let extract_fid str =
+ let pos = String.index str ',' in
+ Str.string_after str (pos+1)
+;;
+
+
+(*
+ * valuta il preambolo
+ *)
+let preeval p =
+ match p with
+ Some s -> s
+ | None -> "[^/]*"
+;;
+
+
+
+
+(* FUNZIONE DI MATCHING: prende il descrittore del file delle uri e il path da
+matchare formato stringa e restituisce la lista dei path che fanno match in
+formato stringa !! TAIL-RECURSIVE !! *)
+
+let pmatch inp pre path fi =
+ let rec aux inp pre path fi acc =
+
+ let s= try
+ Some (Str.string_after (input_line(inp)) 57)
+ with End_of_file -> None
+ in
+ match s with
+ | Some s ->
+ if (String.get s 0) != ' '
+ then
+ begin
+ let cpos = String.index s ':' in
+
+ let apre = Str.string_before s cpos in (* prendo il pre in s *)
+
+ let s2 = Str.string_after s (cpos+1) in
+ let p = (String.length s2)-2 (* NON capisco perche' con 3 non vada bene !!!!*)
+ in
+
+ let sok = Str.string_before s2 p in
+
+
+ if fi = "" (* CASO fi VUOTO*)
+ then
+ if pre = "[^/]*" (* CASO pre QUALSIASI*)
+ then
+ if (Str.string_match (Str.regexp path) sok 0)
+ then
+ begin
+ (*let sokg = Str.replace_first (Str.regexp ",") "#" sok
+ in
+ let sokgs = Str.global_replace (Str.regexp ",") "/" sokg
+ *)
+ let pos= String.index sok '"'
+ in
+ let sokv= Str.string_before sok pos
+ in
+
+ (* let sokve = sokv ^ ".xml"
+ in*)
+ aux inp pre path fi (sokv::acc)
+ end
+ else
+ (aux inp pre path fi acc)
+
+ else (* CASO pre SPECIFICO *)
+
+ begin
+ (*print_endline ("sok:" ^ sok);
+ print_endline ("path:" ^ path);*)
+
+ if (Str.string_match (Str.regexp path) sok 0) && (apre = pre)
+ then
+ begin
+ (*let sokg = Str.replace_first (Str.regexp ",") "#" sok
+ in
+ let sokgs = Str.global_replace (Str.regexp ",") "/" sokg
+ in*)
+ let pos= String.index sok '"'
+ in
+ let sokv= Str.string_before sok pos
+ in
+
+ (*let sokve = sokv ^ ".xml"
+ in*)
+ aux inp pre path fi (sokv::acc)
+ end
+ else
+ (aux inp pre path fi acc)
+
+ end
+
+ else (* CASO fi ESISTENTE *)
+
+ if pre = "[^/]*" (* CASO pre QUALSIASI*)
+ then
+
+ if String.contains sok ','
+ then
+ let pos = String.index sok ',' in
+ let sokwfi = Str.string_before sok pos in
+ if (Str.string_match (Str.regexp path) sokwfi 0) &&
+ (Str.string_match (Str.regexp fi) (extract_fid sok) 0)
+ then
+ begin
+ (*let sokg = Str.replace_first (Str.regexp ",") "#" sok
+ in
+ let sokgs = Str.global_replace (Str.regexp ",") "/" sokg
+ in*)
+ let pos= String.index sok '"'
+ in
+ let sokv= Str.string_before sok pos
+ in
+ (* let sokve = sokv ^ ".xml"
+ in*)
+ aux inp pre path fi (sokv::acc)
+ end
+ else
+ (aux inp pre path fi acc)
+ else
+ (aux inp pre path fi acc)
+
+ else (* CASO pre SPECIFICO *)
+ if String.contains sok ','
+ then
+ let pos = String.index sok ',' in
+ let sokwfi = Str.string_before sok pos in
+ if (Str.string_match (Str.regexp path) sokwfi 0) &&
+ (Str.string_match (Str.regexp fi) (extract_fid sok) 0) && (apre = pre)
+ then
+ begin
+ (*let sokg = Str.replace_first (Str.regexp ",") "#" sok
+ in
+ let sokgs = Str.global_replace (Str.regexp ",") "/" sokg
+ in*)
+ let pos= String.index sok '"'
+ in
+ let sokv= Str.string_before sok pos
+ in
+ (*let sokve = sokv ^ ".xml"
+ in*)
+ aux inp pre path fi (sokv::acc)
+ end
+ else
+ (aux inp pre path fi acc)
+ else
+ (aux inp pre path fi acc)
+ end
+ else
+ (aux inp pre path fi acc)
+ | None -> List.rev acc
+ in
+ aux inp pre path fi []
+;;
+
+
+
+
+(* Data una lista di token restituisce la stringa formata da tutti i token ----> DA TESTARE!!!! *)
+let rec token_to_str p =
+ match p with
+ [] -> ""
+ | head::tail ->
+ let h = match head with
+ MQBC s -> Str.global_replace (Str.regexp "\.") "." s
+ | MQBD -> "/"
+ | MQBQ -> "[^/#]?"
+ | MQBS -> "[^/#]*"
+ | MQBSS -> "[^#]*"
+ in
+ h ^ (token_to_str tail)
+;;
+
+
+let rec fieval fi =
+ match fi with
+ [] -> ""
+ | MQFC i :: tail -> "/" ^ (string_of_int i) ^ (fieval tail)
+ | MQFS :: tail -> "[^/]*" ^ (fieval tail)
+ | MQFSS :: tail -> ".*" ^ (fieval tail)
+;;
+
+(*
+ * conversione di un fragment identifier
+ *)
+let fieval fi =
+ if fi = [] then
+ ""
+ else
+ "#xpointer\\\\(1" ^ fieval fi ^ "\\\\)" (* NON MI E' CHIARO IL PERCHE'!!!! *)
+;;
+
+
+let rec attul uril =
+ match uril with
+ head::tail -> let uril_hd = List.hd uril in
+ { uri = uril_hd; attributes = []; extra = ""}::attul (List.tl uril);
+ | [] -> [];
+;;
+
+
+(* prende preambolo, body (lista di token con "/"), fi (lista di token senza
+"/") e restituisce la lista
+di uri (LISTA DI attributed_uri), contenuti nel file getallrdfuris.xml, che fanno match con l'espressione regolare ricavata da body e con quella ricavata da fi.. tutto
+chiamando la "pmatch()"
+
+ATTENZIONE: il tag in getallrdfuris.xml deve essere piu' lungo,
+ altrimenti "string_match()" da' errore!
+
+*)
+let pattern_ex (apreamble, apattern, afragid) =
+ let path = token_to_str apattern in
+ let fi = fieval afragid in
+ let pre = preeval apreamble in
+ let inp = open_in "./getallrdfuris.xml" in
+ seek_in inp 146;
+ let uril = pmatch inp pre path fi in
+ attul uril;
+;;
+
+
+
+
+
diff --git a/helm/ocaml/mathql_interpreter_galax/pattern.mli b/helm/ocaml/mathql_interpreter_galax/pattern.mli
new file mode 100644
index 000000000..1fd21bdba
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/pattern.mli
@@ -0,0 +1,28 @@
+(* 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://cs.unibo.it/helm/.
+ *)
+
+val pattern_ex :
+ MathQL.mqtref ->
+ Mathql_semantics.result
diff --git a/helm/ocaml/mathql_interpreter_galax/pervasive.xq b/helm/ocaml/mathql_interpreter_galax/pervasive.xq
new file mode 100644
index 000000000..9105b9e29
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/pervasive.xq
@@ -0,0 +1,192 @@
+#######################
+# Standard namespaces #
+#######################
+
+namespace xsd = "http://www.w3c.org/xsd"
+namespace xs = "http://www.w3c.org/xs"
+namespace xml = "http://www.w3.org/xml"
+
+#############################
+# XML Schema wildcard types #
+#############################
+
+define type xs:AnyNumeric { xsd:decimal | xsd:integer | xsd:int | xsd:double | xsd:float }
+
+define type xs:AnyScalar { xsd:boolean |
+ xsd:string |
+ type xs:AnyNumeric |
+ xsd:UnknownSimpleType }
+
+define type xs:AnySimpleType { type xs:AnyScalar* }
+define type xs:AnyAttribute { attribute * { type xs:AnySimpleType } }
+define type xs:AnyElement { element * { type xs:AnyContentModel } }
+define type xs:AnyContentModel { (type xs:AnyAttribute*, (type xs:AnySimpleType | (type xs:AnyElement |
+text)*)) }
+define type xs:AnyDocument { document { type xs:AnyElement } }
+
+#########################
+# XQuery Wildcard types #
+#########################
+define type xs:AnyNode { type xs:AnyElement | type xs:AnyAttribute | text }
+
+define type xs:AnyItem { type xs:AnyNode | type xs:AnyScalar }
+define type xs:AnyType { type xs:AnyItem* }
+
+
+######################
+# Standard functions #
+######################
+
+# data-model accessors.
+# F&O doc. Section 2
+
+define function signature local-name(type xs:AnyNode) returns (xsd:string)
+define function signature name(type xs:AnyNode) returns (xsd:string?)
+define function signature children(type xs:AnyNode) returns (type xs:AnyNode*)
+define function signature attributes(type xs:AnyElement) returns (type xs:AnyAttribute*)
+define function signature parent(type xs:AnyNode) returns (type xs:AnyElement?)
+define function signature data(type xs:AnyNode) returns (type xs:AnySimpleType)
+
+# F&O doc. Section 3.2
+define function signature decimal(xsd:string) returns (xsd:int)
+define function signature integer(xsd:string) returns (xsd:int)
+define function signature long(xsd:string) returns (xsd:int)
+define function signature int(xsd:string) returns (xsd:int)
+define function signature short(xsd:string) returns (xsd:int)
+define function signature byte(xsd:string) returns (xsd:int)
+define function signature float(xsd:string) returns (xsd:double)
+define function signature double(xsd:string) returns (xsd:double)
+
+# polymorphic arithmetic operations #
+# F&O doc, Section 3.3
+
+define function signature numeric-add(numeric, numeric) returns (numeric)
+define function signature numeric-subtract(numeric, numeric) returns (numeric)
+define function signature numeric-multiply(numeric, numeric) returns (numeric)
+define function signature numeric-divide(numeric, numeric) returns (numeric)
+define function signature numeric-mod(numeric, numeric) returns (numeric)
+
+define function signature numeric-unary-plus(numeric) returns (numeric)
+define function signature numeric-unary-minus(numeric) returns (numeric)
+
+# Galax's monomorphic arithmetic operations #
+
+# Caml's int
+define function signature int-add(xsd:int, xsd:int) returns (xsd:int)
+define function signature int-subtract(xsd:int, xsd:int) returns (xsd:int)
+define function signature int-multiply(xsd:int, xsd:int) returns (xsd:int)
+define function signature int-divide(xsd:int, xsd:int) returns (xsd:int)
+define function signature int-mod(xsd:int, xsd:int) returns (xsd:int)
+
+define function signature int-unary-plus(xsd:int) returns (xsd:int)
+define function signature int-unary-minus(xsd:int) returns (xsd:int)
+
+# xsd:decimal
+define function signature decimal-add(xsd:decimal, xsd:decimal) returns (xsd:decimal)
+define function signature decimal-subtract(xsd:decimal, xsd:decimal) returns (xsd:decimal)
+define function signature decimal-multiply(xsd:decimal, xsd:decimal) returns (xsd:decimal)
+define function signature decimal-divide(xsd:decimal, xsd:decimal) returns (xsd:decimal)
+define function signature decimal-mod(xsd:decimal, xsd:decimal) returns (xsd:decimal)
+
+define function signature decimal-unary-plus(xsd:decimal) returns (xsd:decimal)
+define function signature decimal-unary-minus(xsd:decimal) returns (xsd:decimal)
+
+# xsd:float
+define function signature float-add(xsd:float, xsd:float) returns (xsd:float)
+define function signature float-subtract(xsd:float, xsd:float) returns (xsd:float)
+define function signature float-multiply(xsd:float, xsd:float) returns (xsd:float)
+define function signature float-divide(xsd:float, xsd:float) returns (xsd:float)
+define function signature float-mod(xsd:float, xsd:float) returns (xsd:float)
+
+define function signature float-unary-plus(xsd:float) returns (xsd:float)
+define function signature float-unary-minus(xsd:float) returns (xsd:float)
+
+# xsd:double
+define function signature double-add(xsd:double, xsd:double) returns (xsd:double)
+define function signature double-subtract(xsd:double, xsd:double) returns (xsd:double)
+define function signature double-multiply(xsd:double, xsd:double) returns (xsd:double)
+define function signature double-divide(xsd:double, xsd:double) returns (xsd:double)
+define function signature double-mod(xsd:double, xsd:double) returns (xsd:double)
+
+define function signature double-unary-plus(xsd:double) returns (xsd:double)
+define function signature double-unary-minus(xsd:double) returns (xsd:double)
+
+# comparators #
+# F&O doc, Section 3.4
+define function signature nodeeq(type xs:AnyNode, type xs:AnyNode) returns (xsd:boolean)
+define function signature equal(type xs:AnyScalar, type xs:AnyScalar) returns (xsd:boolean)
+define function signature nequal(type xs:AnyScalar, type xs:AnyScalar) returns (xsd:boolean)
+define function signature ge(type xs:AnyScalar, type xs:AnyScalar) returns (xsd:boolean)
+define function signature le(type xs:AnyScalar, type xs:AnyScalar) returns (xsd:boolean)
+define function signature gt(type xs:AnyScalar, type xs:AnyScalar) returns (xsd:boolean)
+define function signature lt(type xs:AnyScalar, type xs:AnyScalar) returns (xsd:boolean)
+
+# F&O doc. Section 3.5
+define function signature floor(xsd:double) returns (xsd:int)
+define function signature ceiling(xsd:double) returns (xsd:int)
+define function signature round(xsd:double) returns (xsd:int)
+
+# functions on strings
+# F&O doc. Section 4.4
+define function signature concat(xsd:string, xsd:string) returns (xsd:string)
+define function signature starts-with(xsd:string, xsd:string) returns (xsd:boolean)
+define function signature ends-with(xsd:string, xsd:string) returns (xsd:boolean)
+define function signature contains(xsd:string, xsd:string) returns (xsd:boolean)
+define function signature substring(xsd:string, xsd:int, xsd:int) returns (xsd:string)
+define function signature string-length(xsd:string) returns (xsd:int)
+define function signature substring-before(xsd:string, xsd:string) returns (xsd:string)
+define function signature substring-after(xsd:string, xsd:string) returns (xsd:string)
+define function signature normalize-space(xsd:string) returns (xsd:string)
+define function signature normalize-unicode(xsd:string) returns (xsd:string)
+define function signature upper-case(xsd:string) returns (xsd:string)
+define function signature lower-case(xsd:string) returns (xsd:string)
+define function signature translate(xsd:string, xsd:string, xsd:string) returns (xsd:string)
+define function signature string-pad(xsd:string, xsd:int, xsd:string) returns (xsd:string)
+define function signature match(xsd:string, xsd:string) returns (xsd:int*)
+define function signature replace(xsd:string, xsd:string, xsd:string) returns (xsd:string)
+
+define function signature codepoint-contains(xsd:string, xsd:string) returns (xsd:boolean)
+define function signature codepoint-substring-before(xsd:string, xsd:string) returns (xsd:string)
+define function signature codepoint-substring-after(xsd:string, xsd:string) returns (xsd:string)
+
+# boolean operations #
+# F&O doc, Section 6.1
+define function signature true() returns (xsd:boolean)
+define function signature false() returns (xsd:boolean)
+
+# F&O doc, Section 6.2
+define function signature or(xsd:boolean, xsd:boolean) returns (xsd:boolean)
+define function signature and(xsd:boolean, xsd:boolean) returns (xsd:boolean)
+define function signature not(xsd:boolean) returns (xsd:boolean)
+
+# functions on sequences #
+# F&O doc, Section 13.2
+define function signature index-of(type xs:AnyNode*, type xs:AnyNode) returns (xsd:int)
+define function signature length(type xs:AnyType) returns (xsd:int)
+define function signature empty(type xs:AnyType) returns (xsd:boolean)
+define function signature distinct-values(type xs:AnyType) returns (type xs:AnyType)
+
+# aggregate functions #
+# F&O doc, Section 13.4
+define function signature avg-int(xsd:int*) returns (xsd:int)
+define function signature max-int(xsd:int*) returns (xsd:int?)
+define function signature min-int(xsd:int*) returns (xsd:int?)
+define function signature sum-int(xsd:int*) returns (xsd:int)
+
+define function signature avg-float(xsd:double*) returns (xsd:double)
+define function signature max-float(xsd:double*) returns (xsd:double?)
+define function signature min-float(xsd:double*) returns (xsd:double?)
+define function signature sum-float(xsd:double*) returns (xsd:double)
+
+define function signature count(type xs:AnyType) returns (xsd:int)
+
+# input-output operations #
+
+# The signature below is a hack : The output of document is declared
+# as the empty choice to avoid the need for explicit cast by the user
+# when loading the document - JS #
+
+# F&O doc, Section 13.5
+define function signature document(xsd:string) returns (type xs:AnyDocument)
+define function signature document-validate(xsd:string, xsd:string) returns (type xs:AnyDocument)
+
diff --git a/helm/ocaml/mathql_interpreter_galax/pervasive.xqp b/helm/ocaml/mathql_interpreter_galax/pervasive.xqp
new file mode 100644
index 000000000..c7a4b1ae8
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/pervasive.xqp
@@ -0,0 +1,192 @@
+#######################
+# Standard namespaces #
+#######################
+
+namespace xsd = "%%XSDURI%%"
+namespace xs = "%%XSURI%%"
+namespace xml = "%%XMLURI%%"
+
+#############################
+# XML Schema wildcard types #
+#############################
+
+define type xs:AnyNumeric { xsd:decimal | xsd:integer | xsd:int | xsd:double | xsd:float }
+
+define type xs:AnyScalar { xsd:boolean |
+ xsd:string |
+ type xs:AnyNumeric |
+ xsd:UnknownSimpleType }
+
+define type xs:AnySimpleType { type xs:AnyScalar* }
+define type xs:AnyAttribute { attribute * { type xs:AnySimpleType } }
+define type xs:AnyElement { element * { type xs:AnyContentModel } }
+define type xs:AnyContentModel { (type xs:AnyAttribute*, (type xs:AnySimpleType | (type xs:AnyElement |
+text)*)) }
+define type xs:AnyDocument { document { type xs:AnyElement } }
+
+#########################
+# XQuery Wildcard types #
+#########################
+define type xs:AnyNode { type xs:AnyElement | type xs:AnyAttribute | text }
+
+define type xs:AnyItem { type xs:AnyNode | type xs:AnyScalar }
+define type xs:AnyType { type xs:AnyItem* }
+
+
+######################
+# Standard functions #
+######################
+
+# data-model accessors.
+# F&O doc. Section 2
+
+define function signature local-name(type xs:AnyNode) returns (xsd:string)
+define function signature name(type xs:AnyNode) returns (xsd:string?)
+define function signature children(type xs:AnyNode) returns (type xs:AnyNode*)
+define function signature attributes(type xs:AnyElement) returns (type xs:AnyAttribute*)
+define function signature parent(type xs:AnyNode) returns (type xs:AnyElement?)
+define function signature data(type xs:AnyNode) returns (type xs:AnySimpleType)
+
+# F&O doc. Section 3.2
+define function signature decimal(xsd:string) returns (xsd:int)
+define function signature integer(xsd:string) returns (xsd:int)
+define function signature long(xsd:string) returns (xsd:int)
+define function signature int(xsd:string) returns (xsd:int)
+define function signature short(xsd:string) returns (xsd:int)
+define function signature byte(xsd:string) returns (xsd:int)
+define function signature float(xsd:string) returns (xsd:double)
+define function signature double(xsd:string) returns (xsd:double)
+
+# polymorphic arithmetic operations #
+# F&O doc, Section 3.3
+
+define function signature numeric-add(numeric, numeric) returns (numeric)
+define function signature numeric-subtract(numeric, numeric) returns (numeric)
+define function signature numeric-multiply(numeric, numeric) returns (numeric)
+define function signature numeric-divide(numeric, numeric) returns (numeric)
+define function signature numeric-mod(numeric, numeric) returns (numeric)
+
+define function signature numeric-unary-plus(numeric) returns (numeric)
+define function signature numeric-unary-minus(numeric) returns (numeric)
+
+# Galax's monomorphic arithmetic operations #
+
+# Caml's int
+define function signature int-add(xsd:int, xsd:int) returns (xsd:int)
+define function signature int-subtract(xsd:int, xsd:int) returns (xsd:int)
+define function signature int-multiply(xsd:int, xsd:int) returns (xsd:int)
+define function signature int-divide(xsd:int, xsd:int) returns (xsd:int)
+define function signature int-mod(xsd:int, xsd:int) returns (xsd:int)
+
+define function signature int-unary-plus(xsd:int) returns (xsd:int)
+define function signature int-unary-minus(xsd:int) returns (xsd:int)
+
+# xsd:decimal
+define function signature decimal-add(xsd:decimal, xsd:decimal) returns (xsd:decimal)
+define function signature decimal-subtract(xsd:decimal, xsd:decimal) returns (xsd:decimal)
+define function signature decimal-multiply(xsd:decimal, xsd:decimal) returns (xsd:decimal)
+define function signature decimal-divide(xsd:decimal, xsd:decimal) returns (xsd:decimal)
+define function signature decimal-mod(xsd:decimal, xsd:decimal) returns (xsd:decimal)
+
+define function signature decimal-unary-plus(xsd:decimal) returns (xsd:decimal)
+define function signature decimal-unary-minus(xsd:decimal) returns (xsd:decimal)
+
+# xsd:float
+define function signature float-add(xsd:float, xsd:float) returns (xsd:float)
+define function signature float-subtract(xsd:float, xsd:float) returns (xsd:float)
+define function signature float-multiply(xsd:float, xsd:float) returns (xsd:float)
+define function signature float-divide(xsd:float, xsd:float) returns (xsd:float)
+define function signature float-mod(xsd:float, xsd:float) returns (xsd:float)
+
+define function signature float-unary-plus(xsd:float) returns (xsd:float)
+define function signature float-unary-minus(xsd:float) returns (xsd:float)
+
+# xsd:double
+define function signature double-add(xsd:double, xsd:double) returns (xsd:double)
+define function signature double-subtract(xsd:double, xsd:double) returns (xsd:double)
+define function signature double-multiply(xsd:double, xsd:double) returns (xsd:double)
+define function signature double-divide(xsd:double, xsd:double) returns (xsd:double)
+define function signature double-mod(xsd:double, xsd:double) returns (xsd:double)
+
+define function signature double-unary-plus(xsd:double) returns (xsd:double)
+define function signature double-unary-minus(xsd:double) returns (xsd:double)
+
+# comparators #
+# F&O doc, Section 3.4
+define function signature nodeeq(type xs:AnyNode, type xs:AnyNode) returns (xsd:boolean)
+define function signature equal(type xs:AnyScalar, type xs:AnyScalar) returns (xsd:boolean)
+define function signature nequal(type xs:AnyScalar, type xs:AnyScalar) returns (xsd:boolean)
+define function signature ge(type xs:AnyScalar, type xs:AnyScalar) returns (xsd:boolean)
+define function signature le(type xs:AnyScalar, type xs:AnyScalar) returns (xsd:boolean)
+define function signature gt(type xs:AnyScalar, type xs:AnyScalar) returns (xsd:boolean)
+define function signature lt(type xs:AnyScalar, type xs:AnyScalar) returns (xsd:boolean)
+
+# F&O doc. Section 3.5
+define function signature floor(xsd:double) returns (xsd:int)
+define function signature ceiling(xsd:double) returns (xsd:int)
+define function signature round(xsd:double) returns (xsd:int)
+
+# functions on strings
+# F&O doc. Section 4.4
+define function signature concat(xsd:string, xsd:string) returns (xsd:string)
+define function signature starts-with(xsd:string, xsd:string) returns (xsd:boolean)
+define function signature ends-with(xsd:string, xsd:string) returns (xsd:boolean)
+define function signature contains(xsd:string, xsd:string) returns (xsd:boolean)
+define function signature substring(xsd:string, xsd:int, xsd:int) returns (xsd:string)
+define function signature string-length(xsd:string) returns (xsd:int)
+define function signature substring-before(xsd:string, xsd:string) returns (xsd:string)
+define function signature substring-after(xsd:string, xsd:string) returns (xsd:string)
+define function signature normalize-space(xsd:string) returns (xsd:string)
+define function signature normalize-unicode(xsd:string) returns (xsd:string)
+define function signature upper-case(xsd:string) returns (xsd:string)
+define function signature lower-case(xsd:string) returns (xsd:string)
+define function signature translate(xsd:string, xsd:string, xsd:string) returns (xsd:string)
+define function signature string-pad(xsd:string, xsd:int, xsd:string) returns (xsd:string)
+define function signature match(xsd:string, xsd:string) returns (xsd:int*)
+define function signature replace(xsd:string, xsd:string, xsd:string) returns (xsd:string)
+
+define function signature codepoint-contains(xsd:string, xsd:string) returns (xsd:boolean)
+define function signature codepoint-substring-before(xsd:string, xsd:string) returns (xsd:string)
+define function signature codepoint-substring-after(xsd:string, xsd:string) returns (xsd:string)
+
+# boolean operations #
+# F&O doc, Section 6.1
+define function signature true() returns (xsd:boolean)
+define function signature false() returns (xsd:boolean)
+
+# F&O doc, Section 6.2
+define function signature or(xsd:boolean, xsd:boolean) returns (xsd:boolean)
+define function signature and(xsd:boolean, xsd:boolean) returns (xsd:boolean)
+define function signature not(xsd:boolean) returns (xsd:boolean)
+
+# functions on sequences #
+# F&O doc, Section 13.2
+define function signature index-of(type xs:AnyNode*, type xs:AnyNode) returns (xsd:int)
+define function signature length(type xs:AnyType) returns (xsd:int)
+define function signature empty(type xs:AnyType) returns (xsd:boolean)
+define function signature distinct-values(type xs:AnyType) returns (type xs:AnyType)
+
+# aggregate functions #
+# F&O doc, Section 13.4
+define function signature avg-int(xsd:int*) returns (xsd:int)
+define function signature max-int(xsd:int*) returns (xsd:int?)
+define function signature min-int(xsd:int*) returns (xsd:int?)
+define function signature sum-int(xsd:int*) returns (xsd:int)
+
+define function signature avg-float(xsd:double*) returns (xsd:double)
+define function signature max-float(xsd:double*) returns (xsd:double?)
+define function signature min-float(xsd:double*) returns (xsd:double?)
+define function signature sum-float(xsd:double*) returns (xsd:double)
+
+define function signature count(type xs:AnyType) returns (xsd:int)
+
+# input-output operations #
+
+# The signature below is a hack : The output of document is declared
+# as the empty choice to avoid the need for explicit cast by the user
+# when loading the document - JS #
+
+# F&O doc, Section 13.5
+define function signature document(xsd:string) returns (type xs:AnyDocument)
+define function signature document-validate(xsd:string, xsd:string) returns (type xs:AnyDocument)
+
diff --git a/helm/ocaml/mathql_interpreter_galax/select.ml b/helm/ocaml/mathql_interpreter_galax/select.ml
new file mode 100644
index 000000000..88477faf0
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/select.ml
@@ -0,0 +1,145 @@
+(* 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 SELECT
+ *)
+
+open MathQL;;
+open Func;;
+
+
+exception ExecuteFunctionNotInitialized;;
+let execute =
+ ref
+ (function _ -> raise ExecuteFunctionNotInitialized)
+;;
+
+(*
+ * valutazione di una stringa
+ *)
+let stringeval env =
+ let module S = Mathql_semantics in
+ function
+ MQCons s ->
+ s
+ | MQFunc (f, rvar) ->
+ let {S.uri = uri} = List.assoc rvar env in
+ apply_func f uri
+ | MQStringRVar rvar ->
+ let {S.uri = uri} = List.assoc rvar env in
+ uri
+ | MQStringSVar svar ->
+ let (_,{S.attributes = attributes}) = List.hd env in
+ List.assoc svar attributes
+ | MQMConclusion ->
+ "MainConclusion"
+ | MQConclusion ->
+ "InConclusion"
+;;
+
+
+
+
+let rec is_good env =
+ let module S = Mathql_semantics in
+ function
+ MQAnd (b1, b2) ->
+ (is_good env b1) && (is_good env b2)
+ | MQOr (b1, b2) ->
+ (is_good env b1) || (is_good env b2)
+ | MQNot b1 ->
+ not (is_good env b1)
+ | MQTrue ->
+ true
+ | MQFalse ->
+ false
+ | MQIs (s1, s2) ->
+ (stringeval env s1) = (stringeval env s2)
+(*CSC: magari le prossime funzioni dovrebbero andare in un file a parte, *)
+(*CSC: insieme alla [execute] che utilizzano *)
+ | MQSetEqual (q1,q2) ->
+ (* set_of_result returns an ordered list of uris without duplicates *)
+ let rec set_of_result =
+ function
+ _,[] -> []
+ | (Some olduri as v),{S.uri = uri}::tl when uri = olduri ->
+ set_of_result (v,tl)
+ | _,{S.uri = uri}::tl ->
+ uri::(set_of_result (Some uri, tl))
+ in
+ let ul1 = set_of_result (None,!execute env q1) in
+ let ul2 = set_of_result (None,!execute env q2) in
+prerr_endline ("MQSETEQUAL(" ^ string_of_int (List.length (!execute env q1)) ^ ">" ^ string_of_int (List.length ul1) ^ "," ^ string_of_int (List.length (!execute env q2)) ^ ">" ^ string_of_int (List.length ul2) ^ ")") ; flush stderr ;
+ (try
+ List.fold_left2 (fun b uri1 uri2 -> b && uri1=uri2) true ul1 ul2
+ with
+ _ -> false)
+ | MQSubset (q1,q2) ->
+(*CSC: codice cut&paste da sopra: ridurlo facendo un'unica funzione h.o. *)
+ (* set_of_result returns an ordered list of uris without duplicates *)
+ let rec set_of_result =
+ function
+ _,[] -> []
+ | (Some olduri as v),{S.uri = uri}::tl when uri = olduri ->
+ set_of_result (v,tl)
+ | _,{S.uri = uri}::tl ->
+ uri::(set_of_result (Some uri, tl))
+ in
+ let ul1 = set_of_result (None,!execute env q1) in
+ let ul2 = set_of_result (None,!execute env q2) in
+prerr_endline ("MQSUBSET(" ^ string_of_int (List.length (!execute env q1)) ^ ">" ^ string_of_int (List.length ul1) ^ "," ^ string_of_int (List.length (!execute env q2)) ^ ">" ^ string_of_int (List.length ul2) ^ ")") ; flush stderr ;
+ let rec is_subset s1 s2 =
+ match s1,s2 with
+ [],_ -> true
+ | _,[] -> false
+ | uri1::tl1,uri2::tl2 when uri1 = uri2 ->
+ is_subset tl1 tl2
+ | uri1::_,uri2::tl2 when uri1 > uri2 ->
+ is_subset s1 tl2
+ | _,_ -> false
+ in
+ is_subset ul1 ul2
+;;
+
+
+(*
+ * implementazione del comando SELECT
+ *)
+
+
+let select_ex env avar alist abool =
+ let _ = print_string ("SELECT = ")
+ and t = Unix.time () in
+ let result =
+ List.filter (function entry -> is_good ((avar,entry)::env) abool) alist
+ in
+ print_string (string_of_int (List.length result) ^ ": ") ;
+ print_endline (string_of_float (Unix.time () -. t) ^ "s") ;
+ flush stdout ;
+ result
+;;
+
+
diff --git a/helm/ocaml/mathql_interpreter_galax/select.mli b/helm/ocaml/mathql_interpreter_galax/select.mli
new file mode 100644
index 000000000..7c2fe9ddf
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/select.mli
@@ -0,0 +1,34 @@
+(* 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://cs.unibo.it/helm/.
+ *)
+
+exception ExecuteFunctionNotInitialized;;
+val execute:
+ (Mathql_semantics.attributed_uri_env ->
+ MathQL.mqlist -> Mathql_semantics.result) ref
+
+val select_ex :
+ Mathql_semantics.attributed_uri_env ->
+ MathQL.mqrvar -> Mathql_semantics.result -> MathQL.mqbool ->
+ Mathql_semantics.result
diff --git a/helm/ocaml/mathql_interpreter_galax/sortedby.ml b/helm/ocaml/mathql_interpreter_galax/sortedby.ml
new file mode 100644
index 000000000..0709bcca1
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/sortedby.ml
@@ -0,0 +1,62 @@
+(* 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 SORTEDBY
+ *)
+
+open MathQL;;
+open Func;;
+(*open Utility;;*)
+
+(*
+ * implementazione del comando SORTEDBY
+ *)
+let sortedby_ex alist order afunc =
+ let before = Unix.time () in
+ let res =
+ let module S = Mathql_semantics in
+ (Sort.list
+ (fun {S.extra = e1} {S.extra = e2} ->
+ match order with
+ MQAsc -> e1 < e2
+ | MQDesc -> e1 > e2
+ )
+ (List.map
+ (fun {S.uri = u ; S.attributes = attr} -> {S.uri = u ; S.attributes = attr ; S.extra = (apply_func afunc u)})
+ alist
+ )
+ )
+ in
+ let after = Unix.time ()
+ and ll1 = string_of_int (List.length alist) in
+ let diff = string_of_float (after -. before) in
+ prerr_endline
+ ("SORTEDBY(" ^ ll1 ^ ") = " ^ string_of_int (List.length res) ^
+ ": " ^ diff ^ "s") ;
+ flush stderr ;
+ res
+;;
+
diff --git a/helm/ocaml/mathql_interpreter_galax/sortedby.mli b/helm/ocaml/mathql_interpreter_galax/sortedby.mli
new file mode 100644
index 000000000..863581a09
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/sortedby.mli
@@ -0,0 +1,27 @@
+(* 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://cs.unibo.it/helm/.
+ *)
+
+val sortedby_ex :
+ Mathql_semantics.result -> MathQL.mqorder -> MathQL.mqfunc -> Mathql_semantics.result
diff --git a/helm/ocaml/mathql_interpreter_galax/test_intersect.ml b/helm/ocaml/mathql_interpreter_galax/test_intersect.ml
new file mode 100755
index 000000000..e86251d32
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/test_intersect.ml
@@ -0,0 +1,69 @@
+
+
+
+
+
+open Mathql_semantics;;
+open MathQL;;
+
+(* stampa tutti i documenti che fanno match con un pattern di input *)
+List.iter
+ (function atturi -> print_endline ("output: " ^ atturi))
+ (match Mqint2.execute
+ (MQList
+ (MQIntersect
+ (
+ (MQSelect
+ (
+ (*SELECT*) "uri0",
+ (* IN *) MQUse
+ (MQPattern
+ (
+ Some "cic",
+ [MQBD; MQBC"Algebra"; MQBD; MQBC "Basics"; MQBD; MQBSS],
+ []
+ ),
+ "$s0"
+ ),
+ (*WHERE *) MQIs
+ (
+ MQStringSVar "$s0",
+ MQConclusion
+ )
+ )
+ ),
+ (MQSelect
+ (
+ (*SELECT*) "uri0",
+ (* IN *) MQUse
+ (MQPattern
+ (
+ Some "cic",
+ [MQBD; MQBC"Algebra"; MQBD; MQBC "Basics"; MQBD; MQBC "max.con"],
+ []
+ ),
+ "$s0"
+ ),
+ (*WHERE *) MQIs
+ (
+ MQStringSVar "$s0",
+ MQConclusion
+ )
+ )
+ )
+ )
+ )
+ )
+ with MQRefs l -> l
+ );
+
+;;
+
+
+
+
+
+
+
+
+
diff --git a/helm/ocaml/mathql_interpreter_galax/test_pattern.ml b/helm/ocaml/mathql_interpreter_galax/test_pattern.ml
new file mode 100755
index 000000000..a06eca8ed
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/test_pattern.ml
@@ -0,0 +1,28 @@
+
+
+
+open Mathql_semantics;;
+open MathQL;;
+
+(* stampa tutti i documenti che fanno match con un pattern di input *)
+List.iter
+ (function atturi -> print_endline ("output: " ^ atturi))
+ (match Mqint2.execute
+ (MQList
+ (MQPattern
+ (
+ Some "cic",
+ (* [MQBD;MQBC "Algebra"; MQBD; MQBC "Basics"; MQBSS],*)
+ [MQBD;MQBC "Algebra"; MQBD; MQBC "Basics"; MQBD;
+ MQBC"Z_exh.con"],
+ (*[MQBSS; MQBC ".var"],*)
+ []
+ )
+ )
+ ) with MQRefs l -> l
+ );
+
+
+
+ ;;
+
diff --git a/helm/ocaml/mathql_interpreter_galax/test_select.ml b/helm/ocaml/mathql_interpreter_galax/test_select.ml
new file mode 100755
index 000000000..98933520d
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/test_select.ml
@@ -0,0 +1,55 @@
+
+
+(*
+ select uri0
+ in use pattern "cic:/Coq/Reals/Rdefinitions/Rlt.con" position $s0
+ where $s0 is mainconclusion
+*)
+
+
+
+open Mathql_semantics;;
+open MathQL;;
+
+(* stampa tutti i documenti che fanno match con un pattern di input *)
+List.iter
+ (function atturi -> print_endline ("output: " ^ atturi))
+ (match Mqint2.execute
+ (MQList
+ (MQSelect
+ (
+ (*SELECT*) "uri0",
+ (* IN *) MQUse
+ (
+ MQPattern
+ (
+ Some "cic",
+ [MQBD; MQBC"Algebra"; MQBD; MQBC "Basics"; MQBD; MQBSS],
+ []
+ ),
+ "$s0"
+ ),
+ (*WHERE *) MQIs
+ (
+ MQStringSVar "$s0",
+ MQConclusion
+ )
+ )
+
+ )
+ )
+ with MQRefs l -> l
+ );
+
+
+
+;;
+
+
+
+
+
+
+
+
+
diff --git a/helm/ocaml/mathql_interpreter_galax/test_select2.ml b/helm/ocaml/mathql_interpreter_galax/test_select2.ml
new file mode 100644
index 000000000..12cc1fc9f
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/test_select2.ml
@@ -0,0 +1,55 @@
+
+
+(*
+ select uri0
+ in use pattern "cic:/Coq/Reals/Rdefinitions/Rlt.con" position $s0
+ where $s0 is mainconclusion
+*)
+
+
+
+open Mathql_semantics;;
+open MathQL;;
+
+(* stampa tutti i documenti che fanno match con un pattern di input *)
+List.iter
+ (function atturi -> print_endline ("output: " ^ atturi))
+ (match Mqint2.execute
+ (MQList
+ (MQSelect
+ (
+ (*SELECT*) "uri0",
+ (* IN *) MQUse
+ (
+ MQPattern
+ (
+ Some "cic",
+ [MQBD; MQBC"Algebra"; MQBD; MQBC "CC_Props"; MQBD; MQBSS],
+ []
+ ),
+ "$s0"
+ ),
+ (*WHERE *) MQIs
+ (
+ MQStringSVar "$s0",
+ MQConclusion
+ )
+ )
+
+ )
+ )
+ with MQRefs l -> l
+ );
+
+
+
+;;
+
+
+
+
+
+
+
+
+
diff --git a/helm/ocaml/mathql_interpreter_galax/test_union.ml b/helm/ocaml/mathql_interpreter_galax/test_union.ml
new file mode 100755
index 000000000..6998632e8
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/test_union.ml
@@ -0,0 +1,69 @@
+
+
+
+
+
+open Mathql_semantics;;
+open MathQL;;
+
+(* stampa tutti i documenti che fanno match con un pattern di input *)
+List.iter
+ (function atturi -> print_endline ("output: " ^ atturi))
+ (match Mqint2.execute
+ (MQList
+ (MQUnion
+ (
+ (MQSelect
+ (
+ (*SELECT*) "uri0",
+ (* IN *) MQUse
+ (MQPattern
+ (
+ Some "cic",
+ [MQBD; MQBC"Algebra"; MQBD; MQBC "Basics"; MQBD; MQBSS],
+ []
+ ),
+ "$s0"
+ ),
+ (*WHERE *) MQIs
+ (
+ MQStringSVar "$s0",
+ MQConclusion
+ )
+ )
+ ),
+ (MQSelect
+ (
+ (*SELECT*) "uri0",
+ (* IN *) MQUse
+ (MQPattern
+ (
+ Some "cic",
+ [MQBD; MQBC"Algebra"; MQBD; MQBC "CC_Props"; MQBD; MQBSS],
+ []
+ ),
+ "$s0"
+ ),
+ (*WHERE *) MQIs
+ (
+ MQStringSVar "$s0",
+ MQConclusion
+ )
+ )
+ )
+ )
+ )
+ )
+ with MQRefs l -> l
+ );
+
+;;
+
+
+
+
+
+
+
+
+
diff --git a/helm/ocaml/mathql_interpreter_galax/test_use.ml b/helm/ocaml/mathql_interpreter_galax/test_use.ml
new file mode 100644
index 000000000..a366e000a
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/test_use.ml
@@ -0,0 +1,29 @@
+
+
+open Mathql_semantics;;
+open MathQL;;
+
+(* stampa tutti i documenti che fanno match con un pattern di input *)
+List.iter
+ (function atturi -> print_endline ("output: " ^ atturi))
+ (match Mqint2.execute
+ (MQList
+ (MQUse
+ (MQPattern
+ (
+ Some "cic",
+ [MQBD; MQBC "Algebra"; MQBD; MQBC "Basics"; MQBSS],
+ (* [MQBD;MQBC "Algebra"; MQBD; MQBC "Basics"; MQBD;
+ MQBC"Z_exh.con"],*)
+ (*[MQBSS; MQBC ".var"],*)
+ []
+ ),
+ "pippo")
+ )
+ ) with MQRefs l -> l
+ );
+
+
+
+;;
+
diff --git a/helm/ocaml/mathql_interpreter_galax/tools.ml b/helm/ocaml/mathql_interpreter_galax/tools.ml
new file mode 100644
index 000000000..7be644224
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/tools.ml
@@ -0,0 +1,98 @@
+
+(* QUESTE FUNZIONI ORA NON VENGONO USATE, SONO STATE INSERITE NEI FILE DELLE
+
+ FUNZIONI CHE LE USANO!!!!*)
+
+
+
+open Unix;;
+
+(* Data una lista di token restituisce la stringa formata da tutti i token *)
+let rec token_to_str p =
+ match p with
+ [] -> ""
+ | head::tail ->
+ let h = match head with
+ MQBC s -> Str.global_replace (Str.regexp "\.") "\\\\\." s
+ | MQBD -> "/"
+ | MQBQ -> "[^/#]?"
+ | MQBS -> "[^/#]*"
+ | MQBSS -> "[^#]*"
+ in
+ h ^ (patterneval tail)
+;;
+
+
+
+
+(* data la lista dei token(fi) la trasforma in stringa aggiungendo la virgola
+tra un token e l'altro *)
+let rec fitoken_to_str p =
+ match p with
+ [] -> ""
+ | head::tail ->
+ let h = match head with
+ MQBQ -> "[^/#]?" ^ ","
+ | MQBS -> "[^/#]*" ^ ","
+ | MQBSS -> "[^#]*" ^ ","
+ in
+ h ^ (patterneval tail)
+;;
+
+
+
+
+
+
+
+(* NON SERVE ORA! *)
+
+(* Dato un path stringa restituisce la lista dei file contenuti a ogni livello
+nella dir relativa al path *)
+
+(*let rec entry_list aspattern dir =
+
+ if !contains(aspattern,'.')
+ then
+ let indir = opendir(aspattern) in
+ let ent = readdir(indir) in
+ if contains(ent, '.') (*se la entry e' un file*)
+ then [geturi(ent)] @ entry_list(readdir(indir), indir)
+ else
+ entry_list(ent, indir) (*se la entry e' una dir*)
+
+ else
+ [geturi(aspattern)] @ entry_list(readdir(dir), dir)*) (*se aspattern e' un file*)
+
+
+
+(* FUNZIONE DI MATCHING: prende il descrittore del file delle uri e il path da
+matchare formato stringa e restituisce la lista dei path che fanno match in
+formato stringa !! TAIL-RECURSIVE !! *)
+
+let pmatch inp path =
+ let rec aux inp path acc =
+
+ let s= try
+ Some (Str.string_after (input_line(inp)) 61)
+ with End_of_file -> None
+ in match s with
+ | Some s ->
+ if Str.string_match (Str.regexp path) s 0
+ then
+ begin
+ let p = (Str.match_end()-3)
+ in
+ aux inp path ((Str.string_before s p)::acc)
+ end
+ else
+ (aux inp path acc)
+ | None -> List.rev acc
+ in
+ aux inp path []
+;;
+
+
+
+
+
diff --git a/helm/ocaml/mathql_interpreter_galax/union.ml b/helm/ocaml/mathql_interpreter_galax/union.ml
new file mode 100644
index 000000000..2e83b7a7d
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/union.ml
@@ -0,0 +1,139 @@
+(* 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://cs.unibo.it/helm/.
+ *)
+
+(*
+ * implementazione del comando UNION
+ *)
+
+(*
+(*
+ *
+ *)
+let xres_fill_context hr h1 l1 =
+ match l1 with
+ [] -> []
+ | _ ->
+ let hh = List.combine h1 l1
+ in
+ List.map
+ (fun x ->
+ if (List.mem_assoc x hh) then
+ List.assoc x hh
+ else
+ ""
+ )
+ hr
+;;
+
+(*
+ * implementazione del comando UNION
+ *)
+let union_ex alist1 alist2 =
+ let head1 = List.hd alist1
+ and tail1 = List.tl alist1
+ and head2 = List.hd alist2
+ and tail2 = List.tl alist2 (* e fin qui ... *)
+ in
+ match (head1, head2) with
+ ([], _) -> assert false (* gli header non devono mai essere vuoti *)
+ | (_, []) -> assert false (* devono contenere almeno [retVal] *)
+ | (_, _) -> let headr = (head2 @
+ (List.find_all
+ (function t -> not (List.mem t head2))
+ head1)
+ ) in (* header del risultato finale *)
+ List.append (* il risultato finale e' la concatenazione ...*)
+ [headr] (* ... dell'header costruito prima ...*)
+ (Sort.list
+ (fun l m -> List.hd l < List.hd m)
+ (match (tail1, tail2) with (* e di una coda "unione" *)
+ ([], _) -> tail2 (* va bene perche' l'altra lista e' vuota *)
+ | (_, []) -> tail1 (* va bene perche' l'altra lista e' vuota *)
+ | (_, _) ->
+ let first = (* parte dell'unione che riguarda solo il primo set *)
+ List.map
+ (
+ fun l ->
+ [List.hd l] @
+ xres_fill_context (List.tl headr) (List.tl head1) (List.tl l)
+ )
+ tail1
+ in
+ List.fold_left
+ (fun par x ->
+ let y = (* elemento candidato ad entrare *)
+ [List.hd x]
+ @
+ xres_fill_context
+ (List.tl headr) (List.tl head2) (List.tl x)
+ in
+ par @ if (List.find_all (fun t -> t = y) par) = [] then
+ [y]
+ else
+ []
+ )
+ first (* List.fold_left *)
+ tail2 (* List.fold_left *)
+(* first @
+ List.map (fun l -> [List.hd l] @
+ xres_fill_context
+ (List.tl headr) (List.tl head2) (List.tl l)
+ ) tail2
+*)
+ ) (* match *)
+ )
+;;
+*)
+
+(* preserves order and gets rid of duplicates *)
+let rec union_ex l1 l2 =
+ let module S = Mathql_semantics in
+ match (l1, l2) with
+ [],l
+ | l,[] -> l
+ | ({S.uri = uri1} as entry1)::tl1,
+ ({S.uri = uri2} as entry2)::_ when uri1 < uri2 ->
+ entry1::(union_ex tl1 l2)
+ | ({S.uri = uri1} as entry1)::_,
+ ({S.uri = uri2} as entry2)::tl2 when uri2 < uri1 ->
+ entry2::(union_ex l1 tl2)
+ | entry1::tl1,entry2::tl2 -> (* same entry *)
+ if entry1 = entry2 then (* same attributes *)
+ entry1::(union_ex tl1 tl2)
+ else
+ assert false
+;;
+
+let union_ex l1 l2 =
+ let before = Unix.time () in
+ let res = union_ex l1 l2 in
+ let after = Unix.time () in
+ let ll1 = string_of_int (List.length l1) in
+ let ll2 = string_of_int (List.length l2) in
+ let diff = string_of_float (after -. before) in
+ prerr_endline ("UNION(" ^ ll1 ^ "," ^ ll2 ^ "): " ^ diff ^ "s") ;
+ flush stderr ;
+ res
+;;
diff --git a/helm/ocaml/mathql_interpreter_galax/union.mli b/helm/ocaml/mathql_interpreter_galax/union.mli
new file mode 100644
index 000000000..6b6ba6d27
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/union.mli
@@ -0,0 +1,27 @@
+(* 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://cs.unibo.it/helm/.
+ *)
+
+val union_ex :
+ Mathql_semantics.result -> Mathql_semantics.result -> Mathql_semantics.result
diff --git a/helm/ocaml/mathql_interpreter_galax/use.ml b/helm/ocaml/mathql_interpreter_galax/use.ml
new file mode 100644
index 000000000..c2a716b23
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/use.ml
@@ -0,0 +1,69 @@
+open Mathql_semantics;;
+
+
+(* prende una lista di uri (contenente alternativamente uri e pos) e costruisce una lista di attributed_uri *)
+let rec attl uril svar =
+ match uril with
+ | head::tail -> let suri = List.hd uril in
+ let len = String.length suri in
+ let scuri = String.sub suri 4 (len-4) in
+ if String.contains scuri '#' then
+ let pos = String.index scuri '#' in
+ let s1 = Str.string_before scuri pos in
+ let xp = Str.string_after scuri pos in
+ let xp = Str.global_replace (Str.regexp "#xpointer(1") "" xp in
+ let xp = Str.global_replace (Str.regexp "\/") "," xp in
+ let xp = Str.global_replace (Str.regexp ")") "" xp in
+ let scuri = (s1 ^ xp) in
+
+ let uril_tl = List.tl uril in
+ {uri = scuri; attributes = [(svar, (List.hd
+ uril_tl))]; extra = ""} :: (attl (List.tl uril_tl) svar)
+ else
+ let uril_tl = List.tl uril in
+ {uri = scuri; attributes = [(svar, (List.hd
+ uril_tl))]; extra = ""} :: (attl (List.tl uril_tl) svar)
+ | [] -> []
+
+
+
+
+
+(* prende un attributed_uri e una svar e restituisce la lista degli
+attributed_uri (backward o forward in base al parametro "d") associando
+la posizione alla var passata *)
+
+let muse svar d path =
+ let dir =
+ match d with
+ "F" -> "/projects/helm/metadata/create4/forward"
+ | _ -> "/projects/helm/metadata/create4/backward"
+ in
+ let dtag =
+ match d with
+ "F" -> "refObj"
+ | _ -> "backPointer" in
+
+ let xq ="namespace h=\"http://www.cs.unibo.it/helm/schemas/mattone.rdf#\"
+ namespace rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"
+ for $i in document(" ^ "\"" ^ dir ^ path.uri ^ ".xml" ^ "\"" ^
+ ")/rdf:RDF/h:Object//h:" ^ dtag ^ "/h:Occurrence
+ return ($i/h:occurrence, $i/h:position)"
+
+ in
+ let uril = Toputils.eval_query_string xq in (* e' una lista di liste di stringhe*)
+ let hd_uril = List.hd uril in(*prendo l'elemento in testa che e' quello
+ che contiene la lista di uri*)
+ attl hd_uril svar (* adesso dalla lista di uri(hd_uril) costruisco una lista di attributed_uri*)
+
+
+
+
+(* prende una lista di uri (Mathql_semantics.result), una variabile (a cui
+associare la posizione), e la direzione (forward o backward) e per ogni uri chiama la muse *)
+let use_ex ulist svar d =
+ List.stable_sort (fun {uri = uri1} {uri = uri2} -> compare uri1 uri2) (List.concat (List.map (muse svar d) ulist))
+;;
+
+
+
diff --git a/helm/ocaml/mathql_interpreter_galax/use.mli b/helm/ocaml/mathql_interpreter_galax/use.mli
new file mode 100644
index 000000000..1dc2b207f
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/use.mli
@@ -0,0 +1,4 @@
+val use_ex:
+ Mathql_semantics.result -> MathQL.mqsvar -> string -> Mathql_semantics.result
+
+
diff --git a/helm/ocaml/mathql_interpreter_galax/utility.ml b/helm/ocaml/mathql_interpreter_galax/utility.ml
new file mode 100644
index 000000000..5ea9b7e67
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/utility.ml
@@ -0,0 +1,119 @@
+(* 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/.
+ *)
+
+(*
+ * funzioni di utilita' generale
+ *)
+
+open Dbconn;;
+
+(*
+ * converte il risultato di una query in una lista di stringhe
+ *
+ * parametri:
+ * l: Postgres.result; risultato della query
+ *
+ * output: string list; lista di stringhe (una per tupla)
+ *
+ * assumo che il risultato della query sia
+ * costituito da un solo valore per tupla
+ *
+ * TODO
+ * verificare che l sia effettivamente costruita come richiesto
+ *)
+let pgresult_to_string_list l = List.map (List.hd) l#get_list;;
+
+(*
+ * converte il risultato di una query in una stringa
+ *
+ * paramteri:
+ * l: Postgres.result; risultato della query
+ *
+ * output: string; valore dell'unica tupla del risultato
+ *
+ * mi aspetto che il risultato contenga una sola tupla
+ * formata da un solo valore
+ *
+ * TODO
+ * verificare che l sia costruita come richiesto
+ *)
+let pgresult_to_string l =
+ match l#get_list with
+ [] -> ""
+ | t -> List.hd (List.hd t)
+;;
+
+(*
+ * parametri:
+ * x: 'a; chiave di cui settare il valore
+ * v: 'b; valore da assegnare alla chiave
+ * l: ('a * 'b) list; lista di coppie in cui effettuare
+ * l'assegnamento
+ *
+ * output: ('a * 'b) list; lista di coppie contenente (x, v)
+ *
+ * TODO
+ * gestire i casi in cui in l compaiono piu' coppie (x, _)
+ * si sostituiscono tutte? se ne sostituisce una e si eliminano
+ * le altre?
+ *)
+let set_assoc x v l =
+ let rec spila testa key value lista =
+ match lista with
+ [] -> testa @ [(key, value)]
+ | (j, _)::tl when j = key -> testa @ [(key, value)] @ tl
+ | hd::tl -> spila (testa @ [hd]) key value tl
+ in
+ spila [] x v l
+;;
+
+(*
+ * parametri:
+ * p: string; nome della proprieta'
+ *
+ * output: string; id interno associato alla proprieta'
+ *)
+let helm_property_id p =
+ let c = pgc () in
+ let q1 = "select att0 from namespace where att1='http://www.cs.unibo.it/helm/schemas/mattone.rdf#'" in
+ let ns = pgresult_to_string (c#exec q1) in
+ let q2 = ("select att0 from property where att2='" ^ p ^ "' and att1=" ^ ns) in
+ let retval = pgresult_to_string (c#exec q2) in
+ (*let _ = print_endline ("utility:q2: " ^ q2 ^ " : " ^ retval) in*)
+ retval
+;;
+
+(*
+ * parametri:
+ * c: string; nome della classe
+ *
+ * output: string; id interno associato alla classe
+ *)
+let helm_class_id cl =
+ let c = pgc () in
+ let ns = pgresult_to_string (c#exec ("select att0 from namespace where att1='http://www.cs.unibo.it/helm/schemas/mattone.rdf#'")) in
+ pgresult_to_string (c#exec ("select att0 from class where att2='" ^ cl ^ "' and att1=" ^ ns))
+;;
+
diff --git a/helm/ocaml/mathql_interpreter_galax/utility.mli b/helm/ocaml/mathql_interpreter_galax/utility.mli
new file mode 100644
index 000000000..9e9e8290d
--- /dev/null
+++ b/helm/ocaml/mathql_interpreter_galax/utility.mli
@@ -0,0 +1,30 @@
+(* 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/.
+ *)
+
+val pgresult_to_string_list : < get_list : string list list; .. > -> string list
+val pgresult_to_string : < get_list : string list list; .. > -> string
+val set_assoc : 'a -> 'b -> ('a * 'b) list -> ('a * 'b) list
+val helm_property_id: string -> string
+val helm_class_id: string -> string
--
2.39.2