Skip to content

Commit

Permalink
Use Conll id in Graph.to_json
Browse files Browse the repository at this point in the history
Before this, in grewpy, it was impossible to get a node using matching info (on graphs with empty nodes)
  • Loading branch information
bguil committed Jan 1, 2024
1 parent 0b042d4 commit 4592423
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/grew_graph.ml
Expand Up @@ -672,15 +672,19 @@ module G_graph = struct
let nodes =
Gid_map.fold
(fun gid node acc ->
let item = (Gid.to_string gid, G_fs.to_json (G_node.get_fs node)) in
let item = (G_node.get_name gid node, G_fs.to_json (G_node.get_fs node)) in
item :: acc
) graph.map []
|> List.rev in

let name_of_gid gid =
let node = find gid graph in
G_node.get_name gid node in

let edges =
Gid_map.fold
(fun src_gid node acc ->
let src = `String (Gid.to_string src_gid) in
let src = `String (G_node.get_name src_gid node) in
Gid_massoc.fold
(fun acc2 tar_gid edge ->
match G_edge.to_json_opt edge with
Expand All @@ -689,24 +693,24 @@ module G_graph = struct
(`Assoc [
("src", src);
("label", js);
("tar", `String (Gid.to_string tar_gid));
("tar", `String (name_of_gid tar_gid));
]
) :: acc2
) acc (G_node.get_next node)
) graph.map [] in

let order = List.map (fun s -> `String (Gid.to_string s)) (get_ordered_gids graph) in
let order = List.map (fun s -> `String (name_of_gid s)) (get_ordered_gids graph) in

let modified_nodes =
List.map
(fun (gid,(_,hf_list)) ->
`Assoc [("id", `String (Gid.to_string gid)); ("features", `List (List.map (fun (fn, _) -> `String fn) hf_list))]
`Assoc [("id", `String (name_of_gid gid)); ("features", `List (List.map (fun (fn, _) -> `String fn) hf_list))]
) graph.impact.nodes in

let modified_edges =
List.map
(fun (gid1,edge,gid2) ->
`Assoc [("src", `String (Gid.to_string gid1)); ("edge", G_edge.to_json edge); ("tar", `String (Gid.to_string gid2))]
`Assoc [("src", `String (name_of_gid gid1)); ("edge", G_edge.to_json edge); ("tar", `String (name_of_gid gid2))]
) graph.impact.edges in

let full_assoc_list = [
Expand Down

0 comments on commit 4592423

Please sign in to comment.