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
42 let prop_pool = ref None;;
56 "/" ^ (string_of_int j)
61 let see_prop_pool () =
62 let _ = print_endline "eccomi" in
64 (fun elem -> print_endline (fst elem ^ ": " ^ snd elem))
65 (match !prop_pool with Some l -> l | _ -> print_endline "ciao"; assert false)
69 * inizializzazione della connessione al database
72 let _ = Dbconn.init () in
75 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#')"
82 | _ -> print_endline "no"; assert false
88 let get_prop_id prop =
89 if prop="refObj" then "F"
90 else if prop="backPointer" then "B"
91 else List.assoc prop (match !prop_pool with Some l -> l | _ -> assert false)
94 (* execute_ex env q *)
95 (* [env] is the attributed uri environment in which the query [q] *)
96 (* must be evaluated *)
97 (* [q] is the query to evaluate *)
98 (* It returns a [Mathql_semantics.result] *)
99 let rec execute_ex env =
101 MQSelect (apvar, alist, abool) ->
102 select_ex env apvar (execute_ex env alist) abool
103 | MQUsedBy (alist, asvar) ->
104 use_ex (execute_ex env alist) asvar (get_prop_id "refObj") (* "F" (*"refObj"*) *)
105 | MQUse (alist, asvar) ->
106 use_ex (execute_ex env alist) asvar (get_prop_id "backPointer") (* "B" (*"backPointer"*) *)
107 | MQPattern (apreamble, apattern, afragid) ->
108 pattern_ex (apreamble, apattern, afragid)
109 | MQUnion (l1, l2) ->
110 union_ex (execute_ex env l1) (execute_ex env l2)
112 diff_ex (execute_ex env l1) (execute_ex env l2)
113 | MQSortedBy (l, o, f) ->
114 sortedby_ex (execute_ex env l) o f
115 | MQIntersect (l1, l2) ->
116 intersect_ex (execute_ex env l1) (execute_ex env l2)
117 | MQListRVar rvar -> [List.assoc rvar env]
118 | MQLetIn (lvar, l1, l2) ->
119 let t = Unix.time () in
121 (*CSC: The interesting code *)
122 let _ = letin_ex lvar (execute_ex env l1) in
124 (*CSC: end of the interesting code *)
127 print_string ("LETIN = " ^ string_of_int (List.length res) ^ ": ") ;
128 print_endline (string_of_float (Unix.time () -. t) ^ "s") ;
135 (* Let's initialize the execute in Select, creating a cyclical recursion *)
136 Select.execute := execute_ex;;
139 * converte il risultato interno di una query (uri + contesto)
140 * in un risultato di sole uri
143 * l: string list list;
148 * il tipo del risultato mantenuto internamente e' diverso dal tipo di risultato
149 * restituito in output poiche', mentre chi effettua le query vuole come risultato
150 * solo le eventuali uri che soddisfano le query stesse, internamente ad una uri
151 * sono associati anche i valori delle variabili che ancora non sono state valutate
152 * perche', ad esempio, si trovano in altri rami dell'albero.
155 * SELECT x IN USE PATTERN "cic:/**.con" POSITION $a WHERE $a IS MainConclusion
156 * L'albero corrispondente a questa query e':
162 * PATTERN $a $a MainConclusion
164 * Nel momento in cui si esegue il ramo USE non sono noti i vincoli sullla variabile $a
165 * percui e' necessario considerare, oltre alle uri, i valori della variabile per i quali
166 * la uri puo' far parte del risultato.
169 MQRefs (List.map (function {Mathql_semantics.uri = uri} -> uri) l)
171 let tmp = List.map (function {Mathql_semantics.uri = uri} -> uri) l in
175 (*let _ = print_endline ("DEBUG: (mqint.ml: xres_to_res)" ^ l) in*)
176 match Str.split (Str.regexp ":\|#\|/\|(\|)") l with
178 match List.rev tl with
179 n::"1"::"xpointer"::tail ->
186 | _ -> (MQBC t) :: MQBD :: par
190 [MQFC (int_of_string n)]
192 | n::m::"1"::"xpointer"::tail ->
199 | _ -> (MQBC t) :: MQBD :: par
203 [MQFC (int_of_string m); MQFC (int_of_string n)]
212 | _ -> (MQBC t) :: MQBD :: par
232 MQList qq -> xres_to_res (execute_ex [] qq)
236 * chiusura della connessione al database
238 let close () = Dbconn.close ();;