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

get rid of old Conll implementation, now depends on libgrew

parent a175ef69
S src
B _build/src
PKG log conll svg containers yojson dep2pict
PKG log conll svg containers yojson dep2pict libgrew
true: package(containers, str, ANSITerminal, yojson, camomile, cairo2, log, conll, dep2pict)
true: package(containers, str, ANSITerminal, yojson, camomile, cairo2, log, conll, dep2pict, amr, libgrew)
......@@ -16,6 +16,7 @@ depends: [
"libcaml-log"
"camomile"
"libcaml-dep2pict"
"libcaml-grew"
]
synopsis: "A command line program to draw linguistic dependencies (see dep2pict.loria.fr)"
url {
......
open Printf
open Log
open Conll
open Dep2pict
open Conllx
exception Found of int
......@@ -94,7 +94,7 @@ let (output_file : string option ref) = ref None
type input_data =
| Dep of Dep2pict.t
| Conll of (string * Conll.t) array
| Conll of (string * Conllx.t) array
let current_data = ref (Conll [||])
let (current_position : int ref) = ref 0 (* position of the current_focus in the current_array *)
......@@ -194,10 +194,10 @@ let view_label () =
let load file =
match Format.get file with
| Format.Dep -> let dep = File.read file in current_data := Dep (Dep2pict.from_dep dep)
| Format.Conll -> current_data := Conll (Conll_corpus.load file)
| Format.Conll -> current_data := Conll (Conllx_corpus.get_data (Conllx_corpus.load file))
| _ ->
Log.fwarning "No valid input format detected for file \"%s\", try to guess...\n%!" file;
let text = File.read file in
if String.length text > 0 && (text.[0] = '1' || text.[0] = '#')
then current_data := Conll (Conll_corpus.load file)
then current_data := Conll (Conllx_corpus.get_data (Conllx_corpus.load file))
else current_data := Dep (Dep2pict.from_dep text)
open Printf
open Log
open Conll
open Dep2pict
open Conllx
open Libgrew
open Global
......@@ -136,8 +137,7 @@ let main () =
let graph = match (!current_data, !current_position) with
| (Dep g,_) -> g
| (Conll [||],_) -> error ~file: !input_file "Empty Conll file"
| (Conll arr, pos) ->
Dep2pict.from_conll ~show_root: !show_root ~rtl:!rtl ~conll:(snd arr.(pos)) in
| (Conll arr, pos) -> snd arr.(pos) |> Conllx.to_json |> Graph.of_json |> Graph.to_dep ~config:(Conllx_config.build "ud") |> (fun d -> Dep2pict.from_dep d) in
begin
match Format.get out_file with
| Format.Svg -> Dep2pict.save_svg ~filename:out_file graph
......@@ -145,7 +145,9 @@ let main () =
| Format.Png -> Dep2pict.save_png ~filename:out_file graph
| Format.Dep -> (
match (!current_data, !current_position) with
| (Conll arr, p) -> File.write out_file (Dep2pict.conll_to_dep ~show_root: !show_root ~conll:(snd arr.(p)))
| (Conll arr, p) ->
let dep = snd arr.(p) |> Conllx.to_json |> Graph.of_json |> Graph.to_dep ~config:(Conllx_config.build "ud") in
File.write out_file dep
| _ -> critical "<dep> output format is available only for <conll> inputs"
)
| f -> critical "<%s> is not a valid output format" (Format.to_string f)
......@@ -154,7 +156,7 @@ let main () =
with
| Error json -> raise (Error json)
| Dep2pict.Error json -> raise (Error json)
| Conll_error json -> raise (Error json)
| Conllx_error json -> raise (Error json)
| Sys_error data -> error ~file: !input_file ~data "Sys_error"
| exc -> error ~file: !input_file ~data:(Printexc.to_string exc) "Unexpected exception, please report"
......
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