Commit 74c24d0d authored by bguillaum's avatar bguillaum
Browse files

version 2.20

- adapt to libcaml-dep2pict 2.24
- automatic refresh when the input file changes
- keep the horizontal position when reloading

git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/semagramme/dep2pict/trunk@8857 7838e531-6607-4d57-9587-6c381814729c
parent 46222e8b
VERSION = 2.19
VERSION = 2.20
INSTALL_DIR = @prefix@@bindir@
DATA_DIR = @prefix@@datarootdir@/dep2pict/
......
......@@ -90,6 +90,8 @@ type input_data =
| Conll of (string * string) array
let (input_file : string option ref) = ref None
let (input_last_modifaction_time) = ref 0.
let (output_file : string option ref) = ref None
let current_data = ref No_data
......@@ -205,18 +207,28 @@ let conll_array file =
let in_ch = open_in file in
let buff = Buffer.create 32 in
let cpt = ref 0 in
let line_num = ref 0 in
let sentid = ref None in
let current_list = ref [] in
try
while true do
incr line_num;
let line = input_line in_ch in
match (!sentid, line) 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
sentid := None
| _, s when s.[0]='#' ->
begin
match Str.bounded_split (Str.regexp "\\(# *\\)\\|\\( *: *\\)") s 2 with
| ["sentid"; si] -> sentid := Some si
| _ -> ()
end
| Some _, line -> Printf.bprintf buff "%s\n" line
| None, line ->
incr cpt;
let new_sentid =
......@@ -227,7 +239,8 @@ let conll_array file =
(fun feat_string ->
match Str.split (Str.regexp "=") feat_string with
| [name;value] -> (name,value)
| _ -> failwith (Printf.sprintf "#1 >>%S<<\n%!" feat_string)
| [name] -> (name, "_")
| _ -> Log.fcritical "[File:%s, line:%d] cannot parse feature structure: %s" file !line_num fs_string
) (Str.split (Str.regexp "|") fs_string) in
(try List.assoc "sentid" fs with Not_found -> sprintf "%05d.conll" !cpt)
| _ -> sprintf "%05d.conll" !cpt in
......@@ -249,7 +262,7 @@ let 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'
if String.length text > 0 && (text.[0] = '1' || text.[0] = '#')
then current_data := Conll (conll_array file)
else current_data := Dep (Dep2pict.from_dep text, text)
with
......
......@@ -64,7 +64,7 @@ let main () =
then Dep2pict.from_conll !current_source
else Dep2pict.from_dep !current_source in
let svg = try Dep2pict.to_svg graph with _ -> failwith "FFF" in
let svg = Dep2pict.to_svg graph in
webkit#load_html_string svg "";
webkit#set_zoom_level (!current_zoom /. 100.);
......@@ -76,25 +76,50 @@ let main () =
let _ = ui#last_button#misc#set_sensitive (has_next ()) 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
(String.concat "\n" (List.map (fun (l,m) -> sprintf "Line %d: %s" l m) msgs));
| Dep2pict.Id_already_in_use_ id -> ui#error_view#buffer#set_text ("Id already in use : "^id)
| Dep2pict.Unknown_index id -> ui#error_view#buffer#set_text ("Can't find index : "^id)
| Dep2pict.Loop_in_dep msg -> ui#error_view#buffer#set_text ("Loop in dependency : "^msg)
| Dep2pict.Conll_format msg -> ui#error_view#buffer#set_text ("Conll format : "^msg) in
| Dep2pict.Id_already_in_use_ id -> ui#error_view#buffer#set_text ("Id already in use: "^id)
| Dep2pict.Unknown_index id -> ui#error_view#buffer#set_text ("Can't find index: "^id)
| Dep2pict.Loop_in_dep msg -> ui#error_view#buffer#set_text ("Loop in dependency: "^msg)
| Dep2pict.Conll_format msg -> ui#error_view#buffer#set_text ("Conll format: "^msg) in
(* -------------------------------------------------------------------------------- *)
(* Hack to keep the horizontal position *)
let user_hpos = ref 0. in
let _ = GMain.Timeout.add ~ms:50
~callback: (fun () ->
if ui#scroll#hadjustment#value = 0. && !user_hpos > 0.
then (ui#scroll#hadjustment#set_value !user_hpos; user_hpos := 0.);
true) in
let reload () =
match !input_file with
| Some filename ->
load filename;
input_last_modifaction_time := (let stat = Unix.stat filename in stat.Unix.st_mtime);
update_source ();
user_hpos := ui#scroll#hadjustment#value; (* Hack (cf above) *)
refresh_view ()
| None -> () in
(* check if file has changed *)
let _ = GMain.Timeout.add
~ms:1000
~callback:
(fun () ->
begin
match !input_file with
| None -> ()
| Some filename ->
let stat = Unix.stat filename in
if stat.Unix.st_mtime > !input_last_modifaction_time
then reload ()
end;
true
) in
(* -------------------------------------------------------------------------------- *)
let open_dep () =
let dialog = GWindow.file_chooser_dialog
......
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