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/.
26 (******************************************************************************)
30 (* Claudio Sacerdoti Coen <sacerdot@cs.unibo.it> *)
33 (* Missing description *)
35 (******************************************************************************)
38 let counter = ref 0 in
39 List.iter (function e -> incr counter ; foo e !counter)
42 let pathname_of_uri uristring =
44 Str.replace_first (Str.regexp "^cic:") "" uristring
47 let make_dirs dirpath =
48 ignore (Unix.system ("mkdir -p \"" ^ dirpath ^ "\""))
61 let soften_classification =
63 Backbone -> InConclusion
64 | Branch -> InHypothesis
65 | InBody -> assert false
69 let hash = Hashtbl.create 117 ;;
71 let add_uri uri kind =
79 match kind,old_kinds with
81 | InBody,_ -> old_kinds
82 | k,_ when List.mem k old_kinds -> old_kinds
85 Hashtbl.replace hash uri new_kinds
88 (* It also removes every element in the hash *)
89 let uris_fold foo init =
90 let xml_element_name_of_kind =
92 Backbone -> "MainConclusion"
93 | Branch -> "MainHypothesis"
94 | InConclusion -> "InConclusion"
95 | InHypothesis -> "InHypothesis"
103 foo j uri (xml_element_name_of_kind kind)
113 let output_content () =
116 [< Xml.xml_nempty "h:refObj" []
117 (Xml.xml_empty "h:Occurrence"
118 ["rdf:about","http://www.cs.unibo.it/helm/schemas/schema-h.rdf#" ^ kind ;
126 let output_file cic_string_uri rdf_string_uri =
127 let module U = UriManager in
128 let module X = Xml in
129 let content = output_content () in
130 let rdf_uri = U.uri_of_string rdf_string_uri in
131 make_dirs (pathname_of_uri (U.buri_of_uri rdf_uri)) ;
133 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
134 X.xml_nempty "rdf:RDF"
136 "xmlns:rdf","http://www.w3.org/1999/02/22-rdf-syntax-ns#";
137 "xmlns:h","http://www.cs.unibo.it/helm/schemas/schema-h.rdf#"]
140 Stream.empty content ; (* raise Stream.failure if not empty *)
141 X.xml_empty "h:Object" ["rdf:about",cic_string_uri]
144 X.xml_nempty "h:Object" ["rdf:about",cic_string_uri] content
147 (Some (pathname_of_uri rdf_string_uri ^ ".xml"))
151 let cicfilename = Getter.getxml uri in
152 let res = CicParser.obj_of_xml cicfilename uri in
153 Unix.unlink cicfilename ;
157 let add_every_constructor uri typeno kind =
158 let module C = Cic in
159 match (get_obj uri) with
160 (C.InductiveDefinition (itys,_,_)) ->
161 let string_uri = UriManager.string_of_uri uri in
162 let sn = string_of_int (typeno + 1) in
163 let (_,_,_,cons) = List.nth itys typeno in
166 let sm = string_of_int m in
168 (string_uri ^ "#xpointer(1/" ^ sn ^ "/" ^ sm ^ ")")
174 let process_type term =
175 let module U = UriManager in
176 let module H = UriHash in
177 let module C = Cic in
178 let rec process_type_aux kind =
181 H.add_uri (U.string_of_uri uri) kind
184 process_type_aux kind te
185 | C.Prod (_,sou,ta) ->
186 let (source_kind,target_kind) =
188 H.Backbone -> (H.Branch,H.Backbone)
189 | H.Branch -> (H.InHypothesis,H.InHypothesis)
190 | H.InBody -> assert false
193 process_type_aux source_kind sou ;
194 process_type_aux target_kind ta
195 | C.Lambda (_,sou,ta) ->
196 let kind' = H.soften_classification kind in
197 process_type_aux kind' sou ;
198 process_type_aux kind' ta
199 | C.LetIn (_,te,ta)->
200 let kind' = H.soften_classification kind in
201 process_type_aux kind' te ;
202 process_type_aux kind ta
204 let kind' = H.soften_classification kind in
205 process_type_aux kind he ;
206 List.iter (process_type_aux kind') tl
207 | C.Appl _ -> assert false
209 UriHash.add_uri (U.string_of_uri uri) kind
210 | C.Abst _ -> assert false
211 | C.MutInd (uri,_,typeno) ->
213 (U.string_of_uri uri ^ "#xpointer(1/" ^
214 string_of_int (typeno + 1) ^ ")")
216 | C.MutConstruct (uri,_,typeno,consno) ->
218 (U.string_of_uri uri ^ "#xpointer(1/" ^
219 string_of_int (typeno + 1) ^ "/" ^ string_of_int consno ^ ")")
221 | C.MutCase (uri,_,typeno,_,term,patterns) ->
222 (* outtype ignored *)
223 let kind' = H.soften_classification kind in
224 add_every_constructor uri typeno kind' ;
225 process_type_aux kind' term ;
226 List.iter (process_type_aux kind') patterns
228 let kind' = H.soften_classification kind in
230 (function (_,_,bo,ty) ->
231 process_type_aux kind' bo ;
232 process_type_aux kind' ty ;
234 | C.CoFix (_,funs) ->
235 let kind' = H.soften_classification kind in
237 (function (_,bo,ty) ->
238 process_type_aux kind' bo ;
239 process_type_aux kind' ty ;
243 process_type_aux H.Backbone (CicMiniReduction.letin_nf term)
247 let module U = UriManager in
248 let module H = UriHash in
249 let module C = Cic in
250 let rec process_body_aux =
253 H.add_uri (U.string_of_uri uri) H.InBody
255 process_body_aux te ;
257 | C.Prod (_,sou,ta) ->
258 process_body_aux sou ;
260 | C.Lambda (_,sou,ta) ->
261 process_body_aux sou ;
263 | C.LetIn (_,te,ta)->
264 process_body_aux te ;
267 List.iter process_body_aux l
269 UriHash.add_uri (U.string_of_uri uri) H.InBody
270 | C.Abst _ -> assert false
271 | C.MutInd (uri,_,typeno) ->
273 (U.string_of_uri uri ^ "#xpointer(1/" ^
274 string_of_int (typeno + 1) ^ ")")
276 | C.MutConstruct (uri,_,typeno,consno) ->
278 (U.string_of_uri uri ^ "#xpointer(1/" ^
279 string_of_int (typeno + 1) ^ "/" ^ string_of_int consno ^ ")")
281 | C.MutCase (uri,_,typeno,outtype,term,patterns) ->
282 add_every_constructor uri typeno H.InBody ;
283 process_body_aux outtype ;
284 process_body_aux term ;
285 List.iter process_body_aux patterns
288 (function (_,_,bo,ty) ->
289 process_body_aux bo ;
290 process_body_aux ty ;
292 | C.CoFix (_,funs) ->
294 (function (_,bo,ty) ->
295 process_body_aux bo ;
296 process_body_aux ty ;
303 let process_obj string_uri =
304 let module U = UriManager in
305 let module C = Cic in
307 (C.Definition (_,bo,ty,_)) ->
310 output_file string_uri string_uri
311 | (C.Axiom (_,ty,_)) ->
313 output_file string_uri string_uri
314 | (C.Variable (_,bo,ty)) ->
318 (Some bo') -> process_body bo'
321 output_file string_uri string_uri
322 | (C.InductiveDefinition _) as id ->
325 CicSubstitution.undebrujin_inductive_def
326 (U.uri_of_string string_uri) id
329 (C.InductiveDefinition (itys,_,_)) ->
331 (fun (_,_,ty,cons) n ->
332 let sn = string_of_int n in
335 (string_uri ^ "#xpointer(1/" ^ sn ^ ")")
336 (string_uri ^ "," ^ sn) ;
339 let sm = string_of_int m in
342 (string_uri ^ "#xpointer(1/" ^ sn ^ "/" ^ sm ^ ")")
343 (string_uri ^ "," ^ sn ^ "," ^ sm)
348 | (C.CurrentProof _) -> assert false
351 let mk_forward string_uri =
352 let module U = UriManager in
353 print_endline ("Now computing metadata of " ^ string_uri) ;
355 let uri = U.uri_of_string string_uri in
356 let obj = get_obj uri in
357 process_obj string_uri obj
361 let usage_msg = "usage: mk_forward[.opt] URI" in
367 prerr_string "No URI provided.\n" ;
368 Arg.usage [] usage_msg ;
371 else if !uri = "" then
375 prerr_string "More than two arguments provided.\n" ;
376 Arg.usage [] usage_msg ;
382 prerr_string "No URI provided.\n" ;
383 Arg.usage [] usage_msg ;