Commit b51cd02c authored by bguillaum's avatar bguillaum

Change interface from "instance" to "graph"

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/semagramme/libcaml-grew/trunk@8809 7838e531-6607-4d57-9587-6c381814729c
parent 472a86ad
......@@ -276,7 +276,8 @@ module Grs = struct
)
module_names
let rewrite grs sequence instance =
let rewrite grs sequence graph =
let instance = Instance.from_graph graph in
Timeout.start ();
let modules_to_apply = modules_of_sequence grs sequence in
......@@ -304,7 +305,8 @@ module Grs = struct
} in
loop instance modules_to_apply
let build_rew_display grs sequence instance =
let build_rew_display grs sequence graph =
let instance = Instance.from_graph graph in
let modules_to_apply = modules_of_sequence grs sequence in
let rec loop instance module_list =
......
......@@ -91,10 +91,10 @@ module Grs: sig
(** [build filename] returns the GRS defined in the file [filename] *)
val build: string -> t
val rewrite: t -> string -> Instance.t -> Rewrite_history.t
val rewrite: t -> string -> G_graph.t -> Rewrite_history.t
(* only externeal strucutre is returned, each edge contains a "dummy" big_step *)
val build_rew_display: t -> string -> Instance.t -> Libgrew_types.rew_display
val build_rew_display: t -> string -> G_graph.t -> Libgrew_types.rew_display
val rule_iter: (string -> Rule.t -> unit) -> t -> unit
val filter_iter: (string -> Rule.t -> unit) -> t -> unit
......
......@@ -624,15 +624,15 @@ module Html_rh = struct
let error ?main_feat ?(dot=false) ?(init_graph=true) ?header prefix msg inst_opt =
let error ?main_feat ?(dot=false) ?(init_graph=true) ?header prefix msg graph_opt =
(* remove files from previous runs *)
let _ = Unix.system (sprintf "rm -f %s*.html" prefix) in
let _ = Unix.system (sprintf "rm -f %s*.dep" prefix) in
let _ = Unix.system (sprintf "rm -f %s*.png" prefix) in
(match inst_opt, init_graph with
| (Some inst, true) when dot -> Instance.save_dot_png ?main_feat prefix inst
| (Some inst, true) -> ignore (Instance.save_dep_png ?main_feat prefix inst)
(match graph_opt, init_graph with
| (Some graph, true) when dot -> Instance.save_dot_png ?main_feat prefix (Instance.from_graph graph)
| (Some graph, true) -> ignore (Instance.save_dep_png ?main_feat prefix (Instance.from_graph graph))
| _ -> ()
);
......
......@@ -11,6 +11,7 @@
open Grew_rule
open Grew_grs
open Grew_graph
(* ================================================================================ *)
module Html_doc : sig
......@@ -45,7 +46,7 @@ module Html_rh: sig
?header:string ->
string ->
string ->
Instance.t option ->
G_graph.t option ->
unit
end (* module Html_rh *)
......
......@@ -35,6 +35,8 @@ type loc = Loc.t
let string_of_loc = Loc.to_string
let line_of_loc = Loc.to_line
type graph = G_graph.t
exception File_dont_exists of string
exception Parsing_err of string * loc option
......@@ -95,8 +97,7 @@ let load_grs file =
let to_sentence ?main_feat gr =
handle ~name:"to_sentence"
(fun () ->
let graph = gr.Instance.graph in
G_graph.to_sentence ?main_feat graph
G_graph.to_sentence ?main_feat gr
) ()
let get_sequence_names grs =
......@@ -112,36 +113,32 @@ let load_gr file =
handle ~name:"load_gr" ~file
(fun () ->
let gr_ast = Grew_parser.gr_of_file file in
Instance.from_graph (G_graph.build gr_ast)
G_graph.build gr_ast
) ()
let load_conll file =
handle ~name:"load_conll" ~file
(fun () ->
let graph = G_graph.of_conll ~loc:(Loc.file file) (Conll.load file) in
Instance.from_graph graph
G_graph.of_conll ~loc:(Loc.file file) (Conll.load file)
) ()
let of_conll file_name line_list =
handle ~name:"of_conll"
(fun () ->
let graph = G_graph.of_conll ~loc:(Loc.file file_name) (Conll.parse file_name line_list) in
Instance.from_graph graph
G_graph.of_conll ~loc:(Loc.file file_name) (Conll.parse file_name line_list)
) ()
let of_brown ?sentid brown =
handle ~name:"of_brown"
(fun () ->
let graph = G_graph.of_brown ?sentid brown in
Instance.from_graph graph
G_graph.of_brown ?sentid brown
) ()
let load_brown file =
handle ~name:"load_brown"
(fun () ->
let brown = File.load file in
let graph = G_graph.of_brown brown in
Instance.from_graph graph
G_graph.of_brown brown
) ()
let load_graph file =
......@@ -160,10 +157,10 @@ let load_graph file =
) ()
let xml_graph xml =
handle ~name:"xml_graph" (fun () -> Instance.from_graph (G_graph.of_xml xml)) ()
handle ~name:"xml_graph" (fun () -> G_graph.of_xml xml) ()
let raw_graph instance =
handle ~name:"raw_graph" (fun () -> G_graph.to_raw instance.Instance.graph) ()
let raw_graph gr =
handle ~name:"raw_graph" (fun () -> G_graph.to_raw gr) ()
let rewrite ~gr ~grs ~seq =
handle ~name:"rewrite" (fun () -> Grs.rewrite grs seq gr) ()
......@@ -187,7 +184,7 @@ let save_index ~dirname ~base_names =
let save_graph_conll filename graph =
handle ~name:"save_graph_conll" (fun () ->
let out_ch = open_out filename in
fprintf out_ch "%s" (Instance.to_conll graph);
fprintf out_ch "%s" (G_graph.to_conll graph);
close_out out_ch
) ()
......@@ -268,8 +265,6 @@ 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 graph_of_instance instance = handle ~name:"graph_of_instance" (fun () -> instance.Instance.graph) ()
let feature_names () = handle ~name:"feature_names" (fun () -> Domain.feature_names ()) ()
let to_dot_graph ?main_feat ?(deco=G_deco.empty) graph =
......
......@@ -19,6 +19,8 @@ val css_file: string
type loc = Loc.t
type graph = G_graph.t
val line_of_loc: loc -> int
val string_of_loc: loc -> string
......@@ -36,7 +38,7 @@ exception Bug of string * loc option
val set_timeout: float option -> unit
val rewrite: gr:Instance.t -> grs:Grs.t -> seq:string -> Rewrite_history.t
val rewrite: gr:G_graph.t -> grs:Grs.t -> seq:string -> Rewrite_history.t
val is_empty: Rewrite_history.t -> bool
......@@ -47,7 +49,7 @@ val num_sol: Rewrite_history.t -> int
@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:Instance.t -> grs:Grs.t -> seq:string -> rew_display
val display: gr:G_graph.t -> grs:Grs.t -> seq:string -> rew_display
val write_stat: string -> Rewrite_history.t -> unit
......@@ -68,9 +70,9 @@ val build_html_doc: ?corpus:bool -> string -> Grs.t -> unit
*)
val get_sequence_names: Grs.t -> string list
val to_sentence: ?main_feat:string -> Instance.t -> string
val to_sentence: ?main_feat:string -> G_graph.t -> string
val save_graph_conll: string -> Instance.t -> unit
val save_graph_conll: string -> G_graph.t -> unit
val save_gr: string -> Rewrite_history.t -> unit
......@@ -94,21 +96,21 @@ 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: string -> Instance.t
val load_graph: string -> G_graph.t
(** [of_conll filename line_list] *)
val of_conll: string -> (int * string) list -> Instance.t
val of_conll: string -> (int * string) list -> G_graph.t
val of_brown: ?sentid:string -> string -> Instance.t
val of_brown: ?sentid:string -> string -> G_graph.t
val xml_graph: Xml.xml -> Instance.t
val xml_graph: Xml.xml -> G_graph.t
(** [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: Instance.t ->
val raw_graph: G_graph.t ->
(string * string) list *
(string * string) list list *
(int * string * int) list
......@@ -133,7 +135,7 @@ val error_html:
?dot: bool ->
header: string ->
string ->
?init:Instance.t ->
?init:G_graph.t ->
string ->
unit
......@@ -150,8 +152,6 @@ val make_index:
val html_sentences: title:string -> string -> (bool * string * int * string) list -> unit
val graph_of_instance: Instance.t -> G_graph.t
val feature_names: unit -> string list option
val to_dot_graph : ?main_feat:string -> ?deco:deco -> graph -> string
......
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