1 (* Copyright (C) 2005, 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 module Trivial_disambiguate:
28 exception Ambiguous_term of string Lazy.t
29 (** disambiguate an _unanmbiguous_ term using dummy callbacks which fail if a
30 * choice from the user is needed to disambiguate the term
31 * @raise Ambiguous_term for ambiguous term *)
32 val disambiguate_string:
34 ?context:Cic.context ->
35 ?metasenv:Cic.metasenv ->
36 ?initial_ugraph:CicUniv.universe_graph ->
37 ?aliases:DisambiguateTypes.environment ->(* previous interpretation status*)
39 ((DisambiguateTypes.domain_item * DisambiguateTypes.codomain_item) list *
40 Cic.metasenv * (* new metasenv *)
42 CicUniv.universe_graph) list (* disambiguated term *)
46 exception Ambiguous_term of string Lazy.t
50 let interactive_user_uri_choice ~selection_mode ?ok
51 ?(enable_button_for_non_vars = true) ~title ~msg ~id uris =
53 let interactive_interpretation_choice interp = raise Exit
54 let input_or_locate_uri ~(title:string) ?id = raise Exit
56 module Disambiguator = Disambiguate.Make (Callbacks)
57 let disambiguate_string ~dbd ?(context = []) ?(metasenv = []) ?initial_ugraph
58 ?(aliases = DisambiguateTypes.Environment.empty) term
61 CicNotationParser.parse_level2_ast (Ulexing.from_utf8_string term)
64 fst (Disambiguator.disambiguate_term ~dbd ~context ~metasenv ast
65 ?initial_ugraph ~aliases ~universe:None)
66 with Exit -> raise (Ambiguous_term (lazy term))
69 let configuration_file = ref "../../matita/matita.conf.xml";;
71 let core_notation_script = "../../matita/core_notation.moo";;
73 let get_from_user ~(dbd:HMysql.dbd) =
75 match read_line () with
79 let term_string = String.concat "\n" (get ()) in
80 let env, metasenv, term, ugraph =
81 List.nth (Trivial_disambiguate.disambiguate_string dbd term_string) 0
83 term, metasenv, ugraph
86 let full = ref false;;
88 let retrieve_only = ref false;;
91 let module S = Saturation in
92 let set_ratio v = S.weight_age_ratio := v; S.weight_age_counter := v
93 and set_sel v = S.symbols_ratio := v; S.symbols_counter := v;
94 and set_conf f = configuration_file := f
97 | "lpo" -> Utils.compare_terms := Utils.lpo
98 | "kbo" -> Utils.compare_terms := Utils.kbo
99 | "nr-kbo" -> Utils.compare_terms := Utils.nonrec_kbo
100 | o -> raise (Arg.Bad ("Unknown term ordering: " ^ o))
101 and set_fullred b = S.use_fullred := b
102 and set_time_limit v = S.time_limit := float_of_int v
103 and set_width w = S.maxwidth := w
104 and set_depth d = S.maxdepth := d
105 and set_full () = full := true
106 and set_retrieve () = retrieve_only := true
109 "-full", Arg.Unit set_full, "Enable full mode";
110 "-f", Arg.Bool set_fullred,
111 "Enable/disable full-reduction strategy (default: enabled)";
113 "-r", Arg.Int set_ratio, "Weight-Age equality selection ratio (default: 4)";
115 "-s", Arg.Int set_sel,
116 "symbols-based selection ratio (relative to the weight ratio, default: 0)";
118 "-c", Arg.String set_conf, "Configuration file (for the db connection)";
120 "-o", Arg.String set_ordering,
121 "Term ordering. Possible values are:\n" ^
122 "\tkbo: Knuth-Bendix ordering\n" ^
123 "\tnr-kbo: Non-recursive variant of kbo (default)\n" ^
124 "\tlpo: Lexicographic path ordering";
126 "-l", Arg.Int set_time_limit, "Time limit in seconds (default: no limit)";
128 "-w", Arg.Int set_width,
129 Printf.sprintf "Maximal width (default: %d)" !Saturation.maxwidth;
131 "-d", Arg.Int set_depth,
132 Printf.sprintf "Maximal depth (default: %d)" !Saturation.maxdepth;
134 "-retrieve", Arg.Unit set_retrieve, "retrieve only";
135 ] (fun a -> ()) "Usage:"
137 Helm_registry.load_from !configuration_file;
138 CicNotation.load_notation core_notation_script;
139 CicNotation.load_notation "../../matita/coq.ma";
140 let dbd = HMysql.quick_connect
141 ~host:(Helm_registry.get "db.host")
142 ~user:(Helm_registry.get "db.user")
143 ~database:(Helm_registry.get "db.database")
146 let term, metasenv, ugraph = get_from_user ~dbd in
147 if !retrieve_only then
148 Saturation.retrieve_and_print dbd term metasenv ugraph
150 Saturation.main dbd !full term metasenv ugraph