libgrew.mli 7.49 KB
Newer Older
bguillaum's avatar
bguillaum committed
1 2 3 4 5 6 7 8 9
(**********************************************************************************)
(*    Libcaml-grew - a Graph Rewriting library 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                                                   *)
(**********************************************************************************)
pj2m's avatar
pj2m committed
10

11
open Conll
Bruno Guillaume's avatar
Bruno Guillaume committed
12
open Yojson.Basic
13

bguillaum's avatar
bguillaum committed
14
(* ==================================================================================================== *)
15
(** {2 General definitions} *)
bguillaum's avatar
bguillaum committed
16
(* ==================================================================================================== *)
17 18
module Libgrew : sig
  val get_version: unit -> string
19 20
  val set_debug_mode: bool -> unit
  val set_safe_commands: bool -> unit
21 22 23 24

  exception Error of string
  exception Bug of string
end
pj2m's avatar
pj2m committed
25

bguillaum's avatar
bguillaum committed
26
(* ==================================================================================================== *)
27
(** {2 Domain} *)
bguillaum's avatar
bguillaum committed
28 29 30 31
(* ==================================================================================================== *)
module Domain : sig
  type t
  val load: string -> t
32
  val dump: t option -> unit
bguillaum's avatar
bguillaum committed
33
  val feature_names: t -> string list
bguillaum's avatar
bguillaum committed
34 35 36 37 38 39 40 41 42
end

(* ==================================================================================================== *)
(** {2 Patterns} *)
(* ==================================================================================================== *)
module Pattern : sig
  type t

  (** [load_pattern domain filename] returns the pattern described in the file *)
bguillaum's avatar
bguillaum committed
43
  val load: ?domain:Domain.t -> string -> t
44 45 46

  (** [load_pattern domain description] returns the pattern described in the [descriprion] string *)
  val parse: ?domain:Domain.t -> string -> t
47

48
  val pid_name_list: t -> string list
49

bguillaum's avatar
bguillaum committed
50 51 52 53 54 55 56
end

(* ==================================================================================================== *)
(** {2 Matching} *)
(* ==================================================================================================== *)
module Matching: sig
  type t
57

Bruno Guillaume's avatar
Bruno Guillaume committed
58
  val to_json: Pattern.t -> Grew_graph.G_graph.t -> t -> json
bguillaum's avatar
bguillaum committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
end

(* ==================================================================================================== *)
(** {2 Deco} *)
(* ==================================================================================================== *)
module Deco: sig
  type t = Grew_graph.G_deco.t

  (** [build pattern matching] returns the deco to be used in the graphical representation.
      WARNING: the function supposes that [matching] was find with the given [pattern]! *)
  val build: Pattern.t -> Matching.t -> t
end


(* ==================================================================================================== *)
bguillaum's avatar
bguillaum committed
74
(** {2 Graph} *)
bguillaum's avatar
bguillaum committed
75 76
(* ==================================================================================================== *)
module Graph : sig
bguillaum's avatar
bguillaum committed
77

