Commit 46a19265 authored by bguillaum's avatar bguillaum
Browse files

add an optional header line in conll output

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/semagramme/libcaml-grew/trunk@7842 7838e531-6607-4d57-9587-6c381814729c
parent af0ba680
...@@ -9,7 +9,7 @@ open Grew_command ...@@ -9,7 +9,7 @@ open Grew_command
open Grew_graph open Grew_graph
open Grew_rule open Grew_rule
(* ==================================================================================================== *)
module Rewrite_history = struct module Rewrite_history = struct
type t = { type t = {
...@@ -71,11 +71,16 @@ module Rewrite_history = struct ...@@ -71,11 +71,16 @@ module Rewrite_history = struct
| _ -> Error.run "Not a single rewriting" | _ -> Error.run "Not a single rewriting"
in loop t in loop t
let save_det_conll base t = let save_det_conll ?header base t =
let rec loop t = let rec loop t =
match (t.good_nf, t.bad_nf) with match (t.good_nf, t.bad_nf) with
| [],[] -> File.write (Instance.to_conll t.instance) (base^".conll") | ([],[]) ->
| [one], [] -> loop one let output =
match header with
| Some h -> sprintf "%% %s\n%s" h (Instance.to_conll t.instance)
| None -> Instance.to_conll t.instance in
File.write output (base^".conll")
| ([one], []) -> loop one
| _ -> Error.run "Not a single rewriting" | _ -> Error.run "Not a single rewriting"
in loop t in loop t
...@@ -88,11 +93,9 @@ module Rewrite_history = struct ...@@ -88,11 +93,9 @@ module Rewrite_history = struct
| [one], [] -> loop one | [one], [] -> loop one
| _ -> Error.run "Not a single rewriting" | _ -> Error.run "Not a single rewriting"
in loop t in loop t
end end (* Rewrite_history *)
(* ==================================================================================================== *)
module Modul = struct module Modul = struct
type t = { type t = {
name: string; name: string;
...@@ -127,8 +130,9 @@ module Modul = struct ...@@ -127,8 +130,9 @@ module Modul = struct
loc = ast_module.Ast.mod_loc; loc = ast_module.Ast.mod_loc;
} in } in
check modul; modul check modul; modul
end end (* module Modul *)
(* ==================================================================================================== *)
module Sequence = struct module Sequence = struct
type t = { type t = {
name: string; name: string;
...@@ -152,13 +156,14 @@ module Sequence = struct ...@@ -152,13 +156,14 @@ module Sequence = struct
loc = ast_sequence.Ast.seq_loc; loc = ast_sequence.Ast.seq_loc;
} in } in
check module_list sequence; sequence check module_list sequence; sequence
end end (* module Sequence *)
(* ==================================================================================================== *)
module Grs = struct module Grs = struct
type t = { type t = {
labels: Label.t list; (* the list of global edge labels *) labels: Label.t list; (* the list of global edge labels *)
modules: Modul.t list; (* the ordered list of modules used from rewriting *) modules: Modul.t list; (* the ordered list of modules used from rewriting *)
sequences: Sequence.t list; sequences: Sequence.t list;
} }
...@@ -278,4 +283,4 @@ module Grs = struct ...@@ -278,4 +283,4 @@ module Grs = struct
(fun modul -> (fun modul ->
List.iter (fun filter -> fct modul.Modul.name filter) modul.Modul.filters List.iter (fun filter -> fct modul.Modul.name filter) modul.Modul.filters
) grs.modules ) grs.modules
end end (* module Grs *)
...@@ -34,7 +34,7 @@ module Rewrite_history: sig ...@@ -34,7 +34,7 @@ module Rewrite_history: sig
(** [save_det_gr base_name t] supposes that the current GRS is deterministic. (** [save_det_gr base_name t] supposes that the current GRS is deterministic.
It writes exactly one output file named [base_name].gr with the unique normal form. *) It writes exactly one output file named [base_name].gr with the unique normal form. *)
val save_det_gr: string -> t -> unit val save_det_gr: string -> t -> unit
val save_det_conll: string -> t -> unit val save_det_conll: ?header:string -> string -> t -> unit
val det_dep_string: t -> string val det_dep_string: t -> string
end end
......
...@@ -163,7 +163,7 @@ let save_conll base rew_hist = Rewrite_history.save_conll base rew_hist ...@@ -163,7 +163,7 @@ let save_conll base rew_hist = Rewrite_history.save_conll base rew_hist
let save_det_gr base rew_hist = Rewrite_history.save_det_gr base rew_hist let save_det_gr base rew_hist = Rewrite_history.save_det_gr base rew_hist
let save_det_conll base rew_hist = Rewrite_history.save_det_conll base rew_hist let save_det_conll ?header base rew_hist = Rewrite_history.save_det_conll ?header base rew_hist
let det_dep_string rew_hist = Rewrite_history.det_dep_string rew_hist let det_dep_string rew_hist = Rewrite_history.det_dep_string rew_hist
......
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