Commit c7fa64a4 authored by Bruno Guillaume's avatar Bruno Guillaume
Browse files

Add Graph.to_raw function needed for dep_diff

parent 8f674fe8
......@@ -374,6 +374,8 @@ module G_fs = struct
let to_json_python t = `Assoc (List.map (fun (fn, fv) -> (fn, `String (string_of_value fv))) t)
(* ---------------------------------------------------------------------- *)
let to_raw t = List.map (fun (name, value) -> (name, string_of_value value)) t
end (* module G_fs *)
(* ================================================================================ *)
......
......@@ -72,6 +72,7 @@ module G_fs: sig
val append_feats_opt: ?loc:Loc.t -> t -> t -> string -> string -> (t * (string * feature_value) list) option
val to_raw: t -> (string * string) list
end (* module G_fs *)
(* ================================================================================ *)
......
......@@ -1613,6 +1613,32 @@ module G_graph = struct
cyclic = !info.back_edges <> [];
}
(* -------------------------------------------------------------------------------- *)
let to_raw ~config graph =
let nodes = Gid_map.fold (fun id elt acc -> (id,elt)::acc) graph.map [] in
let snodes = List.sort
(fun (_,n1) (_,n2) ->
match (G_node.get_position_opt n1, G_node.get_position_opt n2) with
| (Some p1, Some p2) -> Stdlib.compare p1 p2
| _ -> 0
) nodes in
let raw_nodes = List.map (fun (gid,node) -> (gid, G_fs.to_raw (G_node.get_fs node))) snodes in
let get_num gid = list_num (fun (x,_) -> x=gid) raw_nodes in
let edge_list = ref [] in
Gid_map.iter
(fun src_gid node ->
Massoc_gid.iter
(fun tar_gid edge ->
match G_edge.to_string_opt ~config edge with
| Some e -> edge_list := (get_num src_gid, e, get_num tar_gid) :: !edge_list
| None -> edge_list := (get_num src_gid, G_edge.dump edge, get_num tar_gid) :: !edge_list
)
(G_node.get_next node)
)
graph.map;
(graph.meta, List.map snd raw_nodes, !edge_list)
end (* module G_graph *)
......
......@@ -255,6 +255,8 @@ module G_graph: sig
val get_relations: config:Conllx_config.t -> t -> String_set.t
val get_features: t -> String_set.t
val to_raw: config:Conllx_config.t -> t -> (string * string) list * (string * string) list list * (int * string * int) list
end (* module G_graph *)
(* ================================================================================ *)
......
......@@ -71,9 +71,9 @@ module Projection = struct
type t = Grew_types.Projection.t
let empty = Grew_types.Projection.empty
let prune_unambiguous = Grew_types.Projection.prune_unambiguous
let to_json = Grew_types.Projection.to_json
end
......@@ -281,9 +281,12 @@ module Graph = struct
let trace_depth t =
Grew_graph.G_graph.trace_depth t
let insert_proj keys t proj =
Grew_graph.G_graph.insert_proj keys t proj
let to_raw ~config graph =
Libgrew.handle ~name:"Graph.to_raw" (fun () -> Grew_graph.G_graph.to_raw ~config graph) ()
end
(* ==================================================================================================== *)
......
......@@ -174,6 +174,8 @@ module Graph : sig
val get_history: t -> (Deco.t * (string * int) * Deco.t * t) list
val trace_depth: t -> int
val to_raw: config:Conllx_config.t -> t -> (string * string) list * (string * string) list list * (int * string * int) list
end
(* ==================================================================================================== *)
......
Supports Markdown
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