1 (* Copyright (C) 2000, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
27 * implementazione del'interprete MathQL
53 "/" ^ (string_of_int j)
59 * inizializzazione della connessione al database
61 let init () = Dbconn.init ();;
64 * esecuzione di una query
69 * output: string list list; risultato internto formato da uri + contesto.
71 let rec execute_ex q =
73 MQSelect (apvar, alist, abool) ->
74 select_ex apvar (execute_ex alist) abool
75 | MQUsedBy (alist, asvar) ->
76 use_ex (execute_ex alist) asvar "F" (*"refObj"*)
77 | MQUse (alist, asvar) ->
78 use_ex (execute_ex alist) asvar "B" (*"backPointer"*)
79 | MQPattern (apreamble, apattern, afragid) ->
80 pattern_ex apreamble apattern afragid
82 union_ex (execute_ex l1) (execute_ex l2)
84 diff_ex (execute_ex l1) (execute_ex l2)
85 | MQSortedBy (l, o, f) ->
86 sortedby_ex (execute_ex l) o f
87 | MQIntersect (l1, l2) ->
88 intersect_ex (execute_ex l1) (execute_ex l2)
92 * converte il risultato interno di una query (uri + contesto)
93 * in un risultato di sole uri
96 * l: string list list;
101 * il tipo del risultato mantenuto internamente e' diverso dal tipo di risultato
102 * restituito in output poiche', mentre chi effettua le query vuole come risultato
103 * solo le eventuali uri che soddisfano le query stesse, internamente ad una uri
104 * sono associati anche i valori delle variabili che ancora non sono state valutate
105 * perche', ad esempio, si trovano in altri rami dell'albero.
108 * SELECT x IN USE PATTERN "cic:/**.con" POSITION $a WHERE $a IS MainConclusion
109 * L'albero corrispondente a questa query e':
115 * PATTERN $a $a MainConclusion
117 * Nel momento in cui si esegue il ramo USE non sono noti i vincoli sullla variabile $a
118 * percui e' necessario considerare, oltre alle uri, i valori della variabile per i quali
119 * la uri puo' far parte del risultato.
122 let tmp = List.map List.hd (List.tl l) in
126 match Str.split (Str.regexp ":\|#\|/") l with
128 match List.rev tl with
129 ")"::n::"xpointer(1"::tail ->
136 | _ -> (MQString t) :: MQSlash :: par
140 (Some (int_of_string n), None)
142 | ")"::n::m::"xpointer(1"::tail ->
149 | _ -> (MQString t) :: MQSlash :: par
153 (Some (int_of_string m), Some (int_of_string n))
162 | _ -> (MQString t) :: MQSlash :: par
181 MQList qq -> xres_to_res (execute_ex qq)
185 * chiusura della connessione al database
187 let close () = Dbconn.close ();;