grew_utils.mli 9.81 KB
Newer Older
pj2m's avatar
pj2m committed
1

bguillaum's avatar
bguillaum committed
2 3 4
module StringMap : Map.S with type key = string
module StringSet : Set.S with type elt = string

pj2m's avatar
pj2m committed
5
module IntSet : Set.S with type elt = int
6
module IntMap : Map.S with type key = int
pj2m's avatar
pj2m committed
7 8


9 10
val png_file_from_dot: string -> string -> unit

bguillaum's avatar
bguillaum committed
11 12
(* ================================================================================ *)
(* [Loc] general module to describe errors location: (file name, line number in file) *)
pj2m's avatar
pj2m committed
13 14 15
module Loc: sig
  type t = string * int 

bguillaum's avatar
bguillaum committed
16 17
  val opt_set_line: int -> t option -> t option

pj2m's avatar
pj2m committed
18 19 20 21
  val to_string: t -> string
end


bguillaum's avatar
bguillaum committed
22 23 24 25
(* ================================================================================ *)
(* [File] basic functions to read/write file *)
module File: sig
  (** [write data file_name] write [data] in file named [file_name] *)
pj2m's avatar
pj2m committed
26
  val write: string -> string -> unit
bguillaum's avatar
bguillaum committed
27

bguillaum's avatar
bguillaum committed
28 29
  (** [read file_name] read the content of [file_name] line by line. 
     Blanks lines (empty or only with spaces and tabs) are ignored.
bguillaum's avatar
bguillaum committed
30
     Lines with '%' as the first char are ignored. *)
bguillaum's avatar
bguillaum committed
31
  val read: string -> string list
pj2m's avatar
pj2m committed
32 33
end

bguillaum's avatar
bguillaum committed
34 35 36 37 38 39 40 41 42

(* ================================================================================ *)
(* [Pid] describes identifier used in pattern graphs *)
module Pid : sig type t = int end

(* ================================================================================ *)
(* [Pid_map] is the map used in pattern graphs *)
module Pid_map : sig
  include Map.S with type key = int
43

bguillaum's avatar
bguillaum committed
44
  val exists: (key -> 'a -> bool) -> 'a t -> bool
bguillaum's avatar
bguillaum committed
45
end
bguillaum's avatar
bguillaum committed
46

bguillaum's avatar
bguillaum committed
47 48
(* ================================================================================ *)
(* [Gid] describes identifier used in full graphs *)
49 50 51 52 53 54 55
module Gid : sig
  type t = 
    | Old of int
    | New of int * int (* identifier for "created nodes" *)

  val to_string: t -> string
end
bguillaum's avatar
bguillaum committed
56

bguillaum's avatar
bguillaum committed
57 58
(* ================================================================================ *)
(* [Gid_map] is the map used in full graphs *)
bguillaum's avatar
bguillaum committed
59 60 61
module Gid_map : Map.S with type key = Gid.t 


bguillaum's avatar
bguillaum committed
62 63
(* ================================================================================ *)
(* [Array_] contains additional functions on the caml [array] type. *)
pj2m's avatar
pj2m committed
64
module Array_: sig
bguillaum's avatar
bguillaum committed
65 66
  (* [dicho_mem elt array] returns true iff [elt] belongs to [array].
     Warning: the array MUST be sorted and without duplicates. *)
pj2m's avatar
pj2m committed
67 68
  val dicho_mem: 'a -> 'a array -> bool

bguillaum's avatar
bguillaum committed
69 70 71
  (* [dicho_find elt array] returns the index of the position where [elt] is found in the [array].
     [Not found] is raised if [elt] is not in [array].
     Warning: the array MUST be sorted and without duplicates. *)
pj2m's avatar
pj2m committed
72
  val dicho_find: 'a -> 'a array -> int
bguillaum's avatar
bguillaum committed
73 74 75 76

  (* [dicho_find_assoc key array] returns the value associated with [key] in the assoc [array].
     [Not found] is raised if [key] is not defined in [array].
     Warning: the array MUST be sorted (with respect to the first component) and without duplicates. *)
pj2m's avatar
pj2m committed
77 78 79
  val dicho_find_assoc: 'a -> ('a*'b) array -> int
end

bguillaum's avatar
bguillaum committed
80 81
(* ================================================================================ *)
(* [List_] contains additional functions on the caml [list] type. *)
pj2m's avatar
pj2m committed
82 83 84 85
module List_: sig
  (** [rm elt list] removes the first occurence of [elt] in [list]. [Not_found] can be raised. *)
  val rm: 'a -> 'a list -> 'a list
  val opt: 'a option list -> 'a list
bguillaum's avatar
bguillaum committed
86 87 88
      
  (** [pos elt list] return [Some index] if [index] is the smallest position in the [list] equals to [elt]. None is returned if [elt] is not in the [list] *)
  val pos: 'a -> 'a list -> int option
pj2m's avatar
pj2m committed
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106

  val opt_map: ('a -> 'b option) -> 'a list -> 'b list

  val flat_map: ('a -> 'b list) -> 'a list -> 'b list
  (* remove [elt] from [list]. raise Not_found if [elt] is not in [list] *)      
  val remove: 'a -> 'a list -> 'a list

  val foldi_left: (int -> 'a -> 'b -> 'a) -> 'a -> 'b list -> 'a

  (** [disjoint_list] returns true iff the two strictly ordered list are disjoint *)
  val sort_disjoint: 'a list -> 'a list -> bool

  val to_string: ('a -> string) -> string -> 'a list -> string

  val iteri: (int -> 'a -> unit) -> 'a list -> unit

  val mapi: (int -> 'a -> 'b) -> 'a list -> 'b list

107 108
  val sort_mem: 'a -> 'a list -> bool

pj2m's avatar
pj2m committed
109 110 111 112 113 114 115 116
  (* Insert an element in a sorted list. *)
  val sort_insert: 'a -> 'a list -> 'a list

  (* Insert an element in a usort list. Return Some l or None if the element is already in the list *)
  val usort_insert: ?compare:('a -> 'a -> int) -> 'a -> 'a list -> 'a list option

  val sort_is_empty_inter: 'a list -> 'a list -> bool
  val sort_inter: 'a list -> 'a list -> 'a list
bguillaum's avatar
bguillaum committed
117
  val sort_union: 'a list -> 'a list -> 'a list
pj2m's avatar
pj2m committed
118 119 120 121 122
  val sort_disjoint_union: ?compare:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list
  val sort_include: 'a list -> 'a list -> bool
  val sort_included_diff: 'a list -> 'a list -> 'a list
  val sort_diff: 'a list -> 'a list -> 'a list

123 124 125 126 127 128
  val sort_assoc: 'a -> ('a * 'b) list -> 'b option

   (* [sort_remove_assoc k ass_list] returns the input list without the [key] element, 
      if [key] not found, the unchanged input list is returned *)
  val sort_remove_assoc: 'a -> ('a * 'b) list -> ('a * 'b) list

129
  val foldi_left: (int -> 'a -> 'b -> 'a) -> 'a -> 'b list -> 'a
pj2m's avatar
pj2m committed
130 131
end

132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
module type OrderedType =
  sig
    type t
      (** The type of the map keys. *)
    val compare : t -> t -> int
      (** A total ordering function over the keys.
          This is a two-argument function [f] such that
          [f e1 e2] is zero if the keys [e1] and [e2] are equal,
          [f e1 e2] is strictly negative if [e1] is smaller than [e2],
          and [f e1 e2] is strictly positive if [e1] is greater than [e2].
          Example: a suitable ordering function is the generic structural
          comparison function {!Pervasives.compare}. *)
  end
(** Input signature of the functor {!Map.Make}. *)


module type S =
  sig
    type key
    
    type +'a t

    val empty: 'a t

    (* an empty list returned if the key is undefined *) 
    val assoc: key -> 'a t -> 'a list

    val is_empty: 'a t -> bool

    val to_string: ('a -> string) -> 'a t -> string

    val iter: (key -> 'a -> unit) -> 'a t -> unit

    val add: key -> 'a -> 'a t -> 'a t option

    val fold: ('b -> key -> 'a -> 'b) -> 'b -> 'a t -> 'b

    (* raise Not_found if no (key,elt) *)
    val remove: key -> 'a -> 'a t -> 'a t

    (* raise Not_found if no (key,elt) *)
    val remove_key: key -> 'a t -> 'a t

    (* [mem key value t ] test if the couple (key, value) is in the massoc [t]. *)
    val mem: key -> 'a -> 'a t -> bool

    (* mem_key key t] tests is [key] is associated to at least one value in [t]. *)
    val mem_key: key -> 'a t -> bool

    exception Not_disjoint
    val disjoint_union: 'a t -> 'a t -> 'a t 

    exception Duplicate
    val merge_key: key -> key -> 'a t -> 'a t

    val exists: (key -> 'a -> bool) -> 'a t -> bool
  end


module Massoc_make (Ord : OrderedType) : S with type key = Ord.t

193 194
(* ================================================================================ *)
(* module Massoc implements multi-association data: keys are (hardly coded as) int and the same key can be
pj2m's avatar
pj2m committed
195 196 197
associated with a set of values *)
module Massoc: sig
  type 'a t
198

pj2m's avatar
pj2m committed
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
  val empty: 'a t

  (* an empty list returned if the key is undefined *) 
  val assoc: int -> 'a t -> 'a list

  val is_empty: 'a t -> bool

  val to_string: ('a -> string) -> 'a t -> string

  val iter: (int -> 'a -> unit) -> 'a t -> unit

  val add: int -> 'a -> 'a t -> 'a t option

  val fold_left: ('b -> int -> 'a -> 'b) -> 'b -> 'a t -> 'b

  (* raise Not_found if no (key,elt) *)
  val remove: int -> 'a -> 'a t -> 'a t
216

pj2m's avatar
pj2m committed
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
  (* raise Not_found if no (key,elt) *)
  val remove_key: int -> 'a t -> 'a t

  (* [mem key value t ] test if the couple (key, value) is in the massoc [t]. *)
  val mem: int -> 'a -> 'a t -> bool

  (* mem_key key t] tests is [key] is associated to at least one value in [t]. *)
  val mem_key: int -> 'a t -> bool

  exception Not_disjoint
  val disjoint_union: 'a t -> 'a t -> 'a t 

  exception Duplicate
  val merge_key: int -> int -> 'a t -> 'a t

  val exists: (int -> 'a -> bool) -> 'a t -> bool
end
    
235
module Massoc_gid : S with type key = Gid.t
bguillaum's avatar
bguillaum committed
236

pj2m's avatar
pj2m committed
237 238

module Error: sig
bguillaum's avatar
bguillaum committed
239 240 241 242
  exception Build of (string * Loc.t option)
  exception Run of (string * Loc.t option)
  exception Bug of (string * Loc.t option)

pj2m's avatar
pj2m committed
243 244
  val build: ?loc: Loc.t -> ('a, unit, string, 'b) format4 -> 'a
  val run: ?loc: Loc.t -> ('a, unit, string, 'b) format4 -> 'a
bguillaum's avatar
bguillaum committed
245
  val bug: ?loc: Loc.t -> ('a, unit, string, 'b) format4 -> 'a
pj2m's avatar
pj2m committed
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
end




module Id: sig
  type name = string
  type t = int

  type table = name array

  (* [Stop] is raised if [string] is not in [table] *)
  val build: ?loc:Loc.t -> name -> table -> t

  val build_opt: name -> table -> t option 
end

263 264 265 266
module Html: sig
  val enter: out_channel -> ?title: string -> ?header: string -> string -> unit
  val leave: out_channel -> unit
end
bguillaum's avatar
bguillaum committed
267 268 269

module Conll: sig
  type line = {
bguillaum's avatar
bguillaum committed
270 271 272 273 274 275 276 277 278 279
    line_num: int;
    num: int;
    phon: string;
    lemma: string;
    pos1: string;
    pos2: string;
    morph: (string * string) list;
    gov: int;
    dep_lab: string;
  }
280
  
bguillaum's avatar
bguillaum committed
281
  val load: string -> line list
bguillaum's avatar
bguillaum committed
282
end
283 284 285 286 287

(** module for rule that are lexically parametrized *)
module Lex_par: sig
  type t

288 289 290 291 292 293
  val empty:t 
  val append: t -> t -> t

  (** [from_lines filename nb_pattern_var nb_command_var strings] *)
  val from_lines: ?loc: Loc.t -> int -> int -> string list -> t

294 295
  (** [load ?loc local_dir_name nb_pattern_var nb_command_var file] *)
  val load: ?loc: Loc.t -> string -> int -> int -> string -> t
296 297 298 299 300 301 302

  (** [filter index atom t] returns the subset of [t] which contains only entries 
      which refers to [atom] at the [index]^th pattern_var.
      [None] is returnes if no such entry s founded.
   *)
  val filter: int -> string -> t -> t option

bguillaum's avatar
bguillaum committed
303 304 305
  (** [get_param_value index t] returns the [index]^th param_var. *)
  val get_param_value: int -> t -> string

306 307 308 309
  (** [get_command_value index t] supposes that [t] contains iny one element.
      It returns the [index]^th command_var. *)
  val get_command_value: int -> t -> string
end
bguillaum's avatar
bguillaum committed
310 311 312 313 314 315 316 317 318

module Timeout: sig
  exception Stop

  val timeout: float option ref
  val start: unit -> unit

  val check: unit -> unit
end