grew_types.mli 7.46 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
(**********************************************************************************)
(*    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                                                   *)
(**********************************************************************************)

open Grew_base

type feature_name = string (* cat, num, ... *)
type feature_atom = string (* V, N, inf, ... *)
type feature_value = string (* V, 4, "free text", ... *)
type suffix = string

bguillaum's avatar
bguillaum committed
18 19 20 21 22 23 24

type value = String of string | Float of float

val string_of_value : value -> string

val conll_string_of_value : value -> string

25 26
type disjunction = value list

27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
(* ================================================================================ *)
(* [Pid] describes identifier used in pattern graphs *)
module Pid : sig
  type t = Pos of int | Neg of int
  val compare: t -> t -> int
  val to_id: t -> string
  val to_string: t -> string
end (* module Pid *)

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

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

(* ================================================================================ *)
(* [Pid_set] *)
module Pid_set : Set.S with type elt = Pid.t

(* ================================================================================ *)
(* [Gid] describes identifier used in full graphs *)
module Gid : sig
  type t =
    | Old of int
    | New of (int * int) (* identifier for "created nodes" *)
    | Act of (int * string)  (* identifier for "activated nodes" *)

  val compare: t -> t -> int

  val to_string: t -> string
end (* module Gid *)

(* ================================================================================ *)
(* [Gid_map] is the map used in full graphs *)
module Gid_map : Map.S with type key = Gid.t

(* ================================================================================ *)
module Massoc_gid : S with type key = Gid.t

(* ================================================================================ *)
module Massoc_pid : S with type key = Pid.t

(* ================================================================================ *)
bguillaum's avatar
bguillaum committed
72 73 74 75
module Label_domain : sig
  type t
  val empty : t

76 77 78
  (* [decl] is the type for a label declaration: the name and a list of display options *)
  type decl = string * string list

bguillaum's avatar
bguillaum committed
79 80 81 82
  val build: decl list -> t
end

(* ================================================================================ *)
83 84 85 86 87
module Feature_domain: sig
  type feature_spec =
    | Closed of feature_name * feature_atom list (* cat:V,N *)
    | Open of feature_name (* phon, lemma, ... *)
    | Num of feature_name (* position *)
bguillaum's avatar
bguillaum committed
88

89 90
  type t

91
  val empty: t
92

93
  val build: feature_spec list -> t
94

95 96
  (** [sub domain fn1 fn2] returns [true] iff the domain of [fn1] is a subset if the domain of [fn2]. *)
  val sub:  t -> feature_name -> feature_name -> bool
97

98
  val build_closed: feature_name -> feature_atom list -> feature_spec
99

100
end (* module Feature_domain *)
101

102 103 104
(* ================================================================================ *)
module Domain : sig
  type t
105

106
  val build: Label_domain.t -> Feature_domain.t -> t
107

108
  val empty: t
109

110
  val feature_names: t -> string list option
bguillaum's avatar
bguillaum committed
111

112 113
  (** [is_open_feature domain feature_name] returns [true] iff no domain is set or if [feature_name] is defined to be open in the current domain. *)
  val is_open_feature: t -> feature_name -> bool
bguillaum's avatar
bguillaum committed
114

115 116
  (** [check_feature ~loc domain feature_name feature_value] fails iff a domain is set and [feature_name,feature_value] is not defined in the current domain. *)
  val check_feature: ?loc:Loc.t -> t -> feature_name -> feature_atom -> unit
bguillaum's avatar
bguillaum committed
117

118 119 120 121 122 123 124
  (** [check_feature_name ~loc domain feature_name] fails iff a domain is set and [feature_name] is not defined in the current domain. *)
  val check_feature_name: ?loc:Loc.t -> t -> feature_name -> unit
end

(* ================================================================================ *)
(** The module [Label] defines the type of atomic label edges *)
module Label : sig
125
  type t
bguillaum's avatar
bguillaum committed
126

127 128 129 130 131 132
  val succ: t (* built-in label for succ relation *)

  val is_succ: t -> bool

  (** [match_ dom p_label g_label] returns [true] iff [g_label]
      is a global label matching either constant p_label or patten p_label *)
133
  val match_: Domain.t -> t -> t -> bool
bguillaum's avatar
bguillaum committed
134

135 136
  (** [match_list dom list g_label] returns [true] iff [g_label]
      is a global label matching at least one of the p_label of [list] *)
137
  val match_list: Domain.t -> t list -> t -> bool
bguillaum's avatar
bguillaum committed
138

139
  val to_string: Domain.t -> ?locals:Label_domain.decl array -> t -> string
bguillaum's avatar
bguillaum committed
140

141
  val to_int: t -> int option
bguillaum's avatar
bguillaum committed
142

143
  val to_dep: Domain.t -> ?deco:bool -> t -> string
144

145
  val to_dot: Domain.t -> ?deco:bool -> t -> string
146

147 148
  val from_string: ?loc:Loc.t -> Domain.t -> ?locals:Label_domain.decl array -> string -> t
end (* module Label *)
149

150 151 152 153 154 155
(* ================================================================================ *)
(** The module [Label_cst] defines contraints on label edges *)
module Label_cst : sig
  type t =
  | Pos of Label.t list
  | Neg of Label.t list
156

157 158 159 160 161
  val to_string: Domain.t -> t -> string
  val all: t
  val match_: Domain.t -> Label.t -> t -> bool
  val build: ?loc:Loc.t -> Domain.t -> ?locals:Label_domain.decl array -> (string list * bool) -> t
end (* module Label_cst *)
162

163 164 165 166 167
(* ================================================================================ *)
module Feature_value: sig
  val build_disj: ?loc:Loc.t -> Domain.t -> feature_name -> feature_atom list -> value list

  val build_value: ?loc:Loc.t -> Domain.t -> feature_name -> feature_atom -> value
bguillaum's avatar
bguillaum committed
168
end (* module Feature_domain *)
bguillaum's avatar
bguillaum committed
169

170 171

(* ================================================================================ *)
bguillaum's avatar
bguillaum committed
172
(** module for rules that are lexically parametrized *)
173 174 175 176 177 178 179
module Lex_par: sig
  type t

  val append: t -> t -> t

  val dump: t -> unit

bguillaum's avatar
bguillaum committed
180 181 182 183 184
  val size: t -> int

  (** [signature t] returns (number of pattern parameters, number of lexical parameters) *)
  val signature: t -> (int * int)

185 186 187 188 189 190
  (** [from_lines filename nb_pattern_var nb_command_var strings] *)
  val from_lines: ?loc: Loc.t -> int -> int -> string list -> t

  (** [load ?loc local_dir_name nb_pattern_var nb_command_var file] *)
  val load: ?loc: Loc.t -> string -> int -> int -> string -> t

bguillaum's avatar
bguillaum committed
191
  (** [select index atom t] returns the subset of [t] which contains only entries
192
      which refers to [atom] at the [index]^th pattern_var.
bguillaum's avatar
bguillaum committed
193
      [None] is returned if no such entry s founded.
194
   *)
bguillaum's avatar
bguillaum committed
195
  val select: int -> string -> t -> t option
196 197 198 199 200 201 202 203 204

  (** [get_param_value index t] returns the [index]^th param_var. *)
  val get_param_value: int -> t -> string

  (** [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 (* module Lex_par *)

bguillaum's avatar
bguillaum committed
205 206 207 208 209 210 211 212
(* ================================================================================ *)
module Concat_item : sig
  type t =
  | Feat of (Gid.t * feature_name)
  | String of string
end (* module Concat_item *)


213