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