grew_args.ml 5.49 KB
Newer Older
bguillaum's avatar
bguillaum committed
1
2
3
4
5
6
7
8
9
10
(***********************************************************************)
(*    Grew - a Graph Rewriting tool dedicated to NLP applications      *)
(*                                                                     *)
(*    Copyright 2011-2013 Inria, Université de Lorraine                *)
(*                                                                     *)
(*    Webpage: http://grew.loria.fr                                    *)
(*    License: CeCILL (see LICENSE folder or "http://www.cecill.info") *)
(*    Authors: see AUTHORS file                                        *)
(***********************************************************************)

bguillaum's avatar
bguillaum committed
11
12
open Arg
open Log
13
open Libgrew
bguillaum's avatar
bguillaum committed
14
15
16

module Grew_args = struct

Bruno Guillaume's avatar
Bruno Guillaume committed
17
18
  type mode = Undefined | Gui of string | Transform | Grep | Test
  let mode = ref Undefined
bguillaum's avatar
bguillaum committed
19

20
  let grs = ref None
bguillaum's avatar
bguillaum committed
21
  let gui_doc = ref false
Bruno Guillaume's avatar
Bruno Guillaume committed
22
  let old_grs = ref false
23
  let dep_dir = ref None
bguillaum's avatar
bguillaum committed
24

Bruno Guillaume's avatar
Bruno Guillaume committed
25
  let (input_data : string list ref) = ref []
Bruno Guillaume's avatar
Bruno Guillaume committed
26
  let (output_file : string option ref) = ref None
Bruno Guillaume's avatar
Bruno Guillaume committed
27
  let strat = ref "main"
bguillaum's avatar
bguillaum committed
28
29
  let quiet = ref false
  let timeout = ref None
Bruno Guillaume's avatar
Bruno Guillaume committed
30
  let (pattern : string option ref) = ref None
31
  let html = ref false
Bruno Guillaume's avatar
Bruno Guillaume committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

  let help () = List.iter (fun x -> Printf.printf "%s\n" x) [
    "----------------------------------------------------------";
    "usage: grew <subcommand> [<args>]";
    "";
    "subcommands are:";
    "  transform  Apply a GRS on a corpus";
    "  gui        Run the Gtk interface";
    "  grep       Search for a pattern in a corpus";
    "  version    Print current version number";
    "  help <sub> Print help for the given subcommand";
    "";
    "see subcommands help for args";
    "For additional information, see http://grew.loria.fr";
    "----------------------------------------------------------";
  ]
bguillaum's avatar
bguillaum committed
48

Bruno Guillaume's avatar
Bruno Guillaume committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  let help_gui () = List.iter (fun x -> Printf.printf "%s\n" x) [
    "----------------------------------------------------------";
    "usage: grew gui [<args>]";
    "";
    "This subcommand runs the GTK interface for Grew.";
    "It supposes that the opam package \"grew_gui\" is installed.";
    "";
    "args are optionnal and can be change in the GUI:";
    "  -grs <file>    The Graph Rewriting System to load";
    "  -i <file>      The input data (a graph or a corpus)";
    "  -strat <name>  The stategy used by default";
    "";
    "For additional information, see http://grew.loria.fr";
    "----------------------------------------------------------";
  ]
Bruno Guillaume's avatar
Bruno Guillaume committed
64

Bruno Guillaume's avatar
Bruno Guillaume committed
65
66
67
68
  let help_grep () = List.iter (fun x -> Printf.printf "%s\n" x) [
    "----------------------------------------------------------";
    "usage: grew grep [<args>]";
    "";
Bruno Guillaume's avatar
Bruno Guillaume committed
69
    "This subcommand searches for a pattern in a corpus.";
Bruno Guillaume's avatar
Bruno Guillaume committed
70
71
72
73
74
75
76
77
    "";
    "args are optionnal and can be change in the GUI:";
    "  -pattern <pat>   The pattern to search for";
    "  -i <corp>        The input data";
    "";
    "For additional information, see http://grew.loria.fr";
    "----------------------------------------------------------";
  ]
bguillaum's avatar
bguillaum committed
78

Bruno Guillaume's avatar
Bruno Guillaume committed
79
80
81
82
  let help_transform () = List.iter (fun x -> Printf.printf "%s\n" x) [
    "----------------------------------------------------------";
    "usage: grew transform [<args>]";
    "";
Bruno Guillaume's avatar
Bruno Guillaume committed
83
    "This subcommand applies a grs to a graph or a corpus.";
Bruno Guillaume's avatar
Bruno Guillaume committed
84
    "";
Bruno Guillaume's avatar
Fix doc    
Bruno Guillaume committed
85
    "Required arguments:";
Bruno Guillaume's avatar
Bruno Guillaume committed
86
87
    "  -grs <file>    The Graph Rewriting System to load";
    "  -i <file>      The input data (a graph or a corpus)";
Bruno Guillaume's avatar
Fix doc    
Bruno Guillaume committed
88
89
90
91
    "  -o <file>      The output file";
    "";
    "Optionnal arguments:";
    "  -strat <name>  The stategy used in transformation (default=\"main\")";
Bruno Guillaume's avatar
Bruno Guillaume committed
92
93
94
95
    "";
    "For additional information, see http://grew.loria.fr";
    "----------------------------------------------------------";
  ]
bguillaum's avatar
bguillaum committed
96

Bruno Guillaume's avatar
Bruno Guillaume committed
97
  let rec loop = function
Bruno Guillaume's avatar
Fix doc    
Bruno Guillaume committed
98
  | [] -> ()
Bruno Guillaume's avatar
Bruno Guillaume committed
99
  | "-grs" :: file :: args -> grs := Some file; loop args
Bruno Guillaume's avatar
Bruno Guillaume committed
100
101
  | "-i" :: files :: args ->
      input_data := (Str.split (Str.regexp " ") files) @ !input_data; loop args
Bruno Guillaume's avatar
Fix doc    
Bruno Guillaume committed
102
  | "-o" :: file :: args -> output_file := Some file; loop args
Bruno Guillaume's avatar
Bruno Guillaume committed
103
104
  | "-strat" :: s :: args -> strat := s; loop args
  | "-pattern" :: file :: args -> pattern := Some file; loop args
105
  | "-html" :: args -> html := true; loop args
bguillaum's avatar
bguillaum committed
106

Bruno Guillaume's avatar
Fix doc    
Bruno Guillaume committed
107
  | "-timeout" :: f :: args -> timeout := Some (float_of_string f); Rewrite.set_timeout (Some (float_of_string f)); loop args
Bruno Guillaume's avatar
Bruno Guillaume committed
108
109
  | "-max_depth_det" :: i :: args -> Log.warning "max_depth_det not implemented, skip the arg"; loop args
  | "-max_depth_non_det" :: i :: args -> Log.warning "max_depth_non_det not implemented, skip the arg"; loop args
bguillaum's avatar
bguillaum committed
110

Bruno Guillaume's avatar
Bruno Guillaume committed
111
  | "-quiet" :: args -> quiet := true; loop args
112
  | "-old_grs" :: args -> old_grs := true; loop args
bguillaum's avatar
bguillaum committed
113

Bruno Guillaume's avatar
Bruno Guillaume committed
114
  | "-safe_commands" :: args -> Libgrew.set_safe_commands true; loop args
115
  | "-debug" :: args -> Libgrew.set_debug_mode true; loop args
116
117
  | "-debug_loop" :: args -> Rewrite.set_debug_loop (); loop args
  | "-dep_dir" :: dir :: args -> dep_dir := Some dir; loop args
bguillaum's avatar
bguillaum committed
118

Bruno Guillaume's avatar
Bruno Guillaume committed
119
  | x -> Log.fwarning "Ignored arguments: %s" (String.concat " " x)
bguillaum's avatar
bguillaum committed
120

bguillaum's avatar
bguillaum committed
121
  let parse () =
Bruno Guillaume's avatar
Bruno Guillaume committed
122
123
124
125
126
127
128
129
130
131
132
133
134
    match Array.to_list Sys.argv with
    | [] -> failwith "bug: Empty argv"
    | _ :: "gui" :: args -> mode := Gui (String.concat " " args)
    | _ :: "transform" :: args -> mode := Transform; loop args
    | _ :: "grep" :: args -> mode := Grep; loop args
    | _ :: "version" :: _ -> Printf.printf "%s\n" VERSION;
    | _ :: "help" :: "gui" :: _ -> help_gui ()
    | _ :: "help" :: "transform" :: _ -> help_transform ()
    | _ :: "help" :: "grep" :: _ -> help_grep ()
    | _ :: "help" :: "help" :: _ -> Printf.printf "Such a complex feature is still in development!\n"
    | [_] -> help ()
    | _ :: "help" :: _ -> help ()
    | _ :: cmd :: _ -> Log.fwarning "Unknown command \"%s\"" cmd; help()
bguillaum's avatar
bguillaum committed
135
end