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
31 (* FG: ROBA VECCHIA DA BUTTARE (tranne apertura e chiusura database *)
45 open Mathql_semantics;;
49 let prop_pool = ref None;;
63 "/" ^ (string_of_int j)
68 let see_prop_pool () =
69 let _ = print_endline "eccomi" in
71 (fun elem -> print_endline (fst elem ^ ": " ^ snd elem))
72 (match !prop_pool with Some l -> l | _ -> print_endline "ciao"; assert false)
76 * inizializzazione della connessione al database
79 let _ = Dbconn.init () in
82 c#exec "select name,id from property where ns_id in (select id from namespace where url='http://www.cs.unibo.it/helm/schemas/mattone.rdf#')"
89 | _ -> print_endline "no"; assert false
95 let get_prop_id prop =
96 if prop="refObj" then "F"
97 else if prop="backPointer" then "B"
98 else List.assoc prop (match !prop_pool with Some l -> l | _ -> assert false)
101 (* execute_ex env q *)
102 (* [env] is the attributed uri environment in which the query [q] *)
103 (* must be evaluated *)
104 (* [q] is the query to evaluate *)
105 (* It returns a [Mathql_semantics.result] *)
106 let rec execute_ex env =
108 MQSelect (apvar, alist, abool) ->
109 select_ex env apvar (execute_ex env alist) abool
110 | MQUsedBy (alist, asvar) ->
111 use_ex (execute_ex env alist) asvar (get_prop_id "refObj") (* "F" (*"refObj"*) *)
112 | MQUse (alist, asvar) ->
113 use_ex (execute_ex env alist) asvar (get_prop_id "backPointer") (* "B" (*"backPointer"*) *)
114 | MQPattern (apreamble, apattern, afragid) ->
115 pattern_ex (apreamble, apattern, afragid)
116 | MQUnion (l1, l2) ->
117 union_ex (execute_ex env l1) (execute_ex env l2)
119 diff_ex (execute_ex env l1) (execute_ex env l2)
120 | MQSortedBy (l, o, f) ->
121 sortedby_ex (execute_ex env l) o f
122 | MQIntersect (l1, l2) ->
123 intersect_ex (execute_ex env l1) (execute_ex env l2)
124 | MQListRVar rvar -> [List.assoc rvar env]
125 | MQLetIn (lvar, l1, l2) ->
126 let t = Unix.time () in
128 (*CSC: The interesting code *)
129 let _ = letin_ex lvar (execute_ex env l1) in
131 (*CSC: end of the interesting code *)
134 print_string ("LETIN = " ^ string_of_int (List.length res) ^ ": ") ;
135 print_endline (string_of_float (Unix.time () -. t) ^ "s") ;
141 let rec build_result = function
144 {uri = s ; attributes = [] ; extra = ""} :: build_result tail
145 in build_result (List.sort compare l)
148 (* Let's initialize the execute in Select, creating a cyclical recursion *)
149 Select.execute := execute_ex;;
152 * converte il risultato interno di una query (uri + contesto)
153 * in un risultato di sole uri
156 * l: string list list;
161 * il tipo del risultato mantenuto internamente e' diverso dal tipo di risultato
162 * restituito in output poiche', mentre chi effettua le query vuole come risultato
163 * solo le eventuali uri che soddisfano le query stesse, internamente ad una uri
164 * sono associati anche i valori delle variabili che ancora non sono state valutate
165 * perche', ad esempio, si trovano in altri rami dell'albero.
168 * SELECT x IN USE PATTERN "cic:/**.con" POSITION $a WHERE $a IS MainConclusion
169 * L'albero corrispondente a questa query e':
175 * PATTERN $a $a MainConclusion
177 * Nel momento in cui si esegue il ramo USE non sono noti i vincoli sullla variabile $a
178 * percui e' necessario considerare, oltre alle uri, i valori della variabile per i quali
179 * la uri puo' far parte del risultato.
182 MQRefs (List.map (function {Mathql_semantics.uri = uri} -> uri) l)
184 let tmp = List.map (function {Mathql_semantics.uri = uri} -> uri) l in
188 (*let _ = print_endline ("DEBUG: (mqint.ml: xres_to_res)" ^ l) in*)
189 match Str.split (Str.regexp ":\|#\|/\|(\|)") l with
191 match List.rev tl with
192 n::"1"::"xpointer"::tail ->
199 | _ -> (MQBC t) :: MQBD :: par
203 [MQFC (int_of_string n)]
205 | n::m::"1"::"xpointer"::tail ->
212 | _ -> (MQBC t) :: MQBD :: par
216 [MQFC (int_of_string m); MQFC (int_of_string n)]
225 | _ -> (MQBC t) :: MQBD :: par
245 MQList qq -> xres_to_res (execute_ex [] qq)
249 * chiusura della connessione al database
251 let close () = Dbconn.close ();;
253 *****************************************************************************)
255 let init () = () (* FG: implementare l'apertura del database *)
257 let close () = () (* FG: implementare la chiusura del database *)
260 (* contexts *****************************************************************)
262 type svar_context = (MathQL.svar * MathQL.resource_set) list
264 type rvar_context = (MathQL.rvar * MathQL.resource) list
266 type group_context = (MathQL.rvar * MathQL.attribute_group) list
269 let svars = ref [] (* contesto delle svar *)
271 let rvars = ref [] (* contesto delle rvar *)
273 let groups = ref [] (* contesto dei gruppi *)
276 (* valuta una MathQL.set_exp e ritorna un MathQL.resource_set *)
278 let rec exec_set_exp = function
282 (* valuta una MathQL.boole_exp e ritorna un boole *)
284 and exec_boole_exp = function
285 | MathQL.False -> false
286 | MathQL.True -> true
287 | MathQL.Not x -> not (exec_boole_exp x)
288 | MathQL.And (x, y) -> (exec_boole_exp x) && (exec_boole_exp y)
289 | MathQL.Or (x, y) -> (exec_boole_exp x) || (exec_boole_exp y)
292 (* valuta una MathQL.val_exp e ritorna un MathQL.value *)
294 and exec_val_exp = function
295 | MathQL.Const l -> []
298 (* valuta una MathQL.set_exp nel contesto vuoto e ritorna un MathQL.resource_set *)
301 svars := []; rvars := []; groups := [];