Commit d4f52a98 authored by bguillaum's avatar bguillaum

organize libgrew.ml*

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/semagramme/libcaml-grew/trunk@8835 7838e531-6607-4d57-9587-6c381814729c
parent c550e7b5
......@@ -20,28 +20,21 @@ ENDIF
open Grew_fs
open Grew_base
open Grew_types
open Grew_graph
open Grew_rule
open Grew_grs
open Grew_loader
open Grew_html
let css_file = Filename.concat DATA_DIR "style.css"
let empty_grs = Grs.empty
let set_timeout t = Timeout.timeout := t
(* -------------------------------------------------------------------------------- *)
(** {2 Location} *)
type loc = Loc.t
let string_of_loc = Loc.to_string
let line_of_loc = Loc.to_line
type graph = G_graph.t
(* -------------------------------------------------------------------------------- *)
(** {2 Exceptions} *)
exception File_dont_exists of string
exception Parsing_err of string * loc option
exception Build of string * loc option
exception Run of string * loc option
......@@ -63,12 +56,27 @@ let handle ?(name="") ?(file="No file defined") fct () =
| exc -> raise (Bug (sprintf "[Libgrew.%s] UNCATCHED EXCEPTION: %s" name (Printexc.to_string exc), None))
let is_empty rh =
handle ~name:"is_empty" (fun () -> Rewrite_history.is_empty rh) ()
let num_sol rh =
handle ~name:"num_sol" (fun () -> Rewrite_history.num_sol rh) ()
(* -------------------------------------------------------------------------------- *)
(** {2 Graph Rewriting System} *)
type grs = Grs.t
let empty_grs = Grs.empty
let load_grs file =
handle ~name:"load_grs" ~file
(fun () ->
if not (Sys.file_exists file)
then raise (File_dont_exists file)
else Grs.build file
) ()
let get_sequence_names grs =
handle ~name:"get_sequence_names"
(fun () ->
Grs.sequence_names grs
) ()
IFDEF DEP2PICT THEN
let build_html_doc ?(corpus=false) dir grs =
......@@ -90,25 +98,11 @@ let build_html_doc ?(corpus=false) dir grs =
handle ~name:"build_doc [without Dep2pict]" (fun () -> Html_doc.build ~corpus ~dep:false dir grs) ()
END
let load_grs file =
handle ~name:"load_grs" ~file
(fun () ->
if not (Sys.file_exists file)
then raise (File_dont_exists file)
else Grs.build file
) ()
let to_sentence ?main_feat gr =
handle ~name:"to_sentence"
(fun () ->
G_graph.to_sentence ?main_feat gr
) ()
let feature_names grs = handle ~name:"feature_names" (fun () -> Domain.feature_names (Grs.get_domain grs)) ()
let get_sequence_names grs =
handle ~name:"get_sequence_names"
(fun () ->
Grs.sequence_names grs
) ()
(* -------------------------------------------------------------------------------- *)
(** {2 Graph} *)
type graph = G_graph.t
let load_gr grs file =
if not (Sys.file_exists file)
......@@ -126,18 +120,6 @@ let load_conll grs file =
G_graph.of_conll ~loc:(Loc.file file) (Grs.get_domain grs) (Grs.get_label_domain grs) (Conll.load file)
) ()
let of_conll grs file_name line_list =
handle ~name:"of_conll"
(fun () ->
G_graph.of_conll ~loc:(Loc.file file_name) (Grs.get_domain grs) (Grs.get_label_domain grs) (Conll.parse file_name line_list)
) ()
let of_brown grs ?sentid brown =
handle ~name:"of_brown"
(fun () ->
G_graph.of_brown (Grs.get_domain grs) (Grs.get_label_domain grs) ?sentid brown
) ()
let load_brown grs file =
handle ~name:"load_brown"
(fun () ->
......@@ -160,14 +142,72 @@ let load_graph grs file =
loop [load_gr; load_conll; load_brown]
) ()
let of_conll grs file_name line_list =
handle ~name:"of_conll"
(fun () ->
G_graph.of_conll ~loc:(Loc.file file_name) (Grs.get_domain grs) (Grs.get_label_domain grs) (Conll.parse file_name line_list)
) ()
let of_brown grs ?sentid brown =
handle ~name:"of_brown"
(fun () ->
G_graph.of_brown (Grs.get_domain grs) (Grs.get_label_domain grs) ?sentid brown
) ()
let to_dot_graph grs ?main_feat ?(deco=G_deco.empty) graph =
handle ~name:"to_dot_graph" (fun () -> G_graph.to_dot (Grs.get_label_domain grs) ?main_feat graph ~deco) ()
let to_dep_graph grs ?filter ?main_feat ?(deco=G_deco.empty) graph =
handle ~name:"to_dep_graph" (fun () -> G_graph.to_dep (Grs.get_label_domain grs) ?filter ?main_feat ~deco graph) ()
let to_gr_graph grs graph =
handle ~name:"to_gr_graph" (fun () -> G_graph.to_gr (Grs.get_label_domain grs) graph) ()
let to_conll_graph grs graph =
handle ~name:"to_conll_graph" (fun () -> G_graph.to_conll (Grs.get_label_domain grs) graph) ()
let to_sentence ?main_feat gr =
handle ~name:"to_sentence"
(fun () ->
G_graph.to_sentence ?main_feat gr
) ()
let save_graph_conll grs filename graph =
handle ~name:"save_graph_conll" (fun () ->
let out_ch = open_out filename in
fprintf out_ch "%s" (G_graph.to_conll (Grs.get_label_domain grs) graph);
close_out out_ch
) ()
let raw_graph grs gr =
handle ~name:"raw_graph" (fun () -> G_graph.to_raw (Grs.get_label_domain grs) gr) ()
(* -------------------------------------------------------------------------------- *)
(** {2 rew_display: data for the GUI } *)
let display ~gr ~grs ~seq =
handle ~name:"display" (fun () -> Grs.build_rew_display grs seq gr) ()
(* -------------------------------------------------------------------------------- *)
(** {2 Rewrite} *)
type rewrite_history = Rewrite_history.t
let set_timeout t = Timeout.timeout := t
let rewrite ~gr ~grs ~seq =
handle ~name:"rewrite" (fun () -> Grs.rewrite grs seq gr) ()
let display ~gr ~grs ~seq =
handle ~name:"display" (fun () -> Grs.build_rew_display grs seq gr) ()
let is_empty rh =
handle ~name:"is_empty" (fun () -> Rewrite_history.is_empty rh) ()
let num_sol rh =
handle ~name:"num_sol" (fun () -> Rewrite_history.num_sol rh) ()
let write_stat filename rew_hist =
handle ~name:"write_stat" (fun () -> Gr_stat.save filename (Gr_stat.from_rew_history rew_hist)) ()
......@@ -182,12 +222,6 @@ let save_index ~dirname ~base_names =
close_out out_ch
) ()
let save_graph_conll grs filename graph =
handle ~name:"save_graph_conll" (fun () ->
let out_ch = open_out filename in
fprintf out_ch "%s" (G_graph.to_conll (Grs.get_label_domain grs) graph);
close_out out_ch
) ()
let save_gr grs base rew_hist =
handle ~name:"save_gr" (fun () -> Rewrite_history.save_gr (Grs.get_label_domain grs) base rew_hist) ()
......@@ -268,19 +302,10 @@ let make_index ~title ~grs_file ~html ~grs ~seq ~input_dir ~output_dir ~base_nam
let html_sentences ~title = handle ~name:"html_sentences" (fun () -> Html_sentences.build ~title) ()
let feature_names grs = handle ~name:"feature_names" (fun () -> Domain.feature_names (Grs.get_domain grs)) ()
let to_dot_graph grs ?main_feat ?(deco=G_deco.empty) graph =
handle ~name:"to_dot_graph" (fun () -> G_graph.to_dot (Grs.get_label_domain grs) ?main_feat graph ~deco) ()
let to_dep_graph grs ?filter ?main_feat ?(deco=G_deco.empty) graph =
handle ~name:"to_dep_graph" (fun () -> G_graph.to_dep (Grs.get_label_domain grs) ?filter ?main_feat ~deco graph) ()
let to_gr_graph grs graph =
handle ~name:"to_gr_graph" (fun () -> G_graph.to_gr (Grs.get_label_domain grs) graph) ()
let to_conll_graph grs graph =
handle ~name:"to_conll_graph" (fun () -> G_graph.to_conll (Grs.get_label_domain grs) graph) ()
(* -------------------------------------------------------------------------------- *)
(** {2 Patterns} *)
type pattern = Rule.pattern
type matching = Rule.matching
......
......@@ -16,15 +16,15 @@ open Grew_graph
open Grew_rule
open Grew_grs
val css_file: string
type loc = Loc.t
type graph = G_graph.t
(* -------------------------------------------------------------------------------- *)
(** {2 Location} *)
type loc
val line_of_loc: loc -> int
val string_of_loc: loc -> string
(* -------------------------------------------------------------------------------- *)
(** {2 Exceptions} *)
exception File_dont_exists of string
exception Parsing_err of string * loc option
......@@ -37,88 +37,107 @@ exception Run of string * loc option
exception Bug of string * loc option
val set_timeout: float option -> unit
val rewrite: gr:G_graph.t -> grs:Grs.t -> seq:string -> Rewrite_history.t
val is_empty: Rewrite_history.t -> bool
val num_sol: Rewrite_history.t -> int
(** display a gr with a grs in a rew_display
@param gr the grapth to rewrite
@param grs the graph rewriting system
@param seq the name of the sequence to apply
@return a structure {b {i easily}} displayable *)
val display: gr:G_graph.t -> grs:Grs.t -> seq:string -> rew_display
(* -------------------------------------------------------------------------------- *)
(** {2 Graph Rewriting System} *)
type grs
val empty_grs: grs
val write_stat: string -> Rewrite_history.t -> unit
val empty_grs: Grs.t
(** get a graph rewriting system from a file
@return a graph rewriting system
@raise Parsing_err if libgrew can't parse the file
@raise File_dont_exists if the file doesn't exists
*)
val load_grs: string -> Grs.t
(** [build_html_doc directory grs ] *)
val build_html_doc: ?corpus:bool -> string -> Grs.t -> unit
(** give the list of sequence names defined in a GRS
@return a string list
*)
val get_sequence_names: Grs.t -> string list
val to_sentence: ?main_feat:string -> G_graph.t -> string
val save_graph_conll: Grs.t -> string -> G_graph.t -> unit
val save_gr: Grs.t -> string -> Rewrite_history.t -> unit
val save_conll: Grs.t -> string -> Rewrite_history.t -> unit
(** [save_full_conll base_name rh] saves one conll_file for each normal form defined in [rh].
Output files are named according to [base_name] and a secondary index after "__".
The number of conll file produced is returned. *)
val save_full_conll: Grs.t -> string -> Rewrite_history.t -> int
(** [load_grs filename] loads a graph rewriting system from [filename]
@raise Parsing_err if libgrew can't parse the file
@raise File_dont_exists if the file doesn't exists *)
val load_grs: string -> grs
val save_det_gr: Grs.t -> string -> Rewrite_history.t -> unit
(** [get_sequence_names grs] returns the list of sequence names defined in a GRS *)
val get_sequence_names: grs -> string list
val save_det_conll: Grs.t -> ?header:string -> string -> Rewrite_history.t -> unit
(** [build_html_doc ?corpus directory grs]
@[corpus] is a flag (default is [false]) for complete html doc with corpus sentence. *)
val build_html_doc: ?corpus:bool -> string -> grs -> unit
val det_dep_string: Grs.t -> Rewrite_history.t -> string option
val feature_names: grs -> string list option
val conll_dep_string: Grs.t -> ?keep_empty_rh:bool -> Rewrite_history.t -> string option
(* -------------------------------------------------------------------------------- *)
(** {2 Graph} *)
type graph
(** get a graph from a file either in 'gr' or 'conll' format.
File extension should be '.gr' or '.conll'.
@raise Parsing_err if libgrew can't parse the file
@raise File_dont_exists if the file doesn't exists. *)
val load_graph: Grs.t -> string -> G_graph.t
val load_graph: grs -> string -> graph
(** [of_conll filename line_list] *)
val of_conll: Grs.t -> string -> (int * string) list -> G_graph.t
val of_conll: grs -> string -> (int * string) list -> graph
val of_brown: Grs.t -> ?sentid:string -> string -> G_graph.t
val of_brown: grs -> ?sentid:string -> string -> graph
val to_sentence: ?main_feat:string -> graph -> string
(** [raw_graph instance] returns all graph information with a triple of elementary caml types:
- the meta data
- the list of node (node is a list of feature (feature is string * string))
- the list of edge (src, label, tar) where src and tar refers to the position in the node list
*)
val raw_graph: Grs.t -> G_graph.t ->
val raw_graph: grs -> graph ->
(string * string) list *
(string * string) list list *
(int * string * int) list
val to_dot_graph : grs -> ?main_feat:string -> ?deco:deco -> graph -> string
val to_dep_graph : grs -> ?filter: string list -> ?main_feat:string -> ?deco:deco -> graph -> string
val to_gr_graph: grs -> graph -> string
val to_conll_graph: grs -> graph -> string
(* -------------------------------------------------------------------------------- *)
(** {2 rew_display: data for the GUI } *)
(** [display gr grs seq] builds the [rew_display] given by
the rewriting of graph [gr] with the sequence [seq] of [grs].
@param gr the grapth to rewrite
@param grs the graph rewriting system
@param seq the name of the sequence to apply *)
val display: gr:graph -> grs:grs -> seq:string -> rew_display
(* -------------------------------------------------------------------------------- *)
(** {2 Rewrite history} *)
type rewrite_history
val set_timeout: float option -> unit
val rewrite: gr:graph -> grs:grs -> seq:string -> rewrite_history
val is_empty: rewrite_history -> bool
val num_sol: rewrite_history -> int
val write_stat: string -> rewrite_history -> unit
val save_gr: grs -> string -> rewrite_history -> unit
val save_conll: grs -> string -> rewrite_history -> unit
(** [save_full_conll base_name rh] saves one conll_file for each normal form defined in [rh].
Output files are named according to [base_name] and a secondary index after "__".
The number of conll file produced is returned. *)
val save_full_conll: grs -> string -> rewrite_history -> int
val save_det_gr: grs -> string -> rewrite_history -> unit
val save_det_conll: grs -> ?header:string -> string -> rewrite_history -> unit
val det_dep_string: grs -> rewrite_history -> string option
val conll_dep_string: grs -> ?keep_empty_rh:bool -> rewrite_history -> string option
val save_index: dirname:string -> base_names: string list -> unit
val write_annot: Grs.t -> title:string -> string -> string -> (string * Rewrite_history.t) list -> unit
val write_annot: grs -> title:string -> string -> string -> (string * rewrite_history) list -> unit
val write_html:
Grs.t ->
grs ->
?no_init: bool ->
?out_gr: bool ->
?filter: string list ->
......@@ -126,16 +145,18 @@ val write_html:
?dot: bool ->
header: string ->
?graph_file: string ->
Rewrite_history.t -> string -> unit
rewrite_history ->
string ->
unit
val error_html:
Grs.t ->
grs ->
?no_init:bool ->
?main_feat:string ->
?dot: bool ->
header: string ->
string ->
?init:G_graph.t ->
?init:graph ->
string ->
unit
......@@ -143,7 +164,7 @@ val make_index:
title: string ->
grs_file: string ->
html: bool ->
grs: Grs.t ->
grs: grs ->
seq: string ->
input_dir: string ->
output_dir: string ->
......@@ -152,22 +173,18 @@ val make_index:
val html_sentences: title:string -> string -> (bool * string * int * string) list -> unit
val feature_names: Grs.t -> string list option
val to_dot_graph : Grs.t -> ?main_feat:string -> ?deco:deco -> graph -> string
val to_dep_graph : Grs.t -> ?filter: string list -> ?main_feat:string -> ?deco:deco -> graph -> string
val to_gr_graph: Grs.t -> graph -> string
val to_conll_graph: Grs.t -> graph -> string
(* -------------------------------------------------------------------------------- *)
(** {2 Patterns} *)
(* type and function added for the grep mode of grew *)
type pattern
type matching
(** [load_pattern filename] returns the pattern describer in the fuile *)
val load_pattern: Grs.t -> string -> pattern
val load_pattern: grs -> string -> pattern
(** [match_in_graph patern graph] returns the list of the possible matching og [pattern] in [graph] *)
val match_in_graph: Grs.t -> pattern -> graph -> matching list
val match_in_graph: grs -> pattern -> graph -> matching list
(** [match_deco pattern matching] returns the deco to be used in the graphical representation.
WARNING: the function supposes that [matching] was find with the given [pattern]! *)
......
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