]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/metadata/metadataPp.ml
- split metadata type in metadata and constraints. Metadata are computed
[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 (Some d) -> sprintf "MainConclusion(%d)" d
30   | `MainConclusion None -> sprintf "MainConclusion"
31   | `MainHypothesis (Some d) -> sprintf "MainHypothesis(%d)" d
32   | `MainHypothesis None -> "MainHypothesis"
33   | `InConclusion -> "InConclusion"
34   | `InHypothesis -> "InHypothesis"
35   | `InBody -> "InBody"
36
37 let pp_position_tag = function
38   | `MainConclusion _ -> "MainConclusion"
39   | `MainHypothesis _ -> "MainHypothesis"
40   | `InConclusion -> "InConclusion"
41   | `InHypothesis -> "InHypothesis"
42   | `InBody -> "InBody"
43
44 let columns_of_position = function
45   | `MainConclusion (Some d) -> `String "MainConclusion", `Int d
46   | `MainConclusion None -> `String "MainConclusion", `Null
47   | `MainHypothesis (Some d) -> `String "MainHypothesis", `Int d
48   | `MainHypothesis None -> `String "MainHypothesis", `Null
49   | `InConclusion -> `String "InConclusion", `Null
50   | `InHypothesis -> `String "InHypothesis", `Null
51   | `InBody -> `String "InBody", `Null
52
53 (*
54 let metadata_ns = "http://www.cs.unibo.it/helm/schemas/schema-helm"
55 let uri_of_pos pos = String.concat "#" [metadata_ns; pp_position pos]
56 *)
57
58 let pp_sort = function
59   | Cic.Prop -> "Prop"
60   | Cic.Set -> "Set"
61   | Cic.Type _ -> "Type"
62   | Cic.CProp -> "CProp"
63
64 type t = [ `Int of int | `String of string | `Null ]
65
66 let columns_of_metadata ~about metadatas =
67   let sort s = `String (pp_sort s) in
68   let source = `String about in
69   let occurrence u = `String u in
70   List.fold_left
71     (fun (sort_cols, rel_cols, obj_cols) metadata ->
72       match metadata with
73       | `Sort (s, p) ->
74           let (p, d) = columns_of_position p in
75           [source; p; d; sort s] :: sort_cols, rel_cols, obj_cols
76       | `Rel p ->
77           let (p, d) = columns_of_position p in
78           sort_cols, [source; p; d] :: rel_cols, obj_cols
79       | `Obj (o, p) ->
80           let (p, d) = columns_of_position p in
81           sort_cols, rel_cols,
82           [source; occurrence o; p; d] :: obj_cols)
83     ([], [], []) metadatas
84
85 let columns_of_ind_metadata ind_metadata =
86   List.fold_left
87     (fun (sort_cols, rel_cols, obj_cols) (uri, _, metadatas) ->
88       let (s, r, o) = columns_of_metadata ~about:uri metadatas in
89       (List.append sort_cols s, List.append rel_cols r, List.append obj_cols o))
90     ([], [], []) ind_metadata
91
92 let pp_columns ?(sep = "\n") (sort_cols, rel_cols, obj_cols) =
93   String.concat sep
94     ([ "Sort" ] @ List.map Dbi.sdebug (sort_cols :> Dbi.sql_t list list) @
95     [ "Rel" ] @ List.map Dbi.sdebug (rel_cols :> Dbi.sql_t list list) @
96     [ "Obj" ] @ List.map Dbi.sdebug (obj_cols :> Dbi.sql_t list list))
97