Commit bf870865 authored by Bruno Guillaume's avatar Bruno Guillaume

remove unmaintained modes

parent 37a24ca2
......@@ -14,7 +14,7 @@ open Libgrew
module Grew_args = struct
type mode = Gui | Corpus | Filter | Transform | Full | Grep | Test
type mode = Gui | Transform | Grep | Test
let mode = ref Gui
type html_mode =
......@@ -56,11 +56,13 @@ module Grew_args = struct
Printf.printf "grew: %s\n" VERSION;
Printf.printf "libgrew: %s\n" (Libgrew.get_version ())
let obsolote mode = failwith (Printf.sprintf "The mode %s was removed, sorry!" mode)
let args = [
"-corpus", Unit (fun () -> mode := Corpus), " enable corpus mode";
"-corpus", Unit (fun () -> obsolote "corpus"), " enable corpus mode";
"-det", Unit (fun () -> mode := Transform), " enable det mode: rewrite a corpus with a deterministric grs";
"-full", Unit (fun () -> mode := Full), " enable full mode: rewrite a corpus (conll output)";
"-filter", Unit (fun () -> mode := Filter), " enable filter mode";
"-full", Unit (fun () -> obsolote "full"), " [REMOVED] enable full mode: rewrite a corpus (conll output)";
"-filter", Unit (fun () -> obsolote "filter"), " [REMOVED] enable filter mode";
"-grep", Unit (fun () -> mode := Grep), " enable grep mode";
"-test", Unit (fun () -> mode := Test), " enable test mode";
......
......@@ -34,256 +34,6 @@ let handle fct () =
| Libgrew.Bug msg -> fail (sprintf "Libgrew.bug, please report: %s" msg)
| exc -> fail (sprintf "Uncaught exception, please report: %s" (Printexc.to_string exc))
(* -------------------------------------------------------------------------------- *)
let init () =
handle (fun () ->
let output_dir = match !Grew_args.output_dir with
| None -> Log.message "No output_dir specified: use -o option"; exit 1
| Some dir -> dir in
(* remove previous file or dir <output_dir> *)
if Sys.file_exists output_dir
then
if Sys.is_directory output_dir
then ignore (Sys.command("rm -rf " ^ output_dir))
else Unix.unlink output_dir;
(* create a fresh <output_dir> *)
Unix.mkdir output_dir 0o777;
(* load grs file *)
let grs_file = match !Grew_args.grs with
| None -> Log.message "No grs filespecified: use -grs option"; exit 1
| Some f -> f in
let grs = Old_grs.load grs_file in
let domain = Old_grs.get_domain grs in
(* generate documentation in the [doc] folder *)
let _ = Old_grs.build_html_doc ~corpus:true (Filename.concat output_dir "doc") grs in
(* get the list of graphs to rewrite *)
let graph_array = Corpus.get_graphs ?domain !Grew_args.input_data in
let base_names = Array.map fst graph_array in
(* put the list of files to consider in the [index] file *)
Rewrite.save_index ~dirname:output_dir ~base_names;
(* put the grs file in the output folder *)
let _ = Sys.command (sprintf "cp %s %s" grs_file output_dir) in
let sentences = ref [] in
let len = Array.length graph_array in
Array.iteri
(fun index (base_name, gr) ->
Counter.print index len base_name;
let output_base = Filename.concat output_dir base_name in
(* a flag used by write_error to know if html is needed *)
let html = !Grew_args.html <> Grew_args.No in
let stat_file = sprintf "%s.stat" output_base in
let prev_opt =
if !Grew_args.html = Grew_args.Full_html && index > 0
then Some (fst (graph_array.(index-1)))
else None
and next_opt =
if !Grew_args.html = Grew_args.Full_html && index < len-1
then Some (fst (graph_array.(index+1)))
else None in
let header = Html.build_header prev_opt next_opt in
try
let rh = Rewrite.rewrite ~gr ~grs ~seq:!Grew_args.strat in
Rewrite.write_stat stat_file rh;
match !Grew_args.html with
| Grew_args.No
| Grew_args.Html when Rewrite.is_empty rh ->
sentences := (false, base_name, 1, Graph.to_sentence ?main_feat:!Grew_args.main_feat gr) :: !sentences
| _ ->
sentences := (true, base_name, Rewrite.num_sol rh, Graph.to_sentence ?main_feat:!Grew_args.main_feat gr) :: !sentences;
(* output gr files in corpus mode *)
if !Grew_args.out_gr then Rewrite.save_gr ?domain output_base rh;
(* output conll files in corpus mode *)
if !Grew_args.out_conll then Rewrite.save_conll ?domain output_base rh;
Rewrite.write_html
?domain
~no_init: !Grew_args.no_init
?filter: !Grew_args.features
?main_feat: !Grew_args.main_feat
~dot: !Grew_args.dot
~out_gr: !Grew_args.out_gr
~header
rh
output_base
with
| Libgrew.Bug msg ->
Html.write_error ?domain ~header ~html ~init:gr output_base (sprintf "Libgrew.bug, please report: %s" msg)
| Libgrew.Error msg -> Html.write_error ?domain ~header ~html ~init:gr output_base msg
) graph_array;
Counter.finish ();
let title = match !Grew_args.title with
| Some s -> s
| None -> sprintf "Grew corpus on input dir '%s'" (Filename.basename !Grew_args.input_data) in
(* TODO all confluent in Grs module *)
Rewrite.html_sentences ~title output_dir (List.rev !sentences);
Rewrite.make_index
~title
~grs_file
~html: (match !Grew_args.html with Grew_args.No -> false | _ -> true)
~grs
~seq: !Grew_args.strat
~input_dir: !Grew_args.input_data
~output_dir
~base_names
) ()
(* -------------------------------------------------------------------------------- *)
let multi_conll () =
handle (fun () ->
let out_ch = match !Grew_args.output_file with
| None -> Log.message "No output_file specified: use -f option"; exit 1
| Some file -> open_out file in
(* load grs file *)
let grs_file = match !Grew_args.grs with
| None -> Log.message "No grs filespecified: use -grs option"; exit 1
| Some f -> f in
let grs = Grs.load grs_file in
let domain = Grs.domain grs in
(* get the list of files to rewrite *)
let graph_array = Corpus.get_graphs ?domain !Grew_args.input_data in
let len = Array.length graph_array in
Array.iteri
(fun index (base_name, gr) ->
Counter.print index len base_name;
match Rewrite.simple_rewrite ~gr ~grs ~strat:!Grew_args.strat with
| [one] -> fprintf out_ch "%s\n" (Graph.to_conll_string ?domain one)
| l ->
let len = List.length l in
List.iteri (fun i gr ->
fprintf out_ch "# normal form number %d out of %d\n" (i+1) len;
fprintf out_ch "%s\n" (Graph.to_conll_string ?domain gr)
) l
) graph_array;
close_out out_ch;
Counter.finish ()
) ()
(* -------------------------------------------------------------------------------- *)
let obsolete_det () =
handle (fun () ->
if !Grew_args.input_data = ""
then (Log.message "No input data specified: use -i option"; exit 1);
match (!Grew_args.output_dir, !Grew_args.output_file) with
| (None, None) -> Log.message "No output specified: use -o or -f option"; exit 1
| (Some _, Some _) -> Log.message "Ambiguous output: you cannot use -o and -f options together"; exit 1
| (None, Some output_file) -> multi_conll ()
| (Some output_dir, None) ->
if not (!Grew_args.out_gr || !Grew_args.out_conll)
then (Log.message "No output format specified: use -out_gr or -out_conll option"; exit 1);
(* remove previous file or dir <output_dir> *)
if Sys.file_exists output_dir
then
if Sys.is_directory output_dir
then ignore (Sys.command("rm -rf " ^ output_dir))
else Unix.unlink output_dir;
(* create a fresh <output_dir> *)
Unix.mkdir output_dir 0o777;
(* load grs file *)
let grs_file = match !Grew_args.grs with
| None -> Log.message "No grs filespecified: use -grs option"; exit 1
| Some f -> f in
let grs = Old_grs.load grs_file in
let domain = Old_grs.get_domain grs in
(* get the list of graphs to rewrite *)
let graph_array = Corpus.get_graphs ?domain !Grew_args.input_data in
let len = Array.length graph_array in
Array.iteri
(fun index (base_name, gr) ->
Counter.print index len base_name;
let output_base = Filename.concat output_dir base_name in
let rh = Rewrite.rewrite ~gr ~grs ~seq:!Grew_args.strat in
if !Grew_args.out_gr then Rewrite.save_det_gr ?domain output_base rh;
if !Grew_args.out_conll then Rewrite.save_det_conll ?domain output_base rh
) graph_array;
Counter.finish ()
) ()
(* -------------------------------------------------------------------------------- *)
let full () =
handle (fun () ->
if !Grew_args.input_data = ""
then (Log.message "No input data specified: use -i option"; exit 1);
match (!Grew_args.output_dir, !Grew_args.output_file) with
| (None, None) -> Log.message "No output specified: use -o or -f option"; exit 1
| (Some _, Some _) -> Log.message "Ambiguous output: you cannot use -o and -f options together"; exit 1
| (None, Some output_file) -> multi_conll ()
| (Some output_dir, None) ->
if not (!Grew_args.out_gr || !Grew_args.out_conll)
then (Log.message "No output format specified: use -out_gr or -out_conll option"; exit 1);
(* remove previous file or dir <output_dir> *)
if Sys.file_exists output_dir
then
if Sys.is_directory output_dir
then ignore (Sys.command("rm -rf " ^ output_dir))
else Unix.unlink output_dir;
(* create a fresh <output_dir> *)
Unix.mkdir output_dir 0o777;
(* load grs file *)
let grs_file = match !Grew_args.grs with
| None -> Log.message "No grs filespecified: use -grs option"; exit 1
| Some f -> f in
let grs = Old_grs.load grs_file in
let domain = Old_grs.get_domain grs in
(* get the list of graphs to rewrite *)
let graph_array = Corpus.get_graphs ?domain !Grew_args.input_data in
let len = Array.length graph_array in
Array.iteri
(fun index (base_name, gr) ->
Counter.print index len base_name;
let output_base = Filename.concat output_dir base_name in
let rh = Rewrite.rewrite ~gr ~grs ~seq:!Grew_args.strat in
if !Grew_args.out_gr then failwith "Not yet";
if !Grew_args.out_conll then ignore (Rewrite.save_full_conll ?domain output_base rh)
) graph_array;
Counter.finish ()
) ()
(* -------------------------------------------------------------------------------- *)
(* -------------------------------------------------------------------------------- *)
(* -------------------------------------------------------------------------------- *)
(* -------------------------------------------------------------------------------- *)
(* -------------------------------------------------------------------------------- *)
(* -------------------------------------------------------------------------------- *)
(* -------------------------------------------------------------------------------- *)
(* -------------------------------------------------------------------------------- *)
(* -------------------------------------------------------------------------------- *)
(* -------------------------------------------------------------------------------- *)
let transform () =
handle (fun () ->
......@@ -317,10 +67,7 @@ let transform () =
) graph_array;
close_out out_ch;
Counter.finish ()
) ()
) ()
(* -------------------------------------------------------------------------------- *)
let grep () = handle
......
......@@ -25,10 +25,7 @@ let _ =
match !Grew_args.mode with
| Grew_args.Gui -> Grew_gtk.init ()
| Grew_args.Corpus -> Grew_corpus.init ()
| Grew_args.Transform -> Grew_corpus.transform ()
| Grew_args.Full -> Grew_corpus.full ()
| Grew_args.Filter -> Grew_corpus.multi_conll ()
| Grew_args.Grep -> Grew_corpus.grep ()
| Grew_args.Test -> failwith "No test available"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment