Commit 37a24ca2 authored by Bruno Guillaume's avatar Bruno Guillaume

add option old_grs

parent cc9d91ce
......@@ -14,7 +14,7 @@ open Libgrew
module Grew_args = struct
type mode = Gui | Corpus | Filter | Det | Full | Grep | Test
type mode = Gui | Corpus | Filter | Transform | Full | Grep | Test
let mode = ref Gui
type html_mode =
......@@ -25,6 +25,7 @@ module Grew_args = struct
let grs = ref None
let gr = ref None
let gui_doc = ref false
let old_grs = ref false
let input_data = ref ""
let output_dir = ref None
......@@ -57,7 +58,7 @@ module Grew_args = struct
let args = [
"-corpus", Unit (fun () -> mode := Corpus), " enable corpus mode";
"-det", Unit (fun () -> mode := Det), " enable det mode: rewrite a corpus with a deterministric grs";
"-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";
"-grep", Unit (fun () -> mode := Grep), " enable grep mode";
......@@ -67,6 +68,7 @@ module Grew_args = struct
(* options for all modes *)
"-grs", String (fun s -> grs := Some s), "<grs_file> chose the grs file to load";
"-old_grs", Unit (fun () -> old_grs := true), " Use old grs parser";
"-strat", String (fun s -> strat := s), "<strat> set the module strategy to use";
"-seq", String (fun s -> strat := s), "<strat> [DEPRECATED] replaced by -strat option";
"-timeout", Float (fun f -> timeout := Some f; Rewrite.set_timeout (Some f)), "<float> set a timeout on rewriting";
......
......@@ -181,7 +181,7 @@ let multi_conll () =
) ()
(* -------------------------------------------------------------------------------- *)
let det () =
let obsolete_det () =
handle (fun () ->
if !Grew_args.input_data = ""
then (Log.message "No input data specified: use -i option"; exit 1);
......@@ -274,6 +274,54 @@ let full () =
) ()
(* -------------------------------------------------------------------------------- *)
(* -------------------------------------------------------------------------------- *)
(* -------------------------------------------------------------------------------- *)
(* -------------------------------------------------------------------------------- *)
(* -------------------------------------------------------------------------------- *)
(* -------------------------------------------------------------------------------- *)
(* -------------------------------------------------------------------------------- *)
(* -------------------------------------------------------------------------------- *)
(* -------------------------------------------------------------------------------- *)
(* -------------------------------------------------------------------------------- *)
let transform () =
handle (fun () ->
if !Grew_args.input_data = ""
then (Log.message "No input data specified: use -i option"; exit 1);
match (!Grew_args.grs, !Grew_args.input_data, !Grew_args.output_file) with
| (None,_,_) -> Log.message "No grs filespecified: use -grs option"; exit 1
| (_,"",_) -> Log.message "No input data specified: use -i option"; exit 1
| (_,_,None) -> Log.message "No output specified: use -f option"; exit 1
| (Some grs_file, input, Some output_file) ->
let out_ch = open_out output_file 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 input in
let len = Array.length graph_array in
Array.iteri
(fun index (id, gr) ->
Counter.print index len id;
match Rewrite.simple_rewrite ~gr ~grs ~strat:!Grew_args.strat with
| [one] -> fprintf out_ch "%s\n" (Graph.to_conll_string ?domain one)
| l ->
List.iteri (fun i gr ->
let conll = Graph.to_conll ?domain gr in
let conll_new_id = Conll.set_sentid (sprintf "%s_%d" id i) conll in
fprintf out_ch "%s\n" (Conll.to_string conll_new_id)
) l
) graph_array;
close_out out_ch;
Counter.finish ()
) ()
(* -------------------------------------------------------------------------------- *)
let grep () = handle
(fun () ->
......@@ -285,7 +333,7 @@ let full () =
let domain = match !Grew_args.grs with
| None -> None
| Some grs_file -> Old_grs.get_domain (Old_grs.load grs_file) in
| Some file -> Grs.domain (if !Grew_args.old_grs then Grs.load_old file else Grs.load file) in
let pattern = Pattern.load ?domain pattern_file in
......@@ -339,5 +387,3 @@ let full () =
fprintf out_ch "%s" (Buffer.contents buff);
close_out out_ch
) ()
......@@ -81,7 +81,7 @@ module Resources = struct
| None -> ()
| Some file ->
Log.fmessage "Loading grs file: '%s'" file;
current_grs := Some (Grs.load file)
current_grs := Some (if !Grew_args.old_grs then Grs.load_old file else Grs.load file)
(* -------------------------------------------------------------------------------- *)
let domain () = match !current_grs with
......
......@@ -26,7 +26,7 @@ let _ =
match !Grew_args.mode with
| Grew_args.Gui -> Grew_gtk.init ()
| Grew_args.Corpus -> Grew_corpus.init ()
| Grew_args.Det -> Grew_corpus.det ()
| 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 ()
......
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