Commit 3a7520b8 authored by Bruno Guillaume's avatar Bruno Guillaume
Browse files

Mutli_json

parent 96ef8819
......@@ -23,7 +23,7 @@ module Grew_args = struct
let grs = ref None
let dep_dir = ref None
type output = Conllx of Conllx_columns.t | Gr | Dot | Json
type output = Conllx of Conllx_columns.t | Gr | Dot | Json | Multi_json
let output = ref (Conllx Conllx_columns.default)
let (input_data : string list ref) = ref []
......@@ -109,6 +109,7 @@ module Grew_args = struct
| "-gr" :: args -> output := Gr; loop args
| "-dot" :: args -> output := Dot; loop args
| "-json" :: args -> output := Json; loop args
| "-multi_json" :: args -> output := Multi_json; loop args
| "-grew_match_server" :: dir :: args -> grew_match_server := Some dir; loop args
| "-force" :: args -> force := true; loop args
......
......@@ -77,12 +77,28 @@ let transform () =
let data = ref [] in
(fun graph -> data := (graph |> Graph.to_json) :: !data),
(fun () ->
let json = match !data with
| [one] -> one
| _ -> `List (List.rev !data) in
fprintf out_ch "%s\n" (Yojson.Basic.pretty_to_string json)
)
in
let json = match !data with
| [one] -> one
| _ -> `List (List.rev !data) in
fprintf out_ch "%s\n" (Yojson.Basic.pretty_to_string json)
)
| Grew_args.Multi_json ->
let data = ref [] in
(fun graph -> data := (graph |> Graph.to_json) :: !data),
(fun () ->
match (!Grew_args.output_data, !data) with
| (None,_) -> fail "-multi_json implies -o"
| (Some out_file, l) ->
let base =
match Filename.chop_suffix_opt ".json" out_file with
| Some b -> b
| None -> out_file in
List.iteri
(fun i json ->
let sub_out_ch = open_out (sprintf "%s__%d.json" base i) in
fprintf sub_out_ch "%s\n" (Yojson.Basic.pretty_to_string json)
) l
) in
Corpus.iteri
(fun index sent_id gr ->
......
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