]> matita.cs.unibo.it Git - helm.git/blob - components/metadata/metadataPp.ml
tagged 0.5.0-rc1
[helm.git] / components / 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 (* $Id$ *)
27
28 open Printf
29
30 open MetadataTypes
31
32 let pp_relation r = 
33   match r with
34   | Eq i -> sprintf "= %d" i
35   | Ge i -> sprintf ">= %d" i
36   | Gt i -> sprintf "> %d" i
37   | Le i -> sprintf "<= %d" i
38   | Lt i -> sprintf "< %d" i
39
40 let pp_position = function
41   | `MainConclusion (Some d) -> sprintf "MainConclusion(%s)" (pp_relation d)
42   | `MainConclusion None -> sprintf "MainConclusion"
43   | `MainHypothesis (Some d) -> sprintf "MainHypothesis(%s)" (pp_relation d)
44   | `MainHypothesis None -> "MainHypothesis"
45   | `InConclusion -> "InConclusion"
46   | `InHypothesis -> "InHypothesis"
47   | `InBody -> "InBody"
48
49 let pp_position_tag = function
50   | `MainConclusion _ -> mainconcl_pos
51   | `MainHypothesis _ -> mainhyp_pos
52   | `InConclusion -> inconcl_pos
53   | `InHypothesis -> inhyp_pos
54   | `InBody -> inbody_pos
55
56 let columns_of_position pos =
57   match pos with
58   | `MainConclusion (Some (Eq d)) -> `String mainconcl_pos, `Int d
59   | `MainConclusion None -> `String mainconcl_pos, `Null
60   | `MainHypothesis (Some (Eq d)) -> `String mainhyp_pos, `Int d
61   | `MainHypothesis None -> `String mainhyp_pos, `Null
62   | `InConclusion -> `String inconcl_pos, `Null
63   | `InHypothesis -> `String inhyp_pos, `Null
64   | `InBody -> `String inbody_pos, `Null
65   | _ -> assert false 
66
67 (*
68 let metadata_ns = "http://www.cs.unibo.it/helm/schemas/schema-helm"
69 let uri_of_pos pos = String.concat "#" [metadata_ns; pp_position pos]
70 *)
71
72 type t = [ `Int of int | `String of string | `Null ]
73
74 let columns_of_metadata_aux ~about metadata =
75   let sort s = `String (CicPp.ppsort s) in
76   let source = `String (UriManager.string_of_uri about) in
77   let occurrence u = `String (UriManager.string_of_uri u) in
78   List.fold_left
79     (fun (sort_cols, rel_cols, obj_cols) metadata ->
80       match metadata with
81       | `Sort (s, p) ->
82           let (p, d) = columns_of_position (p :> position) in
83           [source; p; d; sort s] :: sort_cols, rel_cols, obj_cols
84       | `Rel p ->
85           let (p, d) = columns_of_position (p :> position) in
86           sort_cols, [source; p; d] :: rel_cols, obj_cols
87       | `Obj (o, p) ->
88           let (p, d) = columns_of_position p in
89           sort_cols, rel_cols,
90           [source; occurrence o; p; d] :: obj_cols)
91     ([], [], []) metadata
92
93 let columns_of_metadata metadata =
94   List.fold_left
95     (fun (sort_cols, rel_cols, obj_cols) (uri, _, metadata) ->
96       let (s, r, o) = columns_of_metadata_aux ~about:uri metadata in
97       (List.append sort_cols s, List.append rel_cols r, List.append obj_cols o))
98     ([], [], []) metadata
99
100 let pp_constr =
101   function
102     | `Sort (sort, p) -> 
103         sprintf "Sort %s; [%s]" 
104           (CicPp.ppsort sort) (String.concat ";" (List.map pp_position p))
105     | `Rel p -> sprintf "Rel [%s]" (String.concat ";" (List.map pp_position p))
106     | `Obj (uri, p) -> sprintf "Obj %s; [%s]" 
107         (UriManager.string_of_uri uri) (String.concat ";" (List.map pp_position p))
108  
109 (*
110 let pp_columns ?(sep = "\n") (sort_cols, rel_cols, obj_cols) =
111   String.concat sep
112     ([ "Sort" ] @ List.map Dbi.sdebug (sort_cols :> Dbi.sql_t list list) @
113     [ "Rel" ] @ List.map Dbi.sdebug (rel_cols :> Dbi.sql_t list list) @
114     [ "Obj" ] @ List.map Dbi.sdebug (obj_cols :> Dbi.sql_t list list))
115 *)
116
117