Add -doc-stats options to print document statistics.
[SXSI/xpathcomp.git] / src / options.ml
1 open Utils
2 open Format
3
4 let index_empty_texts = ref true
5 let sample_factor = ref 64
6 let disable_text_collection = ref false
7 let tc_threshold = ref 60000
8
9 let query = ref ""
10 let input_file = ref ""
11 let output_file = ref None
12 let save_file = ref ""
13 let count_only = ref false
14 let time = ref false
15 let bottom_up = ref false
16 let no_jump = ref false
17 let verbose = ref false
18 let text_index_type = ref 0
19 let do_perf = ref false
20 let twopass = ref false
21 let repeat = ref 1
22 let docstats = ref false
23
24 let set_index_type = function
25   | "default" -> text_index_type := 0
26   | "swcsa" -> text_index_type := 1
27   | "rlcsa" -> text_index_type := 2
28   | s -> raise (Arg.Bad(s))
29
30 let usage_msg = Printf.sprintf "%s [options] <input.{xml|srx}> 'query' [output]" Sys.argv.(0)
31
32 let pos = ref 0
33 let anon_fun =
34   fun s -> match !pos with
35     | 0 -> input_file:= s;incr pos
36     | 1 -> query := s; incr pos
37     | 2 -> output_file := Some s; incr pos
38     | _ -> raise (Arg.Bad(s))
39
40 let set_logger s =
41   List.iter (fun t ->
42     if t = "" then ()
43     else
44       match String.explode t ':' with
45         [ tr; lvl ] ->
46           let l = try int_of_string lvl with _ -> raise (Arg.Bad (lvl)) in
47           if Logger.is_logger tr then Logger.activate tr l
48           else raise (Arg.Bad (t))
49       | _ -> raise (Arg.Bad (t))
50   ) (String.explode s ',')
51
52 let pretty_loggers () =
53   ignore(flush_str_formatter());
54   Pretty.print_list
55     ~sep:", "
56     (fun f s -> fprintf f "%s" s)
57     str_formatter
58     (Logger.available ());
59   flush_str_formatter ()
60
61 let spec = Arg.align
62   [ "-c", Arg.Set(count_only),
63     " counting only (don't materialize the result set)";
64
65     "-two", Arg.Set(twopass),
66     " Use twopass algorithm";
67
68     "-f", Arg.Set_int(sample_factor),
69     "<n> sample factor [default=64]";
70
71     "-ne", Arg.Clear(index_empty_texts),
72     " don't index empty texts [default=index]";
73
74     "-d", Arg.Set(disable_text_collection),
75     " disable text collection[default=false]";
76
77     "-s", Arg.Set_string(save_file),
78     "<save_file> save the intermediate representation into file.srx";
79
80     "-b", Arg.Set(bottom_up), " real bottom up run";
81
82     "-nj", Arg.Set(no_jump), " disable jumping";
83
84     "-p",  Arg.Set(do_perf), " dump perf counters (Linux only)";
85
86     "-index-type", Arg.Symbol ([ "default"; "swcsa"; "rlcsa" ],
87                                set_index_type),
88     " choose text index type";
89
90     "-r", Arg.Set_int(repeat),
91     " repeat query execution n time (benchmarking only, default 1)";
92
93     "-doc-stats", Arg.Set(docstats),
94     " Compute document statistics (performs full traversal)";
95
96
97     "-v", Arg.Set(verbose), " verbose mode"; ] @
98 IFNDEF NTRACE
99 THEN [
100     "-log", Arg.String (set_logger),
101     "<logger1:l1,...,loggern:ln> enable logging with the specified level. Valid loggers are: "
102       ^ (pretty_loggers ())
103      ]
104 ELSE []
105 END
106
107
108 let parse_cmdline() =
109   let _ = Arg.parse spec anon_fun usage_msg
110   in
111   if (!pos > 3 || !pos < 2)
112   then begin Arg.usage spec usage_msg; exit 1 end
113
114
115
116
117