]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/metadata/metadataPp.ml
added helm-metadata module
[helm.git] / helm / ocaml / metadata / metadataPp.ml
1 (* Copyright (C) 2004, HELM Team.
2  * 
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.
6  * 
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.
11  * 
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.
16  *
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,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://helm.cs.unibo.it/
24  *)
25
26 open Printf
27
28 let pp_position = function
29   | `MainConclusion -> "MainConclusion"
30   | `MainHypothesis -> "MainHypothesis"
31   | `InConclusion -> "InConclusion"
32   | `InHypothesis -> "InHypothesis"
33   | `InBody -> "InBody"
34
35 let metadata_ns = "http://www.cs.unibo.it/helm/schemas/schema-helm"
36 let uri_of_pos pos = String.concat "#" [metadata_ns; pp_position pos]
37
38 let pp_sort = function
39   | Cic.Prop -> "Prop"
40   | Cic.Set -> "Set"
41   | Cic.Type _ -> "Type"
42   | Cic.CProp -> "CProp"
43
44 type t = [ `Int of int | `String of string | `Null ]
45
46 let columns_of_metadata ~about metadatas =
47   let position p = `String (pp_position p) in
48   let sort s = `String (pp_sort s) in
49   let source = `String about in
50   let depth d = `Int d in
51   let depth_opt = function None -> `Null | Some d -> `Int d in
52   let occurrence u = `String u in
53   List.fold_left
54     (fun (sort_cols, rel_cols, obj_cols) metadata ->
55       match metadata with
56       | `Sort (s, p, d) ->
57           [source; position p; depth d; sort s] :: sort_cols, rel_cols, obj_cols
58       | `Rel (p, d) ->
59           sort_cols, [source; position p; depth d] :: rel_cols, obj_cols
60       | `Obj (o, p, d) ->
61           sort_cols, rel_cols,
62           [source; occurrence o; position p; depth_opt d] :: obj_cols)
63     ([], [], []) metadatas
64
65 let columns_of_ind_metadata ind_metadata =
66   List.fold_left
67     (fun (sort_cols, rel_cols, obj_cols) (uri, _, metadatas) ->
68       let (s, r, o) = columns_of_metadata ~about:uri metadatas in
69       (List.append sort_cols s, List.append rel_cols r, List.append obj_cols o))
70     ([], [], []) ind_metadata
71
72 let pp_columns ?(sep = "\n") (sort_cols, rel_cols, obj_cols) =
73   String.concat sep
74     ([ "Sort" ] @ List.map Dbi.sdebug (sort_cols :> Dbi.sql_t list list) @
75     [ "Rel" ] @ List.map Dbi.sdebug (rel_cols :> Dbi.sql_t list list) @
76     [ "Obj" ] @ List.map Dbi.sdebug (obj_cols :> Dbi.sql_t list list))
77