Commit 9f152d44 authored by Bruno Guillaume's avatar Bruno Guillaume

first release of the GTK interface as a separate executable

parents
The Grew software is developed in the Sémagramme Team (LORIA - Inria Nancy Grand-Est).
Bruno GUILLAUME is the main developer
Guillaume BONFANTE contributes to the first version of Grew
Guy PERRIER is the main developer of the linguistic resources
Other people have contributed with ideas, code, resources: Mathieu MOREY, Paul MASSON, Florian BESNARD.
# 0.45.0 (2017/10/10)
First version of the GTK interface as an independent executable: grew_gui
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
PREFIX?=/usr/local
BINDIR=$(PREFIX)/bin
DATA_DIR=$(PREFIX)/share/grew/
OCB_FLAGS = -use-ocamlfind -I src
OCB = ocamlbuild $(OCB_FLAGS)
VERSION = `cat VERSION`
all: native
native: src/grew_glade.ml datadir
$(OCB) -tag-line "true: package(libgrew)" grew_gui.native
datadir:
echo $(DATA_DIR) > DATA_DIR
install:
cp grew_gui.native $(BINDIR)/grew_gui
mkdir -p $(DATA_DIR)
cp src/grew.glade $(DATA_DIR)
uninstall:
rm -f $(BINDIR)/grew
rm -f $(DATA_DIR)/grew.glade
.PHONY: all clean byte native install uninstall
clean:
$(OCB) -clean
rm -f DATA_DIR
rm -f src/grew_glade.ml
info:
@echo "BINDIR = $(BINDIR)"
@echo "DATA_DIR = $(DATA_DIR)"
# glade file are not handle by ocamlbuild
src/grew_glade.ml : src/grew.glade
lablgladecc2 $< > $@
sed -iback 's|src/grew.glade|$(DATA_DIR)grew.glade|g' src/grew_glade.ml
rm -f src/grew_glade.mlback
PREFIX?=/Users/guillaum/.local
BINDIR=$(PREFIX)/bin
DATA_DIR=$(PREFIX)/share/grew/
OCB_FLAGS = -use-ocamlfind -I src
OCB = ocamlbuild $(OCB_FLAGS)
VERSION = `cat VERSION`
all: native
native: src/grew_glade.ml datadir
$(OCB) -tag-line "true: package(libgrew_dev)" grew_gui.native
datadir:
echo $(DATA_DIR) > DATA_DIR
install: native
cp grew_gui.native $(BINDIR)/grew_gui_dev
mkdir -p $(DATA_DIR)
cp src/*.glade $(DATA_DIR)
uninstall:
rm -f $(BINDIR)/grew
rm -f $(DATA_DIR)/grew.glade
.PHONY: all clean byte native install uninstall
clean:
$(OCB) -clean
rm -f DATA_DIR
rm -f src/*_glade.ml
info:
@echo "BINDIR = $(BINDIR)"
@echo "DATA_DIR = $(DATA_DIR)"
# glade file are not handle by ocamlbuild
src/grew_glade.ml : src/grew.glade
lablgladecc2 $< > $@
sed -iback 's|src/grew.glade|$(DATA_DIR)grew.glade|g' src/grew_glade.ml
rm -f src/grew_glade.mlback
# glade file are not handle by ocamlbuild
#src/new_glade.ml : src/new.glade
# lablgladecc2 $< > $@
# sed -iback 's|src/new.glade|$(DATA_DIR)new.glade|g' src/new_glade.ml
# rm -f src/new_glade.mlback
0.45.0
true: package(yojson, containers, str, ANSITerminal, camomile, cairo2, log, svg, conll, dep2pict, lablgtk2, lablgtk2.rsvg, lablgtk2.glade, lablwebkit)
true: bin_annot
\ No newline at end of file
open Ocamlbuild_plugin
let read file =
let in_ch = open_in file in
try
let v = input_line in_ch in
close_in in_ch;
v
with End_of_file -> failwith ("Error loading file: "^file)
let () =
dispatch begin function
| After_rules ->
let data_dir = "\""^(read "DATA_DIR")^"\""
and version = "\""^(read "VERSION")^"\"" in
let pp_src = S[A"-pp"; A("cppo -D 'VERSION "^version^"' -D 'DATA_DIR "^data_dir^"'")] in
flag ["ocaml"; "ocamldep"] & pp_src;
flag ["ocaml"; "compile"] & pp_src;
| _ -> ()
end
A GTK interface for the Grew software (see grew.loria.fr)
opam-version: "1"
maintainer: "Bruno.Guillaume@loria.fr"
build: [
["make" "PREFIX=%{prefix}%"]
]
install: [
["make" "install" "PREFIX=%{prefix}%"]
]
remove: [
["make" "uninstall" "PREFIX=%{prefix}%"]
]
depends: [
"cppo"
"lablgtk"
"lablwebkit" {= "1.8.2.1"}
"cairo2"
"ANSITerminal"
"libcaml-log"
"camomile"
"libcaml-dep2pict"
"libcaml-grew"
]
This diff is collapsed.
(***********************************************************************)
(* Grew - a Graph Rewriting tool dedicated to NLP applications *)
(* *)
(* Copyright 2011-2013 Inria, Université de Lorraine *)
(* *)
(* Webpage: http://grew.loria.fr *)
(* License: CeCILL (see LICENSE folder or "http://www.cecill.info") *)
(* Authors: see AUTHORS file *)
(***********************************************************************)
open Arg
open Log
open Libgrew
module Grew_args = struct
let grs = ref None
let fullscreen = ref false
let old_grs = ref false
let input_data = ref None
let strat = ref "main"
let features = ref None
let main_feat = ref None
let timeout = ref None
let usage =
"grew has 3 running modes:\n"^
" * GUI MODE: a Gtk interface (this is the default mode)\n"^
" * CORPUS MODE: runs rewriting on all graphs of a directory\n"^
" * DET MODE: runs a deterministic grs on all graphs of a directory\n"^
"\n"^
"Options for mode selection:"
let dump_version () =
Printf.printf "grew: %s\n" VERSION;
Printf.printf "libgrew: %s\n" (Libgrew.get_version ())
let obsolote mode = failwith (Printf.sprintf "The mode %s was removed, sorry!" mode)
let args = [
(* options for all modes *)
"-grs", String (fun s -> grs := Some s), "<grs_file> chose the grs file to load";
"-old_grs", Unit (fun () -> old_grs := true), " Use old grs parser";
"-strat", String (fun s -> strat := s), "<strat> set the module strategy to use";
"-seq", String (fun s -> strat := s), "<strat> [DEPRECATED] replaced by -strat option";
"-timeout", Float (fun f -> timeout := Some f; Rewrite.set_timeout (Some f)), "<float> set a timeout on rewriting";
"-max_depth_det", Int (fun v -> Rewrite.set_max_depth_det v), "<int> set the maximum depth of rewriting in a module in deterministric rewriting (default: 2000)";
"-max_depth_non_det", Int (fun v -> Rewrite.set_max_depth_non_det v), "<int> set the maximum depth of rewriting in a module in non-deterministric rewriting (default: 100)";
"-features", String (fun s -> features := Some (Str.split (Str.regexp "; *") s)), "<feat_name_list> set the list of feature names to printf in dep format";
"-main_feat", String (fun s -> main_feat := Some s), "<feat_name_list> set the list of feature names used in dep format to set the \"main word\"";
"-debug", Unit (fun () -> libgrew_debug_mode ()), " enable debug mode";
"-debug_loop", Unit (fun () -> Rewrite.set_debug_loop ()), " enable loop debug mode";
"-fullscreen", Unit (fun () -> fullscreen := true), " fullscreen";
"-i", String (fun file -> input_data := Some file), "<input_data> set the input data (file or directory) where to find graph files (.gr or .conll) in corpus or det mode";
]
let parse () =
Arg.parse args (fun s -> Printf.printf "%s" s) usage
end
This diff is collapsed.
(***********************************************************************)
(* Grew - a Graph Rewriting tool dedicated to NLP applications *)
(* *)
(* Copyright 2011-2013 Inria, Université de Lorraine *)
(* *)
(* Webpage: http://grew.loria.fr *)
(* License: CeCILL (see LICENSE folder or "http://www.cecill.info") *)
(* Authors: see AUTHORS file *)
(***********************************************************************)
open Log
open Grew_args
open Grew_gtk
let _ =
Printexc.record_backtrace true;
Log.set_active_levels [`INFO; `MESSAGE; `WARNING];
Log.set_write_to_log_file false;
(* parsing command line args *)
Grew_args.parse ();
Grew_gtk.init ()
This diff is collapsed.
(***********************************************************************)
(* Grew - a Graph Rewriting tool dedicated to NLP applications *)
(* *)
(* Copyright 2011-2013 Inria, Université de Lorraine *)
(* *)
(* Webpage: http://grew.loria.fr *)
(* License: CeCILL (see LICENSE folder or "http://www.cecill.info") *)
(* Authors: see AUTHORS file *)
(***********************************************************************)
open Printf
open Log
open Conll
open Libgrew
open Dep2pict
open Grew_args
(* ================================================================================ *)
module StringMap = Map.Make (String)
(* ================================================================================ *)
module String_ = struct
let contains sub str =
try let _ = Str.search_forward (Str.regexp_string sub) str 0 in true
with Not_found -> false
end
(* ================================================================================ *)
module Array_ = struct
(* dichotomic search in a sorted array *)
let dicho_find elt array =
let rec loop low high =
(if low > high then raise Not_found);
match (low+high)/2 with
| middle when array.(middle) = elt -> middle
| middle when array.(middle) < elt -> loop (middle+1) high
| middle -> loop low (middle - 1) in
loop 0 ((Array.length array) - 1)
end
(* ================================================================================ *)
module File = struct
let read file =
let in_ch = open_in file in
(* if the input file contains an UTF-8 byte order mark (EF BB BF), skip 3 bytes, else get back to 0 *)
(match input_byte in_ch with 0xEF -> seek_in in_ch 3 | _ -> seek_in in_ch 0);
let res = ref [] in
try
while true
do res := (input_line in_ch) :: !res
done; assert false
with End_of_file -> close_in in_ch; List.rev !res
exception Found of int
let get_suffix file_name =
let len = String.length file_name in
try
for i = len-1 downto 0 do
if file_name.[i] = '.'
then raise (Found i)
done;
None
with
| Found i -> Some (String.sub file_name i (len-i))
end (* module File *)
(* ================================================================================ *)
module List_ = struct
(** [index elt l] returns Some i where i is the index of the first occurence of [elt] in [l].
None is returned if [l] does not contain [elt]. *)
let index elt l =
let rec loop i = function
| [] -> None
| e::t when e=elt -> Some i
| _::t -> loop (i+1) t
in loop 0 l
let iteri fct =
let rec loop i = function
| [] -> ()
| h::t -> (fct i h); (loop (i+1) t) in
loop 0
let mapi fct =
let rec loop i = function
| [] -> []
| h::t -> let head = fct i h in head :: (loop (i+1) t)
in loop 0
let rec opt_map fct = function
| [] -> []
| h::t ->
match (fct h) with
| Some x -> x::(opt_map fct t)
| None -> opt_map fct t
let opt_mapi fct =
let rec loop i = function
| [] -> []
| h::t ->
match fct i h with
| Some x -> x::(loop (i+1) t)
| None -> loop (i+1) t
in loop 0
end (* module List_ *)
(* ================================================================================ *)
module Pdf = struct
let dot_to_file dot output_file =
let temp_file_name,out_ch = Filename.open_temp_file ~mode:[Open_rdonly;Open_wronly;Open_text] "grew_" ".dot" in
fprintf out_ch "%s" dot;
close_out out_ch;
ignore (Sys.command(sprintf "dot -Tpdf -o %s %s " output_file temp_file_name))
end (* module Pdf *)
(* ================================================================================ *)
module Svg = struct
let dot_to_tmp dot =
let temp_file_name,out_ch = Filename.open_temp_file ~mode:[Open_rdonly;Open_wronly;Open_text] "grew_" ".dot" in
fprintf out_ch "%s" dot;
close_out out_ch;
let svg_file_name = Str.global_replace (Str.regexp ".dot") ".svg" temp_file_name in
ignore (Sys.command(sprintf "dot -Tsvg -o %s %s " svg_file_name temp_file_name));
svg_file_name
let dot_to_file dot output_file =
let temp_file_name,out_ch = Filename.open_temp_file ~mode:[Open_rdonly;Open_wronly;Open_text] "grew_" ".dot" in
fprintf out_ch "%s" dot;
close_out out_ch;
ignore (Sys.command(sprintf "dot -Tsvg -o %s %s " output_file temp_file_name))
let dep_to_tmp dep =
let temp_file_name = Filename.temp_file "grew_" ".svg" in
let d2p = Dep2pict.from_dep ~dep in
let () = Dep2pict.save_svg ~filename:temp_file_name d2p in
temp_file_name
end (* module Svg *)
(* ==================================================================================================== *)
module Int =
struct
type t = int
let compare = Pervasives.compare
end
module Int_map = Map.Make (Int)
(* ==================================================================================================== *)
module Timer = struct
type t = int
let cpt = ref 0
let table = ref Int_map.empty
let create () =
incr cpt;
let current_time = Unix.times () in
table := Int_map.add !cpt current_time.Unix.tms_utime !table;
!cpt
let see timer =
let current_time = Unix.times () in
current_time.Unix.tms_utime -. (Int_map.find timer !table)
let get timer =
let current_time = Unix.times () in
let diff = current_time.Unix.tms_utime -. (Int_map.find timer !table) in
table := Int_map.remove !cpt !table;
diff
end
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