bguillaum's avatar
bguillaum committed
78 79 80 81
  type t = Grew_graph.G_graph.t
  (** 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
82
      @raise File_not_found if the file doesn't exists. *)
bguillaum's avatar
bguillaum committed
83
  val load: ?domain:Domain.t -> string -> t
bguillaum's avatar
bguillaum committed
84

bguillaum's avatar
bguillaum committed
85
  val of_gr: ?domain:Domain.t -> ?grewpy:bool -> string -> t
86

bguillaum's avatar
bguillaum committed
87
  val of_conll: ?domain:Domain.t -> Conll.t -> t
bguillaum's avatar
bguillaum committed
88

Bruno Guillaume's avatar
Bruno Guillaume committed
89
  val of_json: json -> t
Bruno Guillaume's avatar
Bruno Guillaume committed
90
  val to_json: t -> json
Bruno Guillaume's avatar
Bruno Guillaume committed
91

bguillaum's avatar
bguillaum committed
92
  val of_brown: ?domain:Domain.t -> ?sentid:string -> string -> t
bguillaum's avatar
bguillaum committed
93

94
  val of_pst: ?domain:Domain.t -> string -> t
95

96 97
  val sentence_of_pst: ?domain:Domain.t -> string -> string

98
  val to_sentence: ?main_feat:string -> ?deco:Deco.t -> t -> string
bguillaum's avatar
bguillaum committed
99

100
  val to_dot : ?main_feat:string -> ?deco:Deco.t -> t -> string
101

102
  val to_dep : ?filter: (string -> bool) -> ?main_feat:string -> ?deco:Deco.t -> t -> string
103

104
  val to_gr: t -> string
bguillaum's avatar
bguillaum committed
105

106
  val to_conll: t -> Conll.t
107

108
  val to_conll_string: t -> string
bguillaum's avatar
bguillaum committed
109

bguillaum's avatar
bguillaum committed
110
  (** [search_pattern pattern graph] returns the list of the possible matching of [pattern] in [graph] *)
bguillaum's avatar
bguillaum committed
111
  val search_pattern: ?domain:Domain.t -> Pattern.t -> t -> Matching.t list
112

113
  val node_matching: Pattern.t -> t -> Matching.t -> (string * float) list
bguillaum's avatar
bguillaum committed
114
end
bguillaum's avatar
bguillaum committed
115

116
(* OBSOLETE
bguillaum's avatar
bguillaum committed
117
(* ==================================================================================================== *)
118
(** {2 Graph Rewriting System} *)
bguillaum's avatar
bguillaum committed
119
(* ==================================================================================================== *)
120
module Old_grs: sig
121

bguillaum's avatar
bguillaum committed
122 123
  type t
  val empty: t
124

bguillaum's avatar
bguillaum committed
125 126
  (** [load filename] loads a graph rewriting system from [filename]
      @raise Parsing_err if libgrew can't parse the file
127
      @raise File_not_found if the file doesn't exists *)
bguillaum's avatar
bguillaum committed
128
  val load: string -> t
129

bguillaum's avatar
bguillaum committed
130 131
  (** [get_sequence_names t] returns the list of sequence names defined in a GRS *)
  val get_sequence_names: t -> string list
132

bguillaum's avatar
bguillaum committed
133
  val get_domain: t -> Domain.t option
134 135

  val to_json: t -> string
bguillaum's avatar
bguillaum committed
136
end
137
*)
bguillaum's avatar
bguillaum committed
138

139 140 141
(* ==================================================================================================== *)
(** {2 New Graph Rewriting System} *)
(* ==================================================================================================== *)
142
module Grs : sig
143 144 145
  type t

  val load: string -> t
Bruno Guillaume's avatar
Bruno Guillaume committed
146
  val load_old: string -> t
147 148 149 150

  val dump: t -> unit

  val domain: t -> Domain.t option
151

Bruno Guillaume's avatar
Bruno Guillaume committed
152
  val to_json: t -> json
153

154
  val get_strat_list: t -> string list
155 156
end

bguillaum's avatar
bguillaum committed
157
(* ==================================================================================================== *)
bguillaum's avatar
bguillaum committed
158
(** {2 Rewrite history} *)
bguillaum's avatar
bguillaum committed
159 160
(* ==================================================================================================== *)
module Rewrite: sig
161

bguillaum's avatar
bguillaum committed
162 163
  type display = Libgrew_types.rew_display
  type history
bguillaum's avatar
bguillaum committed
164

165
  val size: display -> int
166 167
  val set_max_depth_det: int -> unit
  val set_max_depth_non_det: int -> unit
bguillaum's avatar
bguillaum committed
168
  val set_debug_loop: unit -> unit
169

bguillaum's avatar
bguillaum committed
170 171 172 173 174
  (** [display gr grs seq] builds the [display] (datatype used by the GUI) 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 *)
175
  val old_display: gr:Graph.t -> grs:Grs.t -> strat:string -> display
176
  val display: gr:Graph.t -> grs:Grs.t -> strat:string -> display
177

178 179
  val at_least_one: grs:Grs.t -> strat:string -> bool
  val at_most_one: grs:Grs.t -> strat:string -> bool
bguillaum's avatar
bguillaum committed
180

bguillaum's avatar
bguillaum committed
181
  val set_timeout: float option -> unit
bguillaum's avatar
bguillaum committed
182

183
  val simple_rewrite: gr:Graph.t -> grs:Grs.t -> strat:string -> Graph.t list
184

bguillaum's avatar
bguillaum committed
185
  val is_empty: history -> bool
bguillaum's avatar
bguillaum committed
186

bguillaum's avatar
bguillaum committed
187
  val num_sol: history -> int
bguillaum's avatar
bguillaum committed
188

189
  val save_gr: string -> history -> unit
bguillaum's avatar
bguillaum committed
190

191
  val save_conll: string -> history -> unit
bguillaum's avatar
bguillaum committed
192

bguillaum's avatar
bguillaum committed
193 194 195
  (** [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. *)
196
  val save_full_conll: string -> history -> int
bguillaum's avatar
bguillaum committed
197

198
  val save_det_gr: string -> history -> unit
bguillaum's avatar
bguillaum committed
199

bguillaum's avatar
bguillaum committed
200 201
  val save_index: dirname:string -> base_names: string list -> unit

bguillaum's avatar
bguillaum committed
202 203
  val save_index: dirname:string -> base_names: string list -> unit

204
  val save_det_conll: ?header:string -> string -> history -> unit
bguillaum's avatar
bguillaum committed
205

206
  val det_dep_string: history -> string option
bguillaum's avatar
bguillaum committed
207

208
  val conll_dep_string: ?keep_empty_rh:bool -> history -> string option
209

210
  val save_index: dirname:string -> base_names: string array -> unit
bguillaum's avatar
bguillaum committed
211
end