From 8abd42ec1af0d5daef1d026ec550b49b07de8340 Mon Sep 17 00:00:00 2001 From: lordi Date: Wed, 22 May 2002 17:45:31 +0000 Subject: [PATCH] sortedby implemented and new uri result format --- helm/ocaml/mathql_interpreter/.depend | 22 ++-- helm/ocaml/mathql_interpreter/Makefile | 6 +- helm/ocaml/mathql_interpreter/dbconn.ml | 31 +++++- helm/ocaml/mathql_interpreter/dbconn.mli | 25 +++++ helm/ocaml/mathql_interpreter/diff.ml | 117 ++++++++++++++++++++ helm/ocaml/mathql_interpreter/diff.mli | 26 +++++ helm/ocaml/mathql_interpreter/eval.ml | 56 +++++++++- helm/ocaml/mathql_interpreter/eval.mli | 27 ++++- helm/ocaml/mathql_interpreter/func.ml | 73 +++++++++++- helm/ocaml/mathql_interpreter/func.mli | 27 ++++- helm/ocaml/mathql_interpreter/intersect.ml | 36 ++++-- helm/ocaml/mathql_interpreter/intersect.mli | 25 +++++ helm/ocaml/mathql_interpreter/mathql.ml | 84 +++++++++----- helm/ocaml/mathql_interpreter/mqint.ml | 110 ++++++++++++++++-- helm/ocaml/mathql_interpreter/mqint.mli | 24 ++++ helm/ocaml/mathql_interpreter/pattern.ml | 43 +++++-- helm/ocaml/mathql_interpreter/pattern.mli | 27 ++++- helm/ocaml/mathql_interpreter/select.ml | 75 +++++++++++-- helm/ocaml/mathql_interpreter/select.mli | 25 +++++ helm/ocaml/mathql_interpreter/sortedby.ml | 54 +++++++++ helm/ocaml/mathql_interpreter/sortedby.mli | 27 +++++ helm/ocaml/mathql_interpreter/union.ml | 40 ++++--- helm/ocaml/mathql_interpreter/union.mli | 25 +++++ helm/ocaml/mathql_interpreter/use.ml | 81 ++++++-------- helm/ocaml/mathql_interpreter/use.mli | 25 +++++ helm/ocaml/mathql_interpreter/utility.ml | 63 +++++++++-- helm/ocaml/mathql_interpreter/utility.mli | 31 +++++- 27 files changed, 1041 insertions(+), 164 deletions(-) create mode 100644 helm/ocaml/mathql_interpreter/diff.ml create mode 100644 helm/ocaml/mathql_interpreter/diff.mli create mode 100644 helm/ocaml/mathql_interpreter/sortedby.ml create mode 100644 helm/ocaml/mathql_interpreter/sortedby.mli diff --git a/helm/ocaml/mathql_interpreter/.depend b/helm/ocaml/mathql_interpreter/.depend index f88082979..b2ce01bf6 100644 --- a/helm/ocaml/mathql_interpreter/.depend +++ b/helm/ocaml/mathql_interpreter/.depend @@ -1,4 +1,6 @@ eval.cmi: mathql.cmo +func.cmi: mathql.cmo +sortedby.cmi: mathql.cmo select.cmi: mathql.cmo pattern.cmi: mathql.cmo mqint.cmi: mathql.cmo @@ -6,10 +8,14 @@ dbconn.cmo: mathql.cmo dbconn.cmi dbconn.cmx: mathql.cmx dbconn.cmi eval.cmo: mathql.cmo eval.cmi eval.cmx: mathql.cmx eval.cmi -utility.cmo: utility.cmi -utility.cmx: utility.cmi -func.cmo: func.cmi -func.cmx: func.cmi +utility.cmo: dbconn.cmi utility.cmi +utility.cmx: dbconn.cmx utility.cmi +func.cmo: dbconn.cmi mathql.cmo utility.cmi func.cmi +func.cmx: dbconn.cmx mathql.cmx utility.cmx func.cmi +diff.cmo: diff.cmi +diff.cmx: diff.cmi +sortedby.cmo: func.cmi mathql.cmo utility.cmi sortedby.cmi +sortedby.cmx: func.cmx mathql.cmx utility.cmx sortedby.cmi select.cmo: func.cmi mathql.cmo utility.cmi select.cmi select.cmx: func.cmx mathql.cmx utility.cmx select.cmi intersect.cmo: intersect.cmi @@ -20,7 +26,7 @@ pattern.cmo: dbconn.cmi eval.cmi utility.cmi pattern.cmi pattern.cmx: dbconn.cmx eval.cmx utility.cmx pattern.cmi use.cmo: dbconn.cmi utility.cmi use.cmi use.cmx: dbconn.cmx utility.cmx use.cmi -mqint.cmo: dbconn.cmi eval.cmi intersect.cmi mathql.cmo pattern.cmi \ - select.cmi union.cmi use.cmi utility.cmi mqint.cmi -mqint.cmx: dbconn.cmx eval.cmx intersect.cmx mathql.cmx pattern.cmx \ - select.cmx union.cmx use.cmx utility.cmx mqint.cmi +mqint.cmo: dbconn.cmi diff.cmi eval.cmi intersect.cmi mathql.cmo pattern.cmi \ + select.cmi sortedby.cmi union.cmi use.cmi utility.cmi mqint.cmi +mqint.cmx: dbconn.cmx diff.cmx eval.cmx intersect.cmx mathql.cmx pattern.cmx \ + select.cmx sortedby.cmx union.cmx use.cmx utility.cmx mqint.cmi diff --git a/helm/ocaml/mathql_interpreter/Makefile b/helm/ocaml/mathql_interpreter/Makefile index 27ae1fb1d..20335f6ce 100644 --- a/helm/ocaml/mathql_interpreter/Makefile +++ b/helm/ocaml/mathql_interpreter/Makefile @@ -2,9 +2,9 @@ PACKAGE = mathql_interpreter REQUIRES = helm-urimanager pgocaml PREDICATES = -INTERFACE_FILES = dbconn.mli eval.mli utility.mli func.mli \ - select.mli intersect.mli union.mli pattern.mli use.mli \ - mqint.mli +INTERFACE_FILES = dbconn.mli eval.mli utility.mli func.mli diff.mli \ + sortedby.mli select.mli intersect.mli union.mli \ + pattern.mli use.mli mqint.mli IMPLEMENTATION_FILES = mathql.ml $(INTERFACE_FILES:%.mli=%.ml) diff --git a/helm/ocaml/mathql_interpreter/dbconn.ml b/helm/ocaml/mathql_interpreter/dbconn.ml index 5f1d25672..fd207ba03 100644 --- a/helm/ocaml/mathql_interpreter/dbconn.ml +++ b/helm/ocaml/mathql_interpreter/dbconn.ml @@ -1,18 +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/. + *) (* * gestione della connessione al database *) (* - * le eccezzioni lanciate dalle funzioni init e pgc sono + * le eccezioni lanciate dalle funzioni init e pgc sono * definite nel modulo Mathql *) open Mathql;; (* * paramentri della connessione + * + * TODO: bisogna scegliere se questi parametri vengono + * passati come argomento *) -(*let connection_param = "host=127.0.0.1 dbname=helm";;*) +(*let connection_param = "dbname=helm";;*) let connection_param = "host=dotto.cs.unibo.it dbname=helm user=helm";; (* diff --git a/helm/ocaml/mathql_interpreter/dbconn.mli b/helm/ocaml/mathql_interpreter/dbconn.mli index c382000c6..c162cf00e 100644 --- a/helm/ocaml/mathql_interpreter/dbconn.mli +++ b/helm/ocaml/mathql_interpreter/dbconn.mli @@ -1,3 +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 pgc : unit -> Postgres.connection val init : unit -> unit val close : unit -> unit diff --git a/helm/ocaml/mathql_interpreter/diff.ml b/helm/ocaml/mathql_interpreter/diff.ml new file mode 100644 index 000000000..41e41c73b --- /dev/null +++ b/helm/ocaml/mathql_interpreter/diff.ml @@ -0,0 +1,117 @@ +(* 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 + *) + +(* + * + *) +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 DIFF + *) +let diff_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 ...*) + (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 + tail2 +(* first @ + List.map (fun l -> [List.hd l] @ + xres_fill_context + (List.tl headr) (List.tl head2) (List.tl l) + ) tail2 +*) + ) (* match *) +;; + +(** TEST **) + +(* +let h1 = ["retVal"; "a"; "b"];; +let l1 = ["pippo"; "3"; "3"];; +let l3 = ["pluto"; "7"; "8"] +let r1 = [h1; l1; l3];; + +(*let h2 = ["retVal"; "b"; "c"];; +let l2 = ["pippo"; "3"; "1"];;*) +let h2 = ["retVal"; "a"; "b"];; +let l2 = ["pippo"; "3"; "3"];; +let r2 = [h2; l2];; + +List.map (fun l -> List.iter print_endline l) (xres_union (r1, r2));; +*) diff --git a/helm/ocaml/mathql_interpreter/diff.mli b/helm/ocaml/mathql_interpreter/diff.mli new file mode 100644 index 000000000..d3a57f708 --- /dev/null +++ b/helm/ocaml/mathql_interpreter/diff.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 diff_ex : string list list -> string list list -> string list list diff --git a/helm/ocaml/mathql_interpreter/eval.ml b/helm/ocaml/mathql_interpreter/eval.ml index 9a5d90dee..c36b92fd2 100644 --- a/helm/ocaml/mathql_interpreter/eval.ml +++ b/helm/ocaml/mathql_interpreter/eval.ml @@ -1,3 +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/. + *) (* * @@ -13,7 +37,7 @@ let rec patterneval p = [] -> "" | head::tail -> let h = match head with - MQString (s) -> s + MQString (s) -> Str.global_replace (Str.regexp "\.") "\\\\\." s | MQSlash -> "/" | MQAnyChr -> "[^/]?" | MQAst -> "[^/]*" @@ -29,12 +53,31 @@ let fieval fi = match fst fi with None -> "" | Some i -> - let s = "#xpointer\(1/" ^ string_of_int (i) in + let s = "#xpointer\\\\(1/" ^ string_of_int (i) in match snd fi with None -> - s ^ "\)" + s ^ "\\\\)" | Some j -> - s ^ "/" ^ string_of_int j ^ "\)" + s ^ "/" ^ string_of_int j ^ "\\\\)" +;; + +(* + * 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 = + p ;; (* @@ -44,6 +87,7 @@ let fieval fi = * SQL standard LIKE perche' MathQL prevede esperssioni con "*" * e con "**". *) -let pattern_match preamble pattern ext fragid = - " ~ '" ^ preamble ^ ":/" ^ (patterneval pattern) ^ "." ^ ext ^ (fieval fragid) ^ "'" +let pattern_match preamble pattern fragid = + " ~ '" ^ (preeval preamble) ^ ":/" ^ (patterneval pattern) ^ (fieval fragid) ^ "'" ;; + diff --git a/helm/ocaml/mathql_interpreter/eval.mli b/helm/ocaml/mathql_interpreter/eval.mli index fae7a5bc9..1c634d977 100644 --- a/helm/ocaml/mathql_interpreter/eval.mli +++ b/helm/ocaml/mathql_interpreter/eval.mli @@ -1,3 +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_match : string -> - Mathql.mquptoken list -> string -> int option * int option -> string + Mathql.mquptoken list -> int option * int option -> string diff --git a/helm/ocaml/mathql_interpreter/func.ml b/helm/ocaml/mathql_interpreter/func.ml index ae01d206a..7f80da7f4 100644 --- a/helm/ocaml/mathql_interpreter/func.ml +++ b/helm/ocaml/mathql_interpreter/func.ml @@ -1,8 +1,36 @@ +(* 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 Dbconn;; +open Utility;; +open Mathql;; + (* * implementazione della funzione NAME *) @@ -16,8 +44,47 @@ let func_name value = Not_found -> "" ;; -(** TEST **) +(* + * + *) +let func_theory value = + "" +;; (* -print_endline (func_name Sys.argv.(1));; -*) + * implementazione delle funzioni dublin core + *) +let func_dc (value, name) = + let c = pgc () + and p = helm_property_id name in + pgresult_to_string (c#exec ("select t" ^ p ^ ".att1 from t" ^ p ^ " where " ^ "t" ^ p ^ ".att0 = '" ^ value ^ "'")) +;; + +(* + * + *) +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/func.mli b/helm/ocaml/mathql_interpreter/func.mli index 3e0377615..5e9d77ff3 100644 --- a/helm/ocaml/mathql_interpreter/func.mli +++ b/helm/ocaml/mathql_interpreter/func.mli @@ -1 +1,26 @@ -val func_name : string -> string +(* 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/intersect.ml b/helm/ocaml/mathql_interpreter/intersect.ml index 7a3f47f34..bd582a3b2 100644 --- a/helm/ocaml/mathql_interpreter/intersect.ml +++ b/helm/ocaml/mathql_interpreter/intersect.ml @@ -1,3 +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/. + *) (* * implementazione del comando INTERSECT @@ -81,15 +105,3 @@ let intersect_ex alist1 alist2 = ) (* match *) ;; -(* -let h1 = ["retVal"; "a"; "b"];; -let l1 = ["pippo"; "3"; "3"];; -let l3 = ["pluto"; "7";"8"] -let r1 = [h1; l1; l3];; - -let h2 = ["retVal"; "b"; "c"];; -let l2 = ["pippo"; "3"; "1"];; -let r2 = [h2; l2];; - -List.map (fun l -> List.iter print_endline l) (xres_intersect (r1, r2));; -*) diff --git a/helm/ocaml/mathql_interpreter/intersect.mli b/helm/ocaml/mathql_interpreter/intersect.mli index f764bea7f..aee42c09c 100644 --- a/helm/ocaml/mathql_interpreter/intersect.mli +++ b/helm/ocaml/mathql_interpreter/intersect.mli @@ -1 +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 intersect_ex : string list list -> string list list -> string list list diff --git a/helm/ocaml/mathql_interpreter/mathql.ml b/helm/ocaml/mathql_interpreter/mathql.ml index 2bdc5a1b7..01cbf431a 100644 --- a/helm/ocaml/mathql_interpreter/mathql.ml +++ b/helm/ocaml/mathql_interpreter/mathql.ml @@ -41,38 +41,57 @@ exception MQInvalidConnection of string (* Input types **************************************************************) (* main type is mquery *) -type mqrvar = string (* name *) +type mqrvar = string (* name *) -type mqsvar = string (* name *) +type mqsvar = string (* name *) type mquptoken = - | MQString of string (* a constant string *) - | MQSlash (* a slash: '/' *) - | MQAnyChr (* Any single character: '?' *) - | MQAst (* single asterisk: '*' *) - | MQAstAst (* double asterisk: '**' *) + | MQString of string (* a constant string *) + | MQSlash (* a slash: '/' *) + | MQAnyChr (* Any single character: '?' *) + | MQAst (* single asterisk: '*' *) + | MQAstAst (* double asterisk: '**' *) -type mqup = mquptoken list (* uri pattern (helper) *) +type mqup = mquptoken list (* uri pattern (helper) *) type mqfi = int option * int option -type mqtref = string * mqup * string * mqfi (* HELM preamble, - uri pattern, - extension, - fragment identifier *) +type mqtref = string * mqup * mqfi (* HELM preamble, + uri pattern, + fragment identifier *) -type mqpattern = mqtref (* constant pattern *) +type mqpattern = mqtref (* constant pattern *) type mqfunc = - | MQName (* NAME *) + | MQName (* NAME *) + | MQTheory + | MQTitle + | MQContributor + | MQCreator + | MQPublisher + | MQSubject + | MQDescription + | MQDate + | MQType + | MQFormat + | MQIdentifier + | MQLanguage + | MQRelation + | MQSource + | MQCoverage + | MQRights + | MQInstitution + | MQContact + | MQFirstVersion + | MQModified type mqstring = - | MQCons of string (* constant *) - | MQFunc of mqfunc * mqrvar (* function, rvar *) - | MQRVar of mqrvar (* rvar *) - | MQSVar of mqsvar (* svar *) - | MQMConclusion (* main conclusion *) - | MQConclusion (* inner conclusion *) + | MQCons of string (* constant *) + | MQFunc of mqfunc * mqrvar (* function, rvar *) + | MQRVar of mqrvar (* rvar *) + | MQSVar of mqsvar (* svar *) + | MQMConclusion (* main conclusion *) + | MQConclusion (* inner conclusion *) type mqbool = | MQTrue @@ -80,15 +99,21 @@ type mqbool = | MQAnd of mqbool * mqbool | MQOr of mqbool * mqbool | MQNot of mqbool - | MQIs of mqstring * mqstring (* operands *) + | MQIs of mqstring * mqstring (* operands *) + +type mqorder = + | MQAsc + | MQDesc type mqlist = - | MQSelect of mqrvar * mqlist * mqbool (* rvar, list, boolean *) - | MQUse of mqlist * mqsvar (* list, Position attribute *) - | MQUsedBy of mqlist * mqsvar (* list, Position attribute *) - | MQPattern of mqpattern (* pattern *) - | MQUnion of mqlist * mqlist (* *) - | MQIntersect of mqlist * mqlist (* *) + | MQSelect of mqrvar * mqlist * mqbool (* rvar, list, boolean *) + | MQUse of mqlist * mqsvar (* list, Position attribute *) + | MQUsedBy of mqlist * mqsvar (* list, Position attribute *) + | MQPattern of mqpattern (* pattern *) + | MQUnion of mqlist * mqlist (* *) + | MQDiff of mqlist * mqlist (* *) + | MQIntersect of mqlist * mqlist (* *) + | MQSortedBy of mqlist * mqorder * mqfunc (* *) type mquery = | MQList of mqlist @@ -96,10 +121,9 @@ type mquery = (* Output types *************************************************************) (* main type is mqresult *) -(* TODO: usare le uri in questo formato *) -type mquref = UriManager.uri * mqfi (* uri, fragment identifier *) +type mquref = UriManager.uri * mqfi (* uri, fragment identifier *) -type mqrefs = string list (* list of references (helper) *) +type mqrefs = mqtref list (* list of references (helper) *) type mqresult = | MQRefs of mqrefs diff --git a/helm/ocaml/mathql_interpreter/mqint.ml b/helm/ocaml/mathql_interpreter/mqint.ml index 240881771..56fa38ad9 100644 --- a/helm/ocaml/mathql_interpreter/mqint.ml +++ b/helm/ocaml/mathql_interpreter/mqint.ml @@ -1,3 +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/. + *) (* * implementazione del'interprete MathQL @@ -9,9 +33,28 @@ open Dbconn;; open Pattern;; open Union;; open Intersect;; +open Diff;; +open Sortedby;; open Use;; open Select;; +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) + ) ^ + ")" +;; + (* * inizializzazione della connessione al database *) @@ -33,10 +76,15 @@ let rec execute_ex q = use_ex (execute_ex alist) asvar "refObj" | MQUse (alist, asvar) -> use_ex (execute_ex alist) asvar "backPointer" - | MQPattern (apreamble, apattern, ext, afragid) -> - pattern_ex apreamble apattern ext afragid + | MQPattern (apreamble, apattern, afragid) -> + let _ = print_endline ("*********" ^ (fi_to_string afragid)); flush stdout in + pattern_ex apreamble apattern afragid | MQUnion (l1, l2) -> union_ex (execute_ex l1) (execute_ex l2) + | MQDiff (l1, l2) -> + diff_ex (execute_ex l1) (execute_ex l2) + | MQSortedBy (l, o, f) -> + sortedby_ex (execute_ex l) o f | MQIntersect (l1, l2) -> intersect_ex (execute_ex l1) (execute_ex l2) ;; @@ -72,14 +120,60 @@ let rec execute_ex q = * la uri puo' far parte del risultato. *) let xres_to_res l = - MQRefs - ( - List.map - List.hd - (List.tl l) - ) + let tmp = List.map List.hd (List.tl l) in + MQRefs + (List.map + (function l -> + match Str.split (Str.regexp ":\|#\|/") l with + hd::tl -> ( + match List.rev tl with + ")"::n::"xpointer(1"::tail -> + ( + hd, + List.fold_left + (fun par t -> + match par with + [] -> [MQString t] + | _ -> (MQString t) :: MQSlash :: par + ) + [] + tail, + (Some (int_of_string n), None) + ) + | ")"::n::m::"xpointer(1"::tail -> + ( + hd, + List.fold_left + (fun par t -> + match par with + [] -> [MQString t] + | _ -> (MQString t) :: MQSlash :: par + ) + [] + tail, + (Some (int_of_string m), Some (int_of_string n)) + ) + | tail -> + ( + hd, + List.fold_left + (fun par t -> + match par with + [] -> [MQString t] + | _ -> (MQString t) :: MQSlash :: par + ) + [] + tail, + (None, None) + ) + ) + | [] -> assert false + ) + tmp + ) ;; + (* * *) diff --git a/helm/ocaml/mathql_interpreter/mqint.mli b/helm/ocaml/mathql_interpreter/mqint.mli index 964bacf98..55836d940 100644 --- a/helm/ocaml/mathql_interpreter/mqint.mli +++ b/helm/ocaml/mathql_interpreter/mqint.mli @@ -1,3 +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/. + *) (* * interfaccia dell'interprete MathQL diff --git a/helm/ocaml/mathql_interpreter/pattern.ml b/helm/ocaml/mathql_interpreter/pattern.ml index 2445e1c76..c9dde8b6a 100644 --- a/helm/ocaml/mathql_interpreter/pattern.ml +++ b/helm/ocaml/mathql_interpreter/pattern.ml @@ -1,14 +1,43 @@ +(* 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 PATTERN + *) open Dbconn;; open Utility;; open Eval;; -let pattern_ex apreamble apattern ext afragid = +let pattern_ex apreamble apattern afragid = let c = pgc () in - let r1 = c#exec "select att0 from class where att2='Object'" in - let res = - c#exec ("select att0 from t" ^ (pgresult_to_string r1) ^ - " where att0 " ^ (pattern_match apreamble apattern ext afragid)) - in - [["retVal"]] @ List.map (fun l -> [l]) (pgresult_to_string_list res) + let r1 = helm_class_id "MathResource" in + let qq = "select att0 from t" ^ r1 ^ " where att0 " ^ (pattern_match apreamble apattern afragid) in + (*let _ = print_endline qq in*) + let res = + c#exec (qq) + in + [["retVal"]] @ List.map (fun l -> [l]) (pgresult_to_string_list res) ;; diff --git a/helm/ocaml/mathql_interpreter/pattern.mli b/helm/ocaml/mathql_interpreter/pattern.mli index f79ec92ff..051ffe9f2 100644 --- a/helm/ocaml/mathql_interpreter/pattern.mli +++ b/helm/ocaml/mathql_interpreter/pattern.mli @@ -1,4 +1,29 @@ +(* 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 : string -> Mathql.mquptoken list -> - string -> int option * int option -> string list list + int option * int option -> string list list diff --git a/helm/ocaml/mathql_interpreter/select.ml b/helm/ocaml/mathql_interpreter/select.ml index 6f60a3e31..191ffde34 100644 --- a/helm/ocaml/mathql_interpreter/select.ml +++ b/helm/ocaml/mathql_interpreter/select.ml @@ -1,3 +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/. + *) (* * implementazione del comando SELECT @@ -15,10 +39,7 @@ let stringeval s l = MQCons s -> s | MQFunc (f, rvar) -> - ( - match f with - MQName -> func_name (List.assoc rvar l) - ) + apply_func f (List.assoc rvar l) | MQRVar rvar -> List.assoc rvar l | MQSVar svar -> @@ -74,7 +95,7 @@ let rec replace avar newval l = | _ -> l (* i casi non compresi sono MQTrue e MQFalse *) ;; -let rec print_booltree b = +(*let rec print_booltree b = match b with MQAnd (b1, b2) -> let i = print_booltree b1 in @@ -98,7 +119,27 @@ let rec print_booltree b = | MQFunc (f, rvar) -> ( match f with - MQName -> "NAME " ^ rvar + MQName -> "NAME " ^ rvar + | MQTheory -> "THEORY" ^ rvar + | MQTitle -> "TITLE" ^ rvar + | MQContributor -> "contributor" ^ rvar + | MQCreator -> "creator" ^ rvar + | MQPublisher -> "publisher" ^ rvar + | MQSubject -> "subject" ^ rvar + | MQDescription -> "description" ^ rvar + | MQDate -> "date" ^ rvar + | MQType -> "type" ^ rvar + | MQFormat -> "format" ^ rvar + | MQIdentifier -> "identifier" ^ rvar + | MQLanguage -> "language" ^ rvar + | MQRelation -> "relation" ^ rvar + | MQSource -> "source" ^ rvar + | MQCoverage -> "coverage" ^ rvar + | MQRights -> "rights" ^ rvar + | MQInstitution -> "institution" ^ rvar + | MQContact -> "contact" ^ rvar + | MQFirstVersion -> "firstversion" ^ rvar + | MQModified -> "modified" ^ rvar ) | MQRVar rvar -> rvar @@ -115,6 +156,26 @@ let rec print_booltree b = ( match f with MQName -> "NAME " ^ rvar + | MQTheory -> "THEORY" ^ rvar + | MQTitle -> "TITLE" ^ rvar + | MQContributor -> "contributor" ^ rvar + | MQCreator -> "creator" ^ rvar + | MQPublisher -> "publisher" ^ rvar + | MQSubject -> "subject" ^ rvar + | MQDescription -> "description" ^ rvar + | MQDate -> "date" ^ rvar + | MQType -> "type" ^ rvar + | MQFormat -> "format" ^ rvar + | MQIdentifier -> "identifier" ^ rvar + | MQLanguage -> "language" ^ rvar + | MQRelation -> "relation" ^ rvar + | MQSource -> "source" ^ rvar + | MQCoverage -> "coverage" ^ rvar + | MQRights -> "rights" ^ rvar + | MQInstitution -> "institution" ^ rvar + | MQContact -> "contact" ^ rvar + | MQFirstVersion -> "firstversion" ^ rvar + | MQModified -> "modified" ^ rvar ) | MQRVar rvar -> rvar @@ -127,7 +188,7 @@ let rec print_booltree b = in print_string (s1v ^ " = " ^ s2v) ;; - +*) (* * implementazione del comando SELECT *) diff --git a/helm/ocaml/mathql_interpreter/select.mli b/helm/ocaml/mathql_interpreter/select.mli index c3af84dd6..7d627b00b 100644 --- a/helm/ocaml/mathql_interpreter/select.mli +++ b/helm/ocaml/mathql_interpreter/select.mli @@ -1,3 +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 select_ex : Mathql.mqrvar -> Mathql.mqsvar list list -> Mathql.mqbool -> Mathql.mqsvar list list diff --git a/helm/ocaml/mathql_interpreter/sortedby.ml b/helm/ocaml/mathql_interpreter/sortedby.ml new file mode 100644 index 000000000..a62926684 --- /dev/null +++ b/helm/ocaml/mathql_interpreter/sortedby.ml @@ -0,0 +1,54 @@ +(* 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 SORTEDBY + *) + +open Mathql;; +open Func;; +open Utility;; + +(* + * implementazione del comando SORTEDBY + *) +let sortedby_ex alist order afunc = + [List.hd alist] + @ + List.map + (List.tl) + (Sort.list + (fun a b -> + match order with + MQAsc -> (List.hd a) < (List.hd b) + | MQDesc -> (List.hd a) > (List.hd b) + ) + (List.map + (fun l -> [apply_func afunc (List.hd l)] @ l) + (List.tl alist) + ) + ) +;; + diff --git a/helm/ocaml/mathql_interpreter/sortedby.mli b/helm/ocaml/mathql_interpreter/sortedby.mli new file mode 100644 index 000000000..ebed97055 --- /dev/null +++ b/helm/ocaml/mathql_interpreter/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 : + string list list -> Mathql.mqorder -> Mathql.mqfunc -> string list list diff --git a/helm/ocaml/mathql_interpreter/union.ml b/helm/ocaml/mathql_interpreter/union.ml index bf402a2f1..2a759535a 100644 --- a/helm/ocaml/mathql_interpreter/union.ml +++ b/helm/ocaml/mathql_interpreter/union.ml @@ -1,3 +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/. + *) (* * implementazione del comando UNION @@ -75,19 +99,3 @@ let union_ex alist1 alist2 = ) (* match *) ;; -(** TEST **) - -(* -let h1 = ["retVal"; "a"; "b"];; -let l1 = ["pippo"; "3"; "3"];; -let l3 = ["pluto"; "7"; "8"] -let r1 = [h1; l1; l3];; - -(*let h2 = ["retVal"; "b"; "c"];; -let l2 = ["pippo"; "3"; "1"];;*) -let h2 = ["retVal"; "a"; "b"];; -let l2 = ["pippo"; "3"; "3"];; -let r2 = [h2; l2];; - -List.map (fun l -> List.iter print_endline l) (xres_union (r1, r2));; -*) diff --git a/helm/ocaml/mathql_interpreter/union.mli b/helm/ocaml/mathql_interpreter/union.mli index 6444b33d2..967915d84 100644 --- a/helm/ocaml/mathql_interpreter/union.mli +++ b/helm/ocaml/mathql_interpreter/union.mli @@ -1 +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 union_ex : string list list -> string list list -> string list list diff --git a/helm/ocaml/mathql_interpreter/use.ml b/helm/ocaml/mathql_interpreter/use.ml index f1ac7c779..cb65699e9 100644 --- a/helm/ocaml/mathql_interpreter/use.ml +++ b/helm/ocaml/mathql_interpreter/use.ml @@ -1,3 +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/. + *) (* * implementazione dei comandi USE/USED BY @@ -19,30 +43,23 @@ open Dbconn;; * * output: string list list; lista su cui e' stato eseguito il * comando USE/USED BY - * - * TODO - * USE e USED BY sono identici dal punto di vista algoritmico, per questo - * sono stati accorpati in una sola funzione; stilisticamente, sarebbe meglio - * avere due implementazioni distinte... *) let use_ex alist asvar usek = let c = pgc () in List.fold_left (fun parziale xres -> - let r1 = pgresult_to_string (c#exec - ("select att0 from property where att2='" ^ usek ^ "'")) - and r2 = pgresult_to_string (c#exec - "select att0 from property where att2='position'") - and r3 = pgresult_to_string (c#exec - "select att0 from property where att2='occurrence'") + let r1 = helm_property_id usek + and r2 = helm_property_id "position" + and r3 = helm_property_id "occurrence" in - let res = c#exec ( - "select distinct t" ^ r3 ^ ".att1, t" ^ r2 ^ ".att1 " ^ + let qq = "select distinct t" ^ r3 ^ ".att1, t" ^ r2 ^ ".att1 " ^ "from t" ^ r3 ^ ", t" ^ r2 ^ ", t" ^ r1 ^ " " ^ "where " ^ "t" ^ r1 ^ ".att0 = '" ^ (List.hd xres) ^ "' and t" ^ r1 ^ ".att1 = t" ^ r2 ^ ".att0 and t" ^ r1 ^ ".att1 = t" ^ r3 ^ - ".att0") + ".att0" in + (*let _ = print_endline ("use: " ^ qq) in*) + let res = c#exec qq in parziale @ if not (List.mem asvar (List.tl (List.hd alist))) then @@ -95,39 +112,3 @@ let use_ex alist asvar usek = (List.tl alist) ;; -(** TEST **) - -(* -let use_ex alist asvar = - if (List.find_all asvar (List.tl (List.hd alist))) = [] then - use_ex_nc alist asvar - else - use_ex_co alist asvar -;; - -List.map - (fun l -> - let t = - match xres with - hd::tl -> (List.hd l)::tl - | [] -> [] - in - let hash = List.combine (List.hd alist) t in - snd (set_assoc asvar (snd l) hash) - ) - (List.find_all - (fun l -> - let currv = - List.hd (List.tl l) - and xresv = - try ( - List.assoc asvar (List.combine (List.tl (List.hd alist)) (List.tl xres)) - ) with - Not_found -> "" - in - xresv = "" or xresv = currv - ) - res#get_list - ) -;; -*) diff --git a/helm/ocaml/mathql_interpreter/use.mli b/helm/ocaml/mathql_interpreter/use.mli index 6bef1f475..708c134c9 100644 --- a/helm/ocaml/mathql_interpreter/use.mli +++ b/helm/ocaml/mathql_interpreter/use.mli @@ -1 +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 use_ex : string list list -> string -> string -> string list list diff --git a/helm/ocaml/mathql_interpreter/utility.ml b/helm/ocaml/mathql_interpreter/utility.ml index 38856a0e1..e3776cfbd 100644 --- a/helm/ocaml/mathql_interpreter/utility.ml +++ b/helm/ocaml/mathql_interpreter/utility.ml @@ -1,8 +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/. + *) (* * funzioni di utilita' generale *) +open Dbconn;; + (* * converte il risultato di una query in una lista di stringhe * @@ -33,7 +59,11 @@ let pgresult_to_string_list l = List.map (List.hd) l#get_list;; * TODO * verificare che l sia costruita come richiesto *) -let pgresult_to_string l = List.hd (List.hd l#get_list);; +let pgresult_to_string l = + match l#get_list with + [] -> "" + | t -> List.hd (List.hd t) +;; (* * parametri: @@ -59,12 +89,31 @@ let set_assoc x v l = spila [] x v l ;; -(** TEST **) +(* + * 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 +;; (* -let h = ["d";"b"];; -let v = ["1";"2"];; -let c = List.combine h v;; + * 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)) +;; -List.iter (fun (a,b) -> print_endline (a ^ ": " ^ b)) (set_assoc "a" "3" c);; -*) diff --git a/helm/ocaml/mathql_interpreter/utility.mli b/helm/ocaml/mathql_interpreter/utility.mli index 928ea33bf..763893247 100644 --- a/helm/ocaml/mathql_interpreter/utility.mli +++ b/helm/ocaml/mathql_interpreter/utility.mli @@ -1,3 +1,30 @@ -val pgresult_to_string_list : < get_list : 'a list list; .. > -> 'a list -val pgresult_to_string : < get_list : 'a list list; .. > -> 'a +(* 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 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