1 (* Read scores file and display the spam scores of each word. *)
8 let default_confdir = (Unix.getenv
"HOME") ^
"/settings/mailvisa2"
9 let default_scorefile = "scores"
11 let usage = "USAGE: mailvisa-view-scores [options]"
12 let help = "Valid options are:
14 -c <path> Look for files in <path> (default: $HOME/settings/mailvisa)
15 -f <path> Load scores from <path> (default: scores)"
19 (** Parse command options from args into hash table. *)
20 let parse_options args
=
21 let options = Hashtbl.create
2 in
23 let add_option name
= increment
i; Hashtbl.add
options name args
.(!i) in
24 while !i < (Array.length args
) do
30 | "-c" -> add_option "confdir"
31 | "-f" -> add_option "scorefile"
33 output_string stderr
("Invalid option: " ^
option ^
"\n");
41 let options = parse_options Sys.argv
42 let confdir = get_option_with_default
options "confdir" default_confdir
44 (** Create an absolute path from a path, by prepending confdir if the path does not contain a slash. *)
45 let absolute_path path
=
46 if String.contains path '
/'
then path
47 else (confdir ^
"/" ^ path
)
49 (* Set constants from command line options *)
50 let scorefile = absolute_path (hash_get
options "scorefile" ~default
:default_scorefile)
54 let wordlist = load_wordlist
scorefile in
56 (fun word score
-> print_endline
(word ^
": " ^
(string_of_float score
)))
57 (wordlist_words
wordlist)