Commit 2ad4cd1f authored by bguillaum's avatar bguillaum

version 2.16.4

Fix bug in loading dep struct whitout features

git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/semagramme/dep2pict/trunk@8669 7838e531-6607-4d57-9587-6c381814729c
parent 348caed7
VERSION = 2.16.3
VERSION = 2.16.4
INSTALL_DIR = @prefix@@bindir@
DATA_DIR = @prefix@@datarootdir@/dep2pict/
......
......@@ -5,5 +5,5 @@ build: [
["make"]
["make" "install"]
]
depends: ["ANSITerminal" "libcaml-log" "cairo2" "menhir" "xml-light" "libcaml-dep2pict"]
depends: ["ANSITerminal" "libcaml-log" "cairo2" "lablgtk" "libcaml-dep2pict"]
......@@ -27,6 +27,7 @@ let (output_file : string option ref) = ref None
let current_infos = ref ["pos"]
(* elements of [current array] are pairs (sentid, code) *)
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 *)
......@@ -39,6 +40,8 @@ let get_pos () = match !current_position with
| None -> 0
| Some v -> v
let get_id () = fst (!current_array.(get_pos ()))
(* -------------------------------------------------------------------------------- *)
let array_assoc key array =
let len = Array.length array in
......@@ -72,7 +75,7 @@ let first () =
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
......@@ -128,9 +131,12 @@ let write file string =
(* -------------------------------------------------------------------------------- *)
let save file =
match !current_position with
| Some index -> !current_array.(index) <- (fst (!current_array.(index)), !current_source);
let out_ch = open_out file in
Array.iter (fun (_,src) -> fprintf out_ch "%s\n\n" src) !current_array;
close_out out_ch
Array.iter (fun (_,src) -> fprintf out_ch "%s\n" src) !current_array;
close_out out_ch;
modified := false
(* -------------------------------------------------------------------------------- *)
let load file =
......@@ -141,9 +147,10 @@ let load file =
let current_list = ref [] in
try
while true do
match (!sentid, input_line in_ch) with
let line = input_line in_ch in
match (!sentid, line) with
| None, "" -> ()
| Some si, "" ->
| Some si, "" ->
current_list := (si, Buffer.contents buff) :: !current_list;
Buffer.clear buff;
sentid := None;
......@@ -152,7 +159,7 @@ let load file =
incr cpt;
let new_sentid =
match Str.split (Str.regexp "\t") line with
| [_;_;_;_;_;"_";_;_;_;_] -> None
| [_;_;_;_;_;"_";_;_;_;_] -> sprintf "%05d.conll" !cpt
| [_;_;_;_;_;fs_string;_;_;_;_] ->
let fs = List.map
(fun feat_string ->
......@@ -160,9 +167,9 @@ let load file =
| [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;
(try List.assoc "sentid" fs with Not_found -> sprintf "%05d.conll" !cpt)
| _ -> sprintf "%05d.conll" !cpt in
sentid := Some new_sentid;
Printf.bprintf buff "%s\n" line
done
with End_of_file ->
......
......@@ -24,6 +24,24 @@ let dep_filter () =
~name:"Dependency structure"
~patterns:[ "*.dep"; "*.conll" ] ()
let check_modified continuation () =
if not !modified
then continuation ()
else
let md = GWindow.message_dialog
~message:("You have unsaved changes in "^(get_id ())^"\nDo you really want to discard your changes")
~buttons: GWindow.Buttons.ok_cancel
~modal: true
~urgency_hint:true
~message_type:`QUESTION
() in
let _ = md#connect#response
(function
| `CANCEL | `DELETE_EVENT -> md#destroy ()
| `OK -> md#destroy (); modified := false; continuation ()
) in
md#show ()
(* -------------------------------------------------------------------------------- *)
let main () =
......@@ -50,8 +68,8 @@ let main () =
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
let _ = ui#first_button#misc#set_sensitive (has_prev ()) in
let _ = ui#last_button#misc#set_sensitive (has_next ()) in
ui#view_label#set_text (view_label ());
ui#toplevel#set_title (file_label ());
......@@ -96,11 +114,13 @@ let main () =
let open_editor () =
let editor = new editor () in
editor#source#buffer#set_text !current_source;
modified := false;
ignore(editor#toplevel#connect#destroy ~callback:editor#toplevel#destroy);
ignore(editor#close_button#connect#clicked ~callback:editor#toplevel#destroy);
let refresh_current_source () =
modified := true;
current_source :=
editor#source#buffer#get_text
~start:editor#source#buffer#start_iter
......@@ -183,20 +203,24 @@ let main () =
let _ = ui#open_button#connect#clicked ~callback:open_dep in
let _ = GMisc.image ~stock:`OPEN ~packing: ui#open_button_box#pack () in
let _ = ui#first_button#connect#clicked ~callback: (fun () -> first (); refresh_view ()) in
let _ = ui#first_button#connect#clicked
~callback: (fun () -> check_modified (fun () -> first (); refresh_view ()) ()) 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 ()) in
let _ = ui#prev_button#connect#clicked
~callback: (fun () -> check_modified (fun () -> prev (); refresh_view ()) ()) 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 ()) in
let _ = ui#next_button#connect#clicked
~callback: (fun () -> check_modified (fun () -> next (); refresh_view ()) ()) 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 ()) in
let _ = ui#last_button#connect#clicked
~callback: (fun () -> check_modified (fun () -> last (); refresh_view ()) ()) in
let _ = GMisc.image ~stock:`GOTO_LAST ~packing: ui#last_button_box#pack () in
let _ = ui#convert_button#connect#clicked ~callback:convert in
let _ = GMisc.image ~stock:`CONVERT ~packing: ui#convert_button_box#pack () in
let _ = GMisc.image ~stock:`OPEN ~packing: ui#convert_button_box#pack () in
let _ = ui#zoom#connect#value_changed
~callback:
......@@ -216,10 +240,14 @@ let main () =
| [`CONTROL] when key = _e -> open_editor ()
| [`CONTROL] when key = _o -> open_dep ()
| [] when key = _Left -> prev (); refresh_view ()
| [] when key = _Right -> next (); refresh_view ()
| [`CONTROL] when key = _Left -> first (); refresh_view ()
| [`CONTROL] when key = _Right -> last (); refresh_view ()
| [] when key = _Left ->
if has_prev () then check_modified (fun () -> prev (); refresh_view ()) ()
| [] when key = _Right ->
if has_next () then check_modified (fun () -> next (); refresh_view ()) ()
| [`CONTROL] when key = _Left ->
if has_prev () then check_modified (fun () -> first (); refresh_view ()) ()
| [`CONTROL] when key = _Right ->
if has_next () then check_modified (fun () -> last (); refresh_view ()) ()
| [`CONTROL] when key = _c -> convert ()
......
......@@ -31,20 +31,20 @@ let usage = String.concat "\n" [
" * dep2pict <options> input_file output_file convert input_file into output_file" ;
" * dep2pict <options> input_file run the GUI with the given file";
" * dep2pict <options> run the GUI with an empty graph";
" * dep2pict (-h | --help) display this help";
" * dep2pict (-v | --version) display version number ("^version^")";
"";
"Formats are guessed from file extension:";
" * input formats are: dep, conll, xml";
" * output formats are: png, svg, pdf, dep";
" * accepted input formats are: dep, conll, xml";
" * accepted output formats are: png, svg, pdf, dep";
"";
"Options:";
" -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";
" (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";
" -p | --position <int> number of the dep structure to display when input file contains sequence (incompatible with -s | --sentid)";
" -d | --debug add on_mouse_over tips in svg output (for debug purpose)";
"================================================================================";
]
......
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