Commit 5ad5e048 authored by Bruno Guillaume's avatar Bruno Guillaume

add “track_rules” flag in Global

parent 4ffd814d
......@@ -632,6 +632,8 @@ module Global = struct
let debug = ref false
let safe_commands = ref false
let track_rules = ref false
end (* module Global *)
module Dependencies = struct
......
......@@ -299,6 +299,7 @@ module Global: sig
val debug: bool ref
val safe_commands: bool ref
val track_rules: bool ref
end
(* ================================================================================ *)
......
......@@ -232,10 +232,10 @@ module G_graph = struct
map: G_node.t Gid_map.t; (* node description *)
fusion: fusion_item list; (* the list of fusion word considered in UD conll *)
highest_index: int; (* the next free integer index *)
rules: string list;
rules: int String_map.t;
}
let empty = { domain=None; meta=[]; map=Gid_map.empty; fusion=[]; highest_index=0; rules=[]; }
let empty = { domain=None; meta=[]; map=Gid_map.empty; fusion=[]; highest_index=0; rules=String_map.empty; }
let get_domain t = t.domain
......@@ -250,7 +250,12 @@ module G_graph = struct
let fold_gid fct t init =
Gid_map.fold (fun gid _ acc -> fct gid acc) t.map init
let push_rule rule_name t = { t with rules = rule_name :: t.rules }
let push_rule rule_name t =
if !Global.track_rules
then
let old = try String_map.find rule_name t.rules with Not_found -> 0 in
{ t with rules = String_map.add rule_name (old+1) t.rules }
else t
let get_rules t = t.rules
......@@ -350,7 +355,7 @@ module G_graph = struct
map;
fusion = [];
highest_index = final_index - 1;
rules = [];
rules = String_map.empty;
}
(* -------------------------------------------------------------------------------- *)
......@@ -478,7 +483,7 @@ module G_graph = struct
map = map_with_nl_nodes;
fusion;
highest_index = free_index -1;
rules = [];
rules = String_map.empty;
}
(* -------------------------------------------------------------------------------- *)
......@@ -542,7 +547,7 @@ module G_graph = struct
map=prec_loop map (List.rev !leaf_list);
fusion = [];
highest_index = !cpt;
rules = [];
rules = String_map.empty;
}
(* -------------------------------------------------------------------------------- *)
......@@ -1121,11 +1126,18 @@ module G_graph = struct
Conll_types.Int_map.add (i+1) mwe acc
) Conll_types.Int_map.empty snl_nodes in
let rules = "# rules " ^ (String_.rev_concat "," graph.rules) in
let text_rules = String_map.fold (fun rule_name occurrences acc ->
match acc with
| "" -> Printf.sprintf "%s[%d]" rule_name occurrences
| _ -> Printf.sprintf "%s[%d];%s" rule_name occurrences acc
) graph.rules "" in
let rules = match text_rules with
| "" -> []
| _ -> ["# rules " ^ text_rules] in
{
Conll.file = None;
Conll.meta = graph.meta @ [rules];
Conll.meta = graph.meta @ rules;
lines;
multiwords = []; (* multiwords are handled by _UD_* features *)
mwes;
......
......@@ -100,7 +100,6 @@ module G_graph: sig
val push_rule: string -> t -> t
val get_rules: t -> string list
(** [edge_out t id label_cst] returns true iff there is an out-edge from the node [id] with a label compatible with [label_cst] *)
val edge_out: t -> Gid.t -> Label_cst.t -> bool
......
......@@ -31,6 +31,8 @@ module Libgrew = struct
let set_safe_commands flag = Grew_base.Global.safe_commands := flag
let set_track_rules flag = Grew_base.Global.track_rules := flag
exception Error of string
exception Bug of string
......
......@@ -18,6 +18,7 @@ module Libgrew : sig
val get_version: unit -> string
val set_debug_mode: bool -> unit
val set_safe_commands: bool -> unit
val set_track_rules: bool -> unit
exception Error of string
exception Bug of string
......
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