]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/tactics/tacticChaser.ml
Merge of the V7_3_new_exportation branch.
[helm.git] / helm / ocaml / tactics / tacticChaser.ml
1 (* Copyright (C) 2000-2002, 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://cs.unibo.it/helm/.
24  *)
25
26 (******************************************************************************)
27 (*                                                                            *)
28 (*                               PROJECT HELM                                 *)
29 (*                                                                            *)
30 (*                Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>               *)
31 (*                                 18/02/2003                                 *)
32 (*                                                                            *)
33 (*                                                                            *)
34 (******************************************************************************)
35
36   (* search arguments on which Apply tactic doesn't fail *)
37 let searchPattern mqi_handle ?(output_html = (fun _ -> ())) ~choose_must () ~status =
38  let ((_, metasenv, _, _), metano) = status in
39  let (_, ey ,ty) = List.find (function (m,_,_) -> m=metano) metasenv in
40   let list_of_must,only = MQueryLevels.out_restr metasenv ey ty in
41   let must = choose_must list_of_must only in
42   let torigth_restriction (u,b) =
43    let p =
44     if b then
45      "http://www.cs.unibo.it/helm/schemas/schema-helm#MainConclusion" 
46     else
47      "http://www.cs.unibo.it/helm/schemas/schema-helm#InConclusion"
48     in
49     (u,p,None)
50   in
51   let rigth_must = List.map torigth_restriction must in
52   let rigth_only = Some (List.map torigth_restriction only) in
53   let result =
54          MQueryInterpreter.execute mqi_handle 
55             (MQueryGenerator.query_of_constraints None
56                 (rigth_must,[],[]) (rigth_only,None,None)) in 
57         let uris =
58          List.map
59                 (function uri,_ ->
60                         MQueryMisc.wrong_xpointer_format_from_wrong_xpointer_format' uri
61                 ) result in
62          let uris',exc =
63                 let rec filter_out =
64                  function
65                                 [] -> [],""
66                         | uri::tl ->
67                                  let tl',exc = filter_out tl in
68                                         try
69                                          if
70                                                 (try
71                                                  ignore
72                                                         (PrimitiveTactics.apply_tac
73                                                          ~term:(MQueryMisc.term_of_cic_textual_parser_uri
74                                                                 (MQueryMisc.cic_textual_parser_uri_of_string uri))
75                                                          ~status);
76                                                  true
77                                                 with ProofEngineTypes.Fail _ -> false)
78                                          then
79                                                 uri::tl',exc
80                                          else
81                                                 tl',exc
82                                         with
83            (ProofEngineTypes.Fail _) as e ->
84                                                  let exc' =
85                                                   "<h1 color=\"red\"> ^ Exception raised trying to apply " ^
86                                                          uri ^ ": " ^ Printexc.to_string e ^ " </h1>" ^ exc
87                                                  in
88                                                   tl',exc'
89                 in
90                  filter_out uris
91          in
92                 let html' =
93                  " <h1>Objects that can actually be applied: </h1> " ^
94                  String.concat "<br>" uris' ^ exc ^
95                  " <h1>Number of false matches: " ^
96                         string_of_int (List.length uris - List.length uris') ^ "</h1>" ^
97                  " <h1>Number of good matches: " ^
98                         string_of_int (List.length uris') ^ "</h1>"
99                 in
100                  output_html html' ;
101                  uris'
102 ;;
103