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 (* AUTOR: Ferruccio Guidi <fguidi@cs.unibo.it>
30 type position = string
34 type spec = MustObj of uri list * position list * depth list
35 | MustSort of sort list * position list * depth list
36 | MustRel of position list * depth list
37 | OnlyObj of uri list * position list * depth list
38 | OnlySort of sort list * position list * depth list
39 | OnlyRel of position list * depth list
40 | Universe of position list
42 type builtin_t = MainHypothesis
51 let text_of_builtin s =
52 let ns = "http://www.cs.unibo.it/helm/schemas/schema-helm#" in
53 if s = ns ^ "MainHypothesis" then "$MH" else
54 if s = ns ^ "InHypothesis" then "$IH" else
55 if s = ns ^ "MainConclusion" then "$MC" else
56 if s = ns ^ "InConclusion" then "$IC" else
57 if s = ns ^ "InBody" then "$IB" else
58 if s = "Set" then "$SET" else
59 if s = "Prop" then "$PROP" else
60 if s = "Type" then "$TYPE" else s
62 let text_of_spec out l =
63 let rec iter = function
65 | [s] -> out "\""; out (text_of_builtin s); out "\""
66 | s :: tail -> out "\""; out (text_of_builtin s); out "\", "; iter tail
68 let txt_list l = out "{"; iter l; out "} " in
69 let txt_spec = function
70 | MustObj (u, p, d) -> out "mustobj "; txt_list u; txt_list p; txt_list d; out "\n"
71 | MustSort (s, p, d) -> out "mustsort "; txt_list s; txt_list p; txt_list d; out "\n"
72 | MustRel ( p, d) -> out "mustrel "; txt_list p; txt_list d; out "\n"
73 | OnlyObj (u, p, d) -> out "onlyobj "; txt_list u; txt_list p; txt_list d; out "\n"
74 | OnlySort (s, p, d) -> out "onlysort "; txt_list s; txt_list p; txt_list d; out "\n"
75 | OnlyRel ( p, d) -> out "onlyrel "; txt_list p; txt_list d; out "\n"
76 | Universe ( p ) -> out "universe "; txt_list p; out "\n"
84 M.Property true M.RefineExact ["objectName"] [] [] [] []
91 let onlyobj = ref [] in
92 let onlysort = ref [] in
93 let onlyrel = ref [] in
94 let only = ref true in
96 let set_val = function
99 let msval = M.Set (List.map (fun s -> M.Const s) l) in
101 let vvar = "val" ^ string_of_int (List.length ! letin) in
102 letin := (vvar, msval) :: ! letin;
106 let cons o (r, s, p, d) =
109 | l -> [(false, [p], set_val l)]
112 con "h:occurrence" r @ con "h:sort" s @
113 con "h:position" p @ con "h:depth" d
115 let property_must n c =
116 M.Property true M.RefineExact [n] []
117 (cons false c) [] [] false (M.Const "")
119 let property_only n cl =
120 let cll = List.map (cons true) cl in
121 M.Property false M.RefineExact [n] []
122 ! univ cll [] false (M.Proj None (M.AVar "obj"))
124 let rec aux = function
126 | Universe l :: tail ->
127 only := true; univ := [(false, ["h:position"], set_val l)]; aux tail
128 | MustObj r p d :: tail ->
129 must := property_must "refObj" (r, [], p, d) :: ! must; aux tail
130 | MustSort s p d :: tail ->
131 must := property_must "refSort" ([], s, p, d) :: ! must; aux tail
132 | MustRel p d :: tail ->
133 must := property_must "refRel" ([], [], p, d) :: ! must; aux tail
134 | OnlyObj r p d :: tail ->
135 onlyobj := (r, [], p, d) :: ! onlyobj; aux tail
136 | OnlySort s p d :: tail ->
137 onlysort := ([], s, p, d) :: ! onlysort; aux tail
138 | OnlyRel p d :: tail ->
139 onlyrel := ([], [], p, d) :: ! onlyrel; aux tail
141 let rec iter f g = function
142 | [] -> raise (Failure "MQueryGenerator.iter")
144 | head :: tail -> let t = (iter f g tail) in g (f head) t
146 text_of_spec prerr_string cl;
150 M.Property false M.RefineExact [] [] [] [] [] true (M.Const ".*")
152 iter (fun x -> x) (fun x y -> M.Bin M.BinFMeet x y) ! must
154 let onlyobj_val = M.Not (M.Proj None (property_only "refObj" ! onlyobj)) in
155 let onlysort_val = M.Not (M.Proj None (property_only "refSort" ! onlysort)) in
156 let onlyrel_val = M.Not (M.Proj None (property_only "refRel" ! onlyrel)) in
158 match ! onlyobj, ! onlysort, ! onlyrel with
160 | _, [], [] -> M.Select "obj" x onlyobj_val
161 | [], _, [] -> M.Select "obj" x onlysort_val
162 | [], [], _ -> M.Select "obj" x onlyrel_val
163 | _, _, [] -> M.Select "obj" x (M.Test M.And onlyobj_val onlysort_val)
164 | _, [], _ -> M.Select "obj" x (M.Test M.And onlyobj_val onlyrel_val)
165 | [], _, _ -> M.Select "obj" x (M.Test M.And onlysort_val onlyrel_val)
166 | _, _, _ -> M.Select "obj" x (M.Test M.And (M.Test M.And onlyobj_val onlysort_val) onlyrel_val)
169 if ! letin = [] then fun x -> x
171 let f (vvar, msval) x = M.LetVVar vvar msval x in
172 iter f (fun x y z -> x (y z)) ! letin
174 M.StatQuery (letin_query (select_query must_query))
177 let ns = "http://www.cs.unibo.it/helm/schemas/schema-helm#" in
179 | MainHypothesis -> ns ^ "MainHypothesis"
180 | InHypothesis -> ns ^ "InHypothesis"
181 | MainConclusion -> ns ^ "MainConclusion"
182 | InConclusion -> ns ^ "InConclusion"
183 | InBody -> ns ^ "InBody"
188 (* conversion functions from the old constraints ***************************)
190 type old_depth = int option
192 type r_obj = uri * position * old_depth
193 type r_rel = position * old_depth
194 type r_sort = position * old_depth * sort
196 type universe = position list option
198 type must_restrictions = r_obj list * r_rel list * r_sort list
199 type only_restrictions =
200 r_obj list option * r_rel list option * r_sort list option
202 let query_of_constraints u (musts_obj, musts_rel, musts_sort)
203 (onlys_obj, onlys_rel, onlys_sort) =
206 | Some i -> [string_of_int i]
208 let must_obj (r, p, d) = MustObj ([r], [p], conv d) in
209 let must_sort (p, d, s) = MustSort ([s], [p], conv d) in
210 let must_rel (p, d) = MustRel ([p], conv d) in
211 let only_obj (r, p, d) = OnlyObj ([r], [p], conv d) in
212 let only_sort (p, d, s) = OnlySort ([s], [p], conv d) in
213 let only_rel (p, d) = OnlyRel ([p], conv d) in
214 let must = List.map must_obj musts_obj @
215 List.map must_rel musts_rel @
216 List.map must_sort musts_sort
219 (match onlys_obj with
221 | Some [] -> [OnlyObj ([], [], [])]
222 | Some l -> List.map only_obj l
224 (match onlys_rel with
226 | Some [] -> [OnlyRel ([], [])]
227 | Some l -> List.map only_rel l
229 (match onlys_sort with
231 | Some [] -> [OnlySort ([], [], [])]
232 | Some l -> List.map only_sort l
235 let univ = match u with None -> [] | Some l -> [Universe l] in
236 compose (must @ only @ univ)