Commit 8ddfbce9 authored by bguillaum's avatar bguillaum

New gui

git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/semagramme/dep2pict/trunk@8324 7838e531-6607-4d57-9587-6c381814729c
parent 10077337
......@@ -2,40 +2,50 @@ include ../config/Makefile
LOG = -DDEBUG=\"@DEBUG@\" -DINFO=\"@INFO@\" -DMESSAGE=\"@MESSAGE@\" -DWARNING=\"@WARNING@\"
opt_gtk : ui.ml ui.cmx gui.cmx main.cmx ../bin/dep2pict.opt
opt_gtk : dep2pict_glade.ml dep2pict_glade.cmx gui.cmx main.cmx ../bin/dep2pict.opt
opt : main.cmx ../bin/dep2pict.opt
ui.ml : dep2pict.glade
sed 's/<property name="invisible_char">&#x25CF;<\/property>//g' dep2pict.glade > glade.tmp
mv glade.tmp dep2pict.glade.ml
lablgladecc2 dep2pict.glade.ml > ui.ml
rm dep2pict.glade.ml
sed 's|dep2pict.glade.ml|$(DATA_DIR)dep2pict.glade|g' ui.ml > ui.tmp
mv ui.tmp ui.ml
dep2pict_glade.ml : dep2pict.glade
@echo " ----> build file 'dep2pict_glade.ml' from 'dep2pict.glade'"
lablgladecc2 dep2pict.glade > dep2pict_glade.ml
@echo " ----> set absolute file location in 'dep2pict_glade.ml' (DATA_DIR = $(DATA_DIR))"
sed -i back 's|dep2pict.glade|$(DATA_DIR)dep2pict.glade|g' dep2pict_glade.ml
rm -f dep2pict_glade.mlback
ui.cmx : ui.ml
$(OCAMLOPT) -c $(LABLGTK_OPT) $(CAIRO_OPT) ui.ml
# dep2pict_glade.ml : dep2pict.glade
# sed 's/<property name="invisible_char">&#x25CF;<\/property>//g' dep2pict.glade > glade.tmp
# mv glade.tmp dep2pict.glade.ml
# lablgladecc2 dep2pict.glade.ml > dep2pict_glade.ml
# rm dep2pict.glade.ml
# sed 's|dep2pict.glade.ml|$(DATA_DIR)dep2pict.glade|g' dep2pict_glade.ml > dep2pict_glade.tmp
# mv dep2pict_glade.tmp dep2pict_glade.ml
dep2pict_glade.cmx : dep2pict_glade.ml
$(OCAMLOPT) -c $(LABLGTK_OPT) $(CAIRO_OPT) dep2pict_glade.ml
DEP_OPT= unix.cmxa str.cmxa bigarray.cmxa $(LABLGTK_OPT) $(CAIRO_OPT) $(XML_LIGHT_OPT) $(ANSITERMINAL_OPT) $(LOG_OPT) $(DEP2PICT_OPT)
DEP_OPT_NOGUI= unix.cmxa str.cmxa bigarray.cmxa $(CAIRO_OPT) $(XML_LIGHT_OPT) $(ANSITERMINAL_OPT) $(LOG_OPT) $(DEP2PICT_OPT)
gui.cmx : gui.ml ui.cmx
$(OCAMLOPT) -c -pp 'camlp4o pa_macro.cmo -DBUILD_GUI -DDATA_DIR=\"$(DATA_DIR)\" $(LOG) -DVERSION=\"$(VERSION)\"' $(DEP_OPT) ui.cmx gui.ml
global.cmx : global.ml
$(OCAMLOPT) -c -pp 'camlp4o pa_macro.cmo -DBUILD_GUI -DDATA_DIR=\"$(DATA_DIR)\" $(LOG) -DVERSION=\"$(VERSION)\"' $(DEP_OPT) global.ml
main.cmx : main.ml
gui.cmx : gui.ml global.cmx dep2pict_glade.cmx
$(OCAMLOPT) -c -pp 'camlp4o pa_macro.cmo -DBUILD_GUI -DDATA_DIR=\"$(DATA_DIR)\" $(LOG) -DVERSION=\"$(VERSION)\"' $(DEP_OPT) dep2pict_glade.cmx gui.ml
main.cmx : main.ml global.cmx
ifeq (@BUILD_GUI@,yes)
$(OCAMLOPT) -c -pp 'camlp4o pa_macro.cmo -DBUILD_GUI -DDATA_DIR=\"$(DATA_DIR)\" $(LOG) -DVERSION=\"$(VERSION)\"' $(DEP_OPT) ui.cmx gui.cmx main.ml
$(OCAMLOPT) -c -pp 'camlp4o pa_macro.cmo -DBUILD_GUI -DDATA_DIR=\"$(DATA_DIR)\" $(LOG) -DVERSION=\"$(VERSION)\"' $(DEP_OPT) dep2pict_glade.cmx global.cmx gui.cmx main.ml
else
$(OCAMLOPT) -c -pp 'camlp4o pa_macro.cmo -DDATA_DIR=\"$(DATA_DIR)\" $(LOG) -DVERSION=\"$(VERSION)\"' $(DEP_OPT) main.ml
$(OCAMLOPT) -c -pp 'camlp4o pa_macro.cmo -DDATA_DIR=\"$(DATA_DIR)\" $(LOG) -DVERSION=\"$(VERSION)\"' $(DEP_OPT) global.cmx main.ml
endif
../bin/dep2pict.opt : main.cmx
mkdir -p ../bin
ifeq (@BUILD_GUI@,yes)
$(OCAMLOPT) -o ../bin/dep2pict.opt -pp 'camlp4o pa_macro.cmo -DBUILD_GUI -DDATA_DIR=\"$(DATA_DIR)\" $(LOG) -DVERSION=\"$(VERSION)\"' $(DEP_OPT) ui.cmx gui.cmx main.cmx
$(OCAMLOPT) -o ../bin/dep2pict.opt -pp 'camlp4o pa_macro.cmo -DBUILD_GUI -DDATA_DIR=\"$(DATA_DIR)\" $(LOG) -DVERSION=\"$(VERSION)\"' $(DEP_OPT) dep2pict_glade.cmx global.cmx gui.cmx main.cmx
else
$(OCAMLOPT) -o ../bin/dep2pict.opt -pp 'camlp4o pa_macro.cmo -DDATA_DIR=\"$(DATA_DIR)\" $(LOG) -DVERSION=\"$(VERSION)\"' $(DEP_OPT_NOGUI) main.cmx
$(OCAMLOPT) -o ../bin/dep2pict.opt -pp 'camlp4o pa_macro.cmo -DDATA_DIR=\"$(DATA_DIR)\" $(LOG) -DVERSION=\"$(VERSION)\"' $(DEP_OPT_NOGUI) global.cmx main.cmx
endif
This diff is collapsed.
open Printf
open Log
type format = Dep | Conll | Xml | Png | Svg | Pdf
exception Found of format
let get_format file =
try
List.iter
(fun (ext, fmt) ->
if Filename.check_suffix file ext
then raise (Found fmt)
) [ ("dep", Dep); ("conll",Conll); ("xml",Xml); ("png",Png); ("svg",Svg); ("pdf",Pdf) ];
Log.fcritical "Unkwnow file extension for file \"%s\"" file
with Found fmt -> fmt
let string_of_format = function
| Dep -> "dep"
| Conll -> "conll"
| Xml -> "xml"
| Png -> "png"
| Svg -> "svg"
| Pdf -> "pdf"
let (input_file : string option ref) = ref None
let (output_file : string option ref) = ref None
let current_infos = ref ["pos"]
let (current_array : (string * string) array ref) = ref [||]
let (current_position : int option ref) = ref None (* position of the current_focus in the current_array *)
let current_source = ref ""
let modified = ref false
let debug = ref false
let get_pos () = match !current_position with
| None -> 0
| Some v -> v
(* -------------------------------------------------------------------------------- *)
let array_assoc key array =
let len = Array.length array in
let rec loop i =
if i = len
then raise Not_found
else
match array.(i) with
| (k,v) when k=key -> (i,v)
| _ -> loop (i+1)
in loop 0
(* -------------------------------------------------------------------------------- *)
let search_sentid sentid =
let (new_pos,_) = array_assoc sentid !current_array in
current_position := Some new_pos
(* -------------------------------------------------------------------------------- *)
let update_source () =
match !current_position with
| None -> ()
| Some p -> current_source := (snd !current_array.(p))
(* -------------------------------------------------------------------------------- *)
let first () =
current_position := Some 0;
update_source ()
(* -------------------------------------------------------------------------------- *)
let last () =
current_position := Some ((Array.length !current_array) - 1);
update_source ()
let has_more_than_one () = Array.length !current_array > 1
(* -------------------------------------------------------------------------------- *)
let next () =
match !current_position with
| Some p when p < (Array.length !current_array)-1 ->
current_position := Some (p+1);
update_source ()
| x -> ()
(* -------------------------------------------------------------------------------- *)
let has_next () =
match !current_position with
| Some p when p < (Array.length !current_array)-1 -> true
| _ -> false
(* -------------------------------------------------------------------------------- *)
let prev () =
match !current_position with
| Some p when p > 0 ->
current_position := Some (p-1);
update_source ()
| x -> ()
(* -------------------------------------------------------------------------------- *)
let has_prev () =
match !current_position with
| Some p when p > 0 -> true
| _ -> false
(* -------------------------------------------------------------------------------- *)
let view_label () =
match (!current_array, !current_position) with
| ([||], None) -> "No dep"
| ([|(id,_)|], Some 0) when id="00001" -> "no_id"
| ([|(id,_)|], Some 0) -> sprintf "[%s]" id
| (a, Some p) ->
let (id, _) = a.(p) in
if id = sprintf "%05d" p
then sprintf "(%d/%d) [no_id]" (p+1) (Array.length a)
else sprintf "(%d/%d) [%s]" (p+1) (Array.length a) id
| _ -> Log.critical "Inconsistent state"
(* -------------------------------------------------------------------------------- *)
let file_label () =
match !input_file with
| None -> "No file loaded"
| Some in_file -> in_file
(* -------------------------------------------------------------------------------- *)
let write file string =
let out_ch = open_out file in
fprintf out_ch "%s\n" string;
close_out out_ch
(* -------------------------------------------------------------------------------- *)
let save file =
let out_ch = open_out file in
Array.iter (fun (_,src) -> fprintf out_ch "%s\n\n" src) !current_array;
close_out out_ch
(* -------------------------------------------------------------------------------- *)
let load file =
let in_ch = open_in file in
let buff = Buffer.create 32 in
let cpt = ref 0 in
let sentid = ref None in
let current_list = ref [] in
try
while true do
match (!sentid, input_line in_ch) with
| None, "" -> ()
| Some si, "" ->
current_list := (si, Buffer.contents buff) :: !current_list;
Buffer.clear buff;
sentid := None;
| Some oc, line -> Printf.bprintf buff "%s\n" line
| None, line ->
incr cpt;
let new_sentid =
match Str.split (Str.regexp "\t") line with
| [_;_;_;_;_;"_";_;_;_;_] -> None
| [_;_;_;_;_;fs_string;_;_;_;_] ->
let fs = List.map
(fun feat_string ->
match Str.split (Str.regexp "=") feat_string with
| [name;value] -> (name,value)
| _ -> failwith (Printf.sprintf "#1 >>%S<<\n%!" feat_string)
) (Str.split (Str.regexp "|") fs_string) in
(try Some (List.assoc "sentid" fs) with Not_found -> Some (sprintf "%05d.conll" !cpt))
| _ -> Some (sprintf "%05d.conll" !cpt) in
sentid := new_sentid;
Printf.bprintf buff "%s\n" line
done
with End_of_file ->
(match !sentid with
| Some si -> current_list := (si, Buffer.contents buff) :: !current_list
| None -> ());
current_array := Array.of_list (List.rev !current_list)
open Printf
open Dep2pict
open Ui
open Log
open Rsvg
open GMain
open GdkKeysyms
(* -------------------------------------------------------------------------------- *)
let writeFile path str =
let file = open_out path in
output file str 0 (String.length str);
flush file;
close_out file
(* -------------------------------------------------------------------------------- *)
let readFile path =
let text =
let file = open_in path in
let fileSize = in_channel_length file in
let buffer = String.create fileSize in
really_input file buffer 0 fileSize;
close_in file;
buffer in text
open Dep2pict
open Dep2pict_glade
open Global
(* -------------------------------------------------------------------------------- *)
let (current_file : string option ref) = ref None
let current_infos = ref ["pos"]
let current_source = ref ""
let current_zoom = ref 100.0
(* -------------------------------------------------------------------------------- *)
let refresh_svg (ui:ui) () =
let refresh_view (ui:ui) () =
try
let svg =
if !current_source <> "" && !current_source.[0] = '1'
......@@ -39,6 +26,14 @@ let refresh_svg (ui:ui) () =
let pixbuf = Rsvg.render_from_string ~size_cb:(Rsvg.at_zoom (!current_zoom /. 100.) (!current_zoom /. 100.)) svg in
ui#svg_view#set_pixbuf pixbuf;
ui#error_view#buffer#set_text "";
let _ = ui#prev_button#misc#set_sensitive (has_prev ()) in
let _ = ui#next_button#misc#set_sensitive (has_next ()) in
let _ = ui#first_button#misc#set_sensitive (has_more_than_one ()) in
let _ = ui#last_button#misc#set_sensitive (has_more_than_one ()) in
ui#view_label#set_text (view_label ());
ui#toplevel#set_title (file_label ());
with
| Dep2pict.Parse_error msgs ->
ui#error_view#buffer#set_text
......@@ -56,8 +51,8 @@ let save_as (ui:ui) () =
let _ = sel#ok_button#connect#clicked
~callback: (fun () ->
writeFile sel#filename !current_source;
current_file := Some sel#filename;
save sel#filename;
input_file := Some sel#filename;
sel#destroy ()
) in
......@@ -66,16 +61,17 @@ let save_as (ui:ui) () =
(* -------------------------------------------------------------------------------- *)
let save (ui:ui) () =
match !current_file with
| Some file -> writeFile file !current_source
match !input_file with
| Some file -> save file
| None -> save_as (ui:ui) ()
(* -------------------------------------------------------------------------------- *)
let reload (ui:ui) () =
match !current_file with
match !input_file with
| Some filename ->
current_source := readFile filename;
refresh_svg ui ()
load filename;
update_source ();
refresh_view ui ()
| None -> ()
(* -------------------------------------------------------------------------------- *)
......@@ -101,15 +97,23 @@ let open_dep (ui:ui) () =
begin
match dialog#run () with
| `OPEN ->
current_file := dialog#filename;
input_file := dialog#filename;
reload ui ()
| `DELETE_EVENT | `CANCEL -> ()
end ;
dialog#destroy ()
(* -------------------------------------------------------------------------------- *)
let export format (ui:ui) () =
let title = sprintf "Save file as %s" format in
let convert (ui:ui) () =
let format =
match (ui#svg_radio#active, ui#png_radio#active, ui#pdf_radio#active) with
| (true,false,false) -> Svg
| (false,true,false) -> Png
| (false,false,true) -> Pdf
| _ -> Log.critical "Inconsistent format radiobuttons" in
let title = sprintf "Convert file to %s" (string_of_format format) in
let file_window = GWindow.file_selection ~title ~show:true() in
let _ = file_window#ok_button#connect#clicked
~callback:(fun () ->
......@@ -119,15 +123,15 @@ let export format (ui:ui) () =
then Dep2pict.fromConllStringToDepString !current_source
else !current_source in
match format with
| "svg" -> writeFile file_window#filename (Dep2pict.fromDepStringToSvgString dep_code)
| "png" -> ignore (Dep2pict.fromDepStringToPng dep_code file_window#filename)
| "pdf" -> ignore (Dep2pict.fromDepStringToPdf dep_code file_window#filename)
| _ -> failwith (sprintf "Unknown format %s" format)
| Svg -> write file_window#filename (Dep2pict.fromDepStringToSvgString dep_code)
| Png -> ignore (Dep2pict.fromDepStringToPng dep_code file_window#filename)
| Pdf -> ignore (Dep2pict.fromDepStringToPdf dep_code file_window#filename)
| _ -> Log.fcritical "Unsupported output format: %s" (string_of_format format)
end;
file_window#destroy ()
) in
let _ = file_window#cancel_button#connect#clicked ~callback:(file_window#destroy) in
let _ = file_window#complete ~filter:("*."^format) in
let _ = file_window#complete ~filter:("*."^(string_of_format format)) in
()
(* -------------------------------------------------------------------------------- *)
......@@ -147,46 +151,75 @@ let open_editor parent () =
~visible:true () in
ignore(editor#source#buffer#connect#changed
~callback:(fun () -> refresh_current_source (); refresh_svg parent ()));
~callback:(fun () -> refresh_current_source (); refresh_view parent ()));
editor#check_widgets ();
editor#toplevel#show ();
()
(* -------------------------------------------------------------------------------- *)
let main ?infos ?file () =
let main () =
let _ = GMain.Main.init () in
let ui = new ui () in
let () = ui#toplevel#set_title ("Dep2pict v. "^VERSION) in
let _ = ui#toplevel#connect#destroy ~callback:GMain.Main.quit in
let _ = ui#edit#connect#clicked ~callback:(open_editor ui) in
let _ = ui#reload#connect#clicked ~callback:(reload ui) in
let _ = GMisc.image ~stock:`REFRESH ~packing: ui#reload_box#pack () in
let _ = ui#save#connect#clicked ~callback:(save ui) in
let _ = GMisc.image ~stock:`SAVE ~packing: ui#save_box#pack () in
let _ = ui#save_as#connect#clicked ~callback:(save_as ui) in
let _ = ui#open_btn#connect#clicked ~callback:(open_dep ui) in
let _ = ui#reload#connect#clicked ~callback:(reload ui) in
let _ = GMisc.image ~stock:`SAVE_AS ~packing: ui#save_as_box#pack () in
let _ = ui#edit#connect#clicked ~callback:(open_editor ui) in
let _ = GMisc.image ~stock:`EDIT ~packing: ui#edit_box#pack () in
let _ = ui#open_button#connect#clicked ~callback:(open_dep ui) in
let _ = GMisc.image ~stock:`OPEN ~packing: ui#open_button_box#pack () in
let _ = ui#first_button#connect#clicked ~callback: (fun () -> first (); refresh_view ui ()) in
let _ = GMisc.image ~stock:`GOTO_FIRST ~packing: ui#first_button_box#pack () in
let _ = ui#prev_button#connect#clicked ~callback: (fun () -> prev (); refresh_view ui ()) in
let _ = GMisc.image ~stock:`GO_BACK ~packing: ui#prev_button_box#pack () in
let _ = ui#next_button#connect#clicked ~callback: (fun () -> next (); refresh_view ui ()) in
let _ = GMisc.image ~stock:`GO_FORWARD ~packing: ui#next_button_box#pack () in
let _ = ui#last_button#connect#clicked ~callback: (fun () -> last (); refresh_view ui ()) in
let _ = GMisc.image ~stock:`GOTO_LAST ~packing: ui#last_button_box#pack () in
let _ = ui#convert_button#connect#clicked ~callback:(convert ui) in
let _ = GMisc.image ~stock:`CONVERT ~packing: ui#convert_button_box#pack () in
let _ = ui#zoom#connect#value_changed
~callback:
(fun () ->
current_zoom := ui#zoom#adjustment#value;
refresh_svg ui ()
) in
~callback: (fun () -> current_zoom := ui#zoom#adjustment#value; refresh_view ui ()) in
ignore(ui#to_svg#connect#clicked ~callback:(export "svg" ui));
ignore(ui#to_png#connect#clicked ~callback:(export "png" ui));
ignore(ui#to_pdf#connect#clicked ~callback:(export "pdf" ui));
let _ = ui#toplevel#event#connect#key_press
~callback: (fun ev ->
let key = GdkEvent.Key.keyval ev in
let modif = GdkEvent.Key.state ev in
begin
match modif with
| [`CONTROL] when key = _r -> reload ui ()
| [`CONTROL] when key = _s -> open_dep ui ()
| [`CONTROL] when key = _e -> open_editor ui ()
| [`CONTROL] when key = _o -> open_dep ui ()
(match infos with
| None -> ()
| Some cst -> current_infos := cst
);
| [] when key = _Left -> prev (); refresh_view ui ()
| [] when key = _Right -> next (); refresh_view ui ()
| [`CONTROL] when key = _Left -> first (); refresh_view ui ()
| [`CONTROL] when key = _Right -> last (); refresh_view ui ()
(match file with
| None -> ()
| Some f -> current_file := Some f; reload ui ()
);
| [`CONTROL] when key = _c -> convert ui ()
| _ -> ()
end;
true) in
ui#check_widgets ();
ui#toplevel#show ();
update_source ();
refresh_view ui ();
GMain.Main.main ()
......@@ -2,11 +2,13 @@ open Printf
open Log
open Dep2pict
open Global
IFDEF BUILD_GUI THEN
open Gui
let gui ?infos ?file () = Gui.main ?infos ?file ()
let gui () = Gui.main ()
ELSE
let gui ?infos ?file () = Log.critical "Gui not available"
let gui () = Log.critical "Gui not available"
END
let version = VERSION
......@@ -38,33 +40,47 @@ let usage = String.concat "\n" [
" -i | --infos <string> select infos to display for conll input:";
" <string> is a '|' separated list of atoms from: \"lemma\", \"pos\", \"lpos\", \"all\",";
" (default=\"pos\")";
" -p | --position <int> number of the dep structure to display when input file contains sequence (default=0)";
" -p | --position <int> number of the dep structure to display when input file contains sequence";
" (incompatible with -s | --sentid, is sentid not defined the default is 0)";
" -s | --sentid <string> identifier of the sentence to display (incompatible with -p | --position)";
" -v | --version display version number ("^version^")";
" -h | --help show this help";
" -t | --tips add on_mouse_over tips in svg output (for debug purpose)";
" -d | --debug add on_mouse_over tips in svg output (for debug purpose)";
"================================================================================";
]
let input_file = ref None
let output_file = ref None
let position = ref 0
let tips = ref false
let logo = String.concat "\n" [
"[GRAPH] { word_spacing=0; opacity=50; scale=300 }";
"[WORDS] {";
" A { word=\"Dep\"; forecolor=purple; }";
" B { word=\"2\"; forecolor=orange; }";
" C { word=\"pict\"; forecolor=pink; }";
"}";
"[EDGES] {";
" A -> B { color=red; }";
" C -> B { color=blue;}";
" B -> A { bottom; color=yellow; }";
" B -> C { bottom; color=green; }";
"}";
]
let infos = ref ["pos"]
let requested_sentid = ref None
let rec parse_arg = function
| [] -> ()
| "-v"::_ | "--version"::_ -> printf "%s\n%!" version; exit 0
| "-h"::_ | "--help"::_ -> printf "%s\n%!" usage; exit 0
| "-i"::i::tail
| "--infos"::i::tail -> infos := Str.split (Str.regexp " *| *") i
| "-i"::i::tail
| "--infos"::i::tail -> current_infos := Str.split (Str.regexp " *| *") i; parse_arg tail
| "-p"::i::tail
| "--position"::i::tail -> position := (int_of_string i); parse_arg tail
| "--position"::i::tail -> current_position := Some (int_of_string i); parse_arg tail
| "-t"::tail | "--tips"::tail -> tips := true; parse_arg tail
| "-s"::s::tail
| "--sentid"::s::tail -> requested_sentid := Some s
| "-d"::tail | "--debug"::tail -> debug := true; parse_arg tail
| s::_ when s.[0] = '-' -> Log.fcritical "Unknwon option \"%s\"" s
......@@ -79,57 +95,67 @@ let rec parse_arg = function
end;
parse_arg tail
type format = Dep | Conll | Xml | Png | Svg | Pdf
exception Found of format
let get_format file =
try
List.iter
(fun (ext, fmt) ->
if Filename.check_suffix file ext
then raise (Found fmt)
) [ ("dep", Dep); ("conll",Conll); ("xml",Xml); ("png",Png); ("svg",Svg); ("pdf",Pdf) ];
Log.fcritical "Unkwnow file extension for file \"%s\"" file
with Found fmt -> fmt
let _ =
let () = parse_arg (List.tl (Array.to_list Sys.argv)) in
match (!input_file, !output_file) with
| (None, None) -> gui ~infos:(!infos) ()
| (Some file,_) when not (Sys.file_exists file) -> Log.fcritical "The input file %s doesn't exist." file
| (Some file, None) -> gui ~infos:(!infos) ~file ()
| (Some in_file, Some out_file) ->
(* check for input_file *)
match !input_file with
| None -> current_source := logo; gui ()
| Some in_file when not (Sys.file_exists in_file) -> Log.fcritical "The input file %s doesn't exist." in_file
| Some in_file -> load in_file;
(* check for focus *)
begin
try
match (get_format in_file, get_format out_file) with
| (Xml, Png) -> ignore (Dep2pict.fromXmlFileToPng in_file out_file !position)
| (Dep, Png) -> ignore (Dep2pict.fromDepFileToPng in_file out_file)
| (Conll, Png) -> ignore (Dep2pict.fromConllFileToPng ~infos:!infos in_file out_file)
| (Xml, Svg) -> ignore (Dep2pict.fromXmlFileToSvgFile ~debug:(!tips) in_file out_file !position)
| (Dep, Svg) -> ignore (Dep2pict.fromDepFileToSvgFile ~debug:(!tips) in_file out_file)
| (Conll, Svg) -> ignore (Dep2pict.fromConllFileToSvgFile ~debug:(!tips) ~infos:!infos in_file out_file)
| (Xml, Pdf) -> ignore (Dep2pict.fromXmlFileToPdf in_file out_file !position)
| (Dep, Pdf) -> ignore (Dep2pict.fromDepFileToPdf in_file out_file)
| (Conll, Pdf) -> ignore (Dep2pict.fromConllFileToPdf ~infos:!infos in_file out_file)
| (Conll, Dep) -> Dep2pict.fromConllFileToDep ~infos:!infos in_file out_file
| (Dep, Dep)
| (Xml, Dep) -> Log.fcritical "Conversion from Xml or Dep into Dep is not implemented. Please contact developers if your really need it!"
| (_, Xml) -> Log.fcritical "Conversion to Xml is not implemented. Please contact developers if your really need it!"
| (Pdf, _) -> Log.fcritical "pdf in not a valid input format"
| (Svg, _) -> Log.fcritical "svg in not a valid input format"
| (Png, _) -> Log.fcritical "png in not a valid input format"
| (_, Conll) -> Log.fcritical "conll in not a valid output format"
with
| Dep2pict.Parse_error msgs -> List.iter (fun (l,m) -> printf "Line %d: %s\n" l m) msgs; Log.fcritical "Parse error"
| Dep2pict.Id_already_in_use_ id -> Log.fcritical "Id already in use : %s" id
| Dep2pict.Unknown_index id -> Log.fcritical "Can't find index: %s" id
| Dep2pict.Loop_in_dep msg -> Log.fcritical "Loop in dependency : %s" msg
match (!current_position, !requested_sentid) with
| (None, None) when Array.length !current_array = 0 -> ()
| (None, None) -> current_position := Some 0
| (Some p, None) when p < 0 || p >= (Array.length !current_array) ->
Log.fwarning "position %d is out of bounds, set position to 0" p;
current_position := Some 0
| (Some p, None) -> current_position := Some p
| (None, Some sentid) -> (
try search_sentid sentid
with Not_found -> Log.fwarning "sentid %s cannot be found, set position to 0" sentid;
)
| (Some _, Some _) -> Log.fcritical "Options --position and --sentid are incompatible"
end;
Log.finfo "File %s generated." out_file
| (None, Some _) -> Log.bug "Some output without input!"
update_source ();
match !output_file with
| None -> gui ()
| Some out_file ->
begin
try
match (get_format in_file, get_format out_file) with
| (Xml, Png) -> ignore (Dep2pict.fromXmlFileToPng in_file out_file (get_pos ()))
| (Dep, Png) -> ignore (Dep2pict.fromDepFileToPng in_file out_file)
| (Conll, Png) -> ignore (Dep2pict.fromConllStringToPng ~infos:!current_infos !current_source out_file)
| (Xml, Svg) -> ignore (Dep2pict.fromXmlFileToSvgFile ~debug:(!debug) in_file out_file (get_pos ()))
| (Dep, Svg) -> ignore (Dep2pict.fromDepFileToSvgFile ~debug:(!debug) in_file out_file)
| (Conll, Svg) -> ignore (Dep2pict.fromConllStringToSvgFile ~infos:!current_infos !current_source out_file)
| (Xml, Pdf) -> ignore (Dep2pict.fromXmlFileToPdf in_file out_file (get_pos ()))
| (Dep, Pdf) -> ignore (Dep2pict.fromDepFileToPdf in_file out_file)
| (Conll, Pdf) -> ignore (Dep2pict.fromConllStringToPdf ~infos:!current_infos !current_source out_file)
| (Conll, Dep) -> Dep2pict.fromConllStringToDep ~infos:!current_infos !current_source out_file
| (Dep, Dep)
| (Xml, Dep) -> Log.fcritical "Conversion from Xml or Dep into Dep is not implemented. Please contact developers if your really need it!"
| (_, Xml) -> Log.fcritical "Conversion to Xml is not implemented. Please contact developers if your really need it!"
| (Pdf, _) -> Log.fcritical "pdf in not a valid input format"
| (Svg, _) -> Log.fcritical "svg in not a valid input format"
| (Png, _) -> Log.fcritical "png in not a valid input format"
| (_, Conll) -> Log.fcritical "conll in not a valid output format"
with
| Dep2pict.Parse_error msgs -> List.iter (fun (l,m) -> printf "Line %d: %s\n" l m) msgs; Log.fcritical "Parse error !!"
| Dep2pict.Id_already_in_use_ id -> Log.fcritical "Id already in use : %s" id
| Dep2pict.Unknown_index id -> Log.fcritical "Can't find index: %s" id
| Dep2pict.Loop_in_dep msg -> Log.fcritical "Loop in dependency : %s" msg
end;
Log.finfo "File %s generated." out_file
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