Commit 2bed2c4d authored by bguillaum's avatar bguillaum

version 2.22:

* switch to libcaml-conll
* remove source edition

git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/semagramme/dep2pict/trunk@8907 7838e531-6607-4d57-9587-6c381814729c
parent 0dbeea3d
......@@ -10,15 +10,18 @@ VERSION = `cat VERSION`
all: native
native: src/dep2pict_glade.ml datadir
sed -iback 's|src/dep2pict.glade|$(DATA_DIR)dep2pict.glade|g' src/dep2pict_glade.ml
rm -f src/dep2pict_glade.mlback
$(OCB) main.native
datadir:
echo $(DATA_DIR) > DATA_DIR
install:
install: native
cp main.native $(BINDIR)/dep2pict
mkdir -p $(DATA_DIR)
cp src/dep2pict.glade $(DATA_DIR)
cp -r examples $(DATA_DIR)
uninstall:
rm -f $(BINDIR)/dep2pict
......@@ -28,7 +31,6 @@ uninstall:
clean:
$(OCB) -clean
rm -f DATA_DIR
rm -f src/dep2pict_glade.ml
info:
......@@ -38,5 +40,3 @@ info:
# glade file are not handle by ocamlbuild
src/dep2pict_glade.ml : src/dep2pict.glade
lablgladecc2 $< > $@
sed -iback 's|src/dep2pict.glade|$(DATA_DIR)dep2pict.glade|g' src/dep2pict_glade.ml
rm -f src/dep2pict_glade.mlback
true: package(str, ANSITerminal, camomile, cairo2, log, dep2pict, lablgtk2, lablgtk2.rsvg, lablgtk2.glade, lablwebkit)
true: package(str, ANSITerminal, camomile, cairo2, log, conll, dep2pict, lablgtk2, lablgtk2.rsvg, lablgtk2.glade, lablwebkit)
[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; }
}
[GRAPH] {
background=#F9F9F9;
scale=200;
edge_label_size=8;
vspace=14;
}
[WORDS] {
w0 { word = "ROOT"; bold; }
w1 { word = "Economic"; }
w2 { word = "news"; }
w3 { word = "had"; }
w4 { word = "little"; }
w5 { word = "effect"; }
w6 { word = "on"; }
w7 { word = "financial"; }
w8 { word = "market"; }
w9 { word = "."; }
}
[EDGES] {
w0 -> w3 {label = "PRED"; }
w2 -> w1 {label = "ATT"; }
w3 -> w2 {label = "SBJ"; }
w3 -> w5 {label = "OBJ"; }
w5 -> w4 {label = "ATT"; }
w5 -> w6 {label = "ATT"; }
w3 -> w9 {label = "PU"; }
w6 -> w8 {label = "PC"; }
w8 -> w7 {label = "ATT"; }
}
\ No newline at end of file
This diff is collapsed.
......@@ -2,49 +2,6 @@
<glade-interface>
<!-- interface-requires gtk+ 2.16 -->
<!-- interface-naming-policy project-wide -->
<widget class="GtkWindow" id="editor">
<property name="can_focus">False</property>
<property name="default_width">440</property>
<property name="default_height">250</property>
<child>
<widget class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow4">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">automatic</property>
<property name="vscrollbar_policy">automatic</property>
<child>
<widget class="GtkTextView" id="source">
<property name="visible">True</property>
<property name="can_focus">True</property>
</widget>
</child>
</widget>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="close_button">
<property name="label" translatable="yes">Close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</widget>
</child>
</widget>
<widget class="GtkWindow" id="ui">
<property name="can_focus">False</property>
<property name="default_width">1400</property>
......@@ -83,74 +40,6 @@
<property name="position">0</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="save">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip" translatable="yes">Save (Ctrl + s)</property>
<property name="use_underline">True</property>
<property name="image_position">top</property>
<child>
<widget class="GtkHBox" id="save_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<placeholder/>
</child>
</widget>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="save_as">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip" translatable="yes">Save as</property>
<child>
<widget class="GtkHBox" id="save_as_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<placeholder/>
</child>
</widget>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="edit">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip" translatable="yes">Edit (Ctrl + e)</property>
<child>
<widget class="GtkHBox" id="edit_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<placeholder/>
</child>
</widget>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">3</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="open_button">
<property name="visible">True</property>
......@@ -170,7 +59,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">4</property>
<property name="position">1</property>
</packing>
</child>
</widget>
......
open Printf
open Log
open Conll
open Dep2pict
module File = struct
......@@ -34,24 +35,6 @@ let critical msg = ksprintf
| false -> Log.fcritical "%s" m
) msg
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; }";
"}";
]
exception Found of int
let get_suffix file_name =
let len = String.length file_name in
......@@ -81,27 +64,29 @@ module Format = struct
| Svg -> "svg"
| Pdf -> "pdf"
| No_suff -> "no_suff"
| Unk suff -> sprintf "unkown suffix '%s'" suff
| Unk suff -> sprintf "unknown suffix '%s'" suff
end
type input_data =
| No_data
| Dep of Dep2pict.t * string
| Conll of (string * string) array
let (input_file : string option ref) = ref None
let dir = DATA_DIR
let input_file = ref (Filename.concat dir "examples/logo.dep")
let (input_last_modifaction_time) = ref 0.
let (output_file : string option ref) = ref None
let current_data = ref No_data
type input_data =
| Dep of Dep2pict.t
| Conll of (string * Conll.t) array
let current_data = ref (Conll [||])
let (current_position : int ref) = ref 0 (* position of the current_focus in the current_array *)
let current_source = ref logo (* by default use the logo code *)
let modified = ref false
let debug = ref false
let requested_sentid = ref None
(* the name of the file containing special chars (like korean chars) *)
let (special_chars : string option ref) = ref None
let get_id () =
match !current_data with
| Conll arr -> fst (arr.(!current_position))
......@@ -128,29 +113,38 @@ let search_sentid sentid =
| _ -> Log.critical "[search_sentid] can be use only with CONLL data"
(* -------------------------------------------------------------------------------- *)
let update_source () =
match (!current_data, !current_position) with
| (Conll arr, p) -> current_source := (snd arr.(p))
| (Dep (graph,text), _) -> current_source := text
| (No_data, _) -> current_source := logo
let set_position () =
match (!current_data, !current_position, !requested_sentid) with
| (Conll _, _, Some sentid) -> (
try search_sentid sentid
with Not_found ->
Log.fwarning "sentid %s cannot be found, set position to 0" sentid;
current_position := 0
)
| (Conll arr, p, None) when p < 0 || p >= (Array.length arr) ->
Log.fwarning "position %d is out of bounds, set position to 0" p;
current_position := 0
| (Conll _, p, None) -> current_position := p
| (_, _, Some _) -> Log.fcritical "Options --sentid can be used only with CONLL input"
| (_, _, None) -> ()
(* -------------------------------------------------------------------------------- *)
let first () =
match !current_data with
| Conll arr -> current_position := 0; update_source ()
| Conll arr -> current_position := 0
| _ -> Log.critical "[first] can be use only with CONLL data"
(* -------------------------------------------------------------------------------- *)
let last () =
match !current_data with
| Conll arr -> current_position :=((Array.length arr) - 1); update_source ()
| Conll arr -> current_position :=((Array.length arr) - 1)
| _ -> Log.critical "[last] can be use only with CONLL data"
(* -------------------------------------------------------------------------------- *)
let next () =
match (!current_data, !current_position) with
| (Conll arr, p) when p < (Array.length arr) - 1 ->
current_position := p+1; update_source ()
current_position := p+1
| _ -> Log.critical "[next] can be use only with CONLL data"
(* -------------------------------------------------------------------------------- *)
......@@ -163,7 +157,7 @@ let has_next () =
let prev () =
match (!current_data, !current_position) with
| (Conll _, p) when p > 0 ->
current_position := p-1; update_source ()
current_position := p-1
| _ -> Log.critical "[prev] can be use only with CONLL data"
(* -------------------------------------------------------------------------------- *)
......@@ -184,87 +178,18 @@ let view_label () =
else sprintf "(%d/%d) [%s]" (p+1) (Array.length a) id
| _ -> "no_id"
(* -------------------------------------------------------------------------------- *)
let file_label () =
match !input_file with
| None -> "No file loaded"
| Some in_file -> in_file
(* -------------------------------------------------------------------------------- *)
let save file =
match (!current_data, !current_position) with
| (Conll arr, index) ->
arr.(index) <- (fst (arr.(index)), !current_source);
let out_ch = open_out file in
Array.iter (fun (_,src) -> fprintf out_ch "%s\n" src) arr;
close_out out_ch;
modified := false
| _ -> Log.critical "[Global.save] can be use only with CONLL data"
(* -------------------------------------------------------------------------------- *)
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
| _, 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 =
match Str.split (Str.regexp "\t") line with
| [_;_;_;_;_;"_";_;_;_;_] -> sprintf "%05d.conll" !cpt
| [_;_;_;_;_;fs_string;_;_;_;_] ->
let fs = List.map
(fun feat_string ->
match Str.split (Str.regexp "=") feat_string with
| [name;value] -> (name,value)
| [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
sentid := Some new_sentid;
Printf.bprintf buff "%s\n" line
done; assert false
with End_of_file ->
(match !sentid with
| Some si -> current_list := (si, Buffer.contents buff) :: !current_list
| None -> ());
Array.of_list (List.rev !current_list)
(* -------------------------------------------------------------------------------- *)
let load file =
try
match Format.get file with
| Format.Dep -> let dep = File.read file in current_data := Dep (Dep2pict.from_dep dep, dep)
| Format.Conll -> current_data := Conll (conll_array file)
| Format.Dep -> let dep = File.read file in current_data := Dep (Dep2pict.from_dep dep)
| Format.Conll -> current_data := Conll (Conll_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_array file)
else current_data := Dep (Dep2pict.from_dep text, text)
then current_data := Conll (Conll_corpus.load file)
else current_data := Dep (Dep2pict.from_dep text)
with
| Dep2pict.Parse_error msgs -> List.iter (fun (l,m) -> printf "Line %d: %s\n" l m) msgs; critical "Parse error !!"
| Dep2pict.Id_already_in_use_ id -> critical "Id already in use : %s" id
......
open Printf
open Log
open Rsvg
open GMain
open GdkKeysyms
open Conll
open Dep2pict
open Dep2pict_glade
......@@ -24,25 +25,6 @@ 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 () =
......@@ -59,11 +41,10 @@ let main () =
(* -------------------------------------------------------------------------------- *)
let refresh_view () =
try
let graph =
if !current_source <> "" && !current_source.[0] = '1'
then Dep2pict.from_conll !current_source
else Dep2pict.from_dep !current_source in
let graph = match (!current_data, !current_position) with
| (Conll arr, p) -> Dep2pict.from_conll (snd arr.(p))
| (Dep graph, _) -> graph in
let svg = Dep2pict.to_svg graph in
webkit#load_html_string svg "";
webkit#set_zoom_level (!current_zoom /. 100.);
......@@ -75,7 +56,7 @@ let main () =
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 ());
ui#toplevel#set_title !input_file;
with
| Dep2pict.Parse_error msgs ->
ui#error_view#buffer#set_text
......@@ -89,27 +70,23 @@ let main () =
(* Hack to keep the horizontal position *)
let user_hpos = ref 0. in
let _ = GMain.Timeout.add ~ms:50
~callback: (fun () ->
~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
load !input_file;
input_last_modifaction_time := (let stat = Unix.stat !input_file in stat.Unix.st_mtime);
user_hpos := ui#scroll#hadjustment#value; (* Hack (cf above) *)
refresh_view () in
(* check if file has changed *)
let _ = GMain.Timeout.add
~ms:1000
~callback:
(fun () ->
begin
(* begin
match !input_file with
| None -> ()
| Some filename ->
......@@ -117,7 +94,7 @@ let main () =
if stat.Unix.st_mtime > !input_last_modifaction_time
then reload ()
end;
true
*) true
) in
(* -------------------------------------------------------------------------------- *)
......@@ -133,58 +110,13 @@ let main () =
begin
match dialog#run () with
| `OPEN ->
input_file := dialog#filename;
reload ()
(match dialog#filename with
| Some f -> input_file := f; reload ();
| None -> ())
| `DELETE_EVENT | `CANCEL -> ()
end ;
dialog#destroy () in
(* -------------------------------------------------------------------------------- *)
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
~stop:editor#source#buffer#end_iter
~slice:true
~visible:true () in
ignore(editor#source#buffer#connect#changed
~callback:(fun () -> refresh_current_source (); refresh_view ()));
editor#check_widgets ();
editor#toplevel#show ();
() in
(* -------------------------------------------------------------------------------- *)
let save_as () =
let sel = GWindow.file_selection ~title:"Save file" ~show:true() in
(* TODO deal with dep|conll... sel#complete ~filter:"*.conll"; *)
let _ = sel#ok_button#connect#clicked
~callback: (fun () ->
save sel#filename;
input_file := Some sel#filename;
sel#destroy ()
) in
let _ = sel#cancel_button#connect#clicked ~callback:(sel#destroy) in
() in
(* -------------------------------------------------------------------------------- *)
let save () =
match !input_file with
| Some file -> save file
| None -> save_as () in
(* -------------------------------------------------------------------------------- *)
let convert () =
......@@ -200,10 +132,9 @@ let main () =
let _ = file_window#ok_button#connect#clicked
~callback:(fun () ->
begin
let graph =
if String.length !current_source > 0 && !current_source.[0] = '1'
then Dep2pict.from_conll !current_source
else Dep2pict.from_dep !current_source in
let graph = match (!current_data, !current_position) with
| (Conll arr, p) -> Dep2pict.from_conll (snd arr.(p))
| (Dep graph, _) -> graph in
match format with
| Format.Svg -> Dep2pict.save_svg ~filename:file_window#filename graph
......@@ -221,32 +152,23 @@ let main () =
let _ = ui#reload#connect#clicked ~callback:reload in
let _ = GMisc.image ~stock:`REFRESH ~packing: ui#reload_box#pack () in
let _ = ui#save#connect#clicked ~callback:save in
let _ = GMisc.image ~stock:`SAVE ~packing:ui#save_box#pack () in
let _ = ui#save_as#connect#clicked ~callback:save_as in
let _ = GMisc.image ~stock:`SAVE_AS ~packing: ui#save_as_box#pack () in
let _ = ui#edit#connect#clicked ~callback:open_editor in
let _ = GMisc.image ~stock:`EDIT ~packing: ui#edit_box#pack () in
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 () -> check_modified (fun () -> first (); refresh_view ()) ()) in
~callback: (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 () -> check_modified (fun () -> prev (); refresh_view ()) ()) in
~callback: (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 () -> check_modified (fun () -> next (); refresh_view ()) ()) in
~callback: (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 () -> check_modified (fun () -> last (); refresh_view ()) ()) in
~callback: (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
......@@ -266,18 +188,16 @@ let main () =
begin
match modif with
| [`CONTROL] when key = _r -> reload ()
| [`CONTROL] when key = _s -> save ()
| [`CONTROL] when key = _e -> open_editor ()
| [`CONTROL] when key = _o -> open_dep ()
| [] when key = _Left ->
if has_prev () then check_modified (fun () -> prev (); refresh_view ()) ()
if has_prev () then prev (); refresh_view ()
| [] when key = _Right ->
if has_next () then check_modified (fun () -> next (); refresh_view ()) ()
if has_next () then next (); refresh_view ()
| [`CONTROL] when key = _Left ->
if has_prev () then check_modified (fun () -> first (); refresh_view ()) ()
if has_prev () then first (); refresh_view ()
| [`CONTROL] when key = _Right ->
if has_next () then check_modified (fun () -> last (); refresh_view ()) ()
if has_next () then last (); refresh_view ()
| [`CONTROL] when key = _c -> convert ()
......@@ -287,7 +207,6 @@ let main () =
ui#check_widgets ();
ui#toplevel#show ();
update_source ();
refresh_view ();
reload ();
GMain.Main.main ()
open Printf
open Log
open Conll
open Dep2pict
open Global
......@@ -42,12 +43,7 @@ let usage = String.concat "\n" [
]
let requested_sentid = ref None
(* the name of the file containing special chars (like korean chars) *)
let special_chars = ref None
let first = ref true
let rec parse_arg = function
| [] -> ()
| "-v"::_ | "--version"::_ -> printf "%s\n%!" version; exit 0
......@@ -69,9 +65,9 @@ let rec parse_arg = function
| anon :: tail ->
begin
match !input_file with
| None -> input_file := Some anon
| Some _ ->
if !first
then (input_file := anon; first := false)
else
match !output_file with