grew_types.mli 6.57 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
(**********************************************************************************)
(*    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", ... *)
bguillaum's avatar
bguillaum committed
16 17 18 19 20 21 22

type value = String of string | Float of float

val string_of_value : value -> string

val conll_string_of_value : value -> string

23 24
type disjunction = value list

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
(* ================================================================================ *)
(* [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
49
  type t = int
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

  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
67 68
module Label_domain : sig
  type t
bguillaum's avatar
bguillaum committed
69
  
70 71 72
  (* [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
73 74 75 76
  val build: decl list -> t
end

(* ================================================================================ *)
77 78 79 80 81
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
82

83 84
  type t

85
  val build: feature_spec list -> t
86

87 88
  (** [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
89

90
  val build_closed: feature_name -> feature_atom list -> feature_spec
91

92
end (* module Feature_domain *)
93

94 95 96
(* ================================================================================ *)
module Domain : sig
  type t
97

98
  val build: Label_domain.t -> Feature_domain.t -> t
99

bguillaum's avatar
bguillaum committed
100
  val feature_names: t -> string list
bguillaum's avatar
bguillaum committed
101

102
  (** [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. *)
bguillaum's avatar
bguillaum committed
103
  val is_open_feature: ?domain: t -> feature_name -> bool
bguillaum's avatar
bguillaum committed
104

105
  (** [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. *)
bguillaum's avatar
bguillaum committed
106
  val check_feature: ?loc:Loc.t -> ?domain: t -> feature_name -> feature_atom -> unit
bguillaum's avatar
bguillaum committed
107

108
  (** [check_feature_name ~loc domain feature_name] fails iff a domain is set and [feature_name] is not defined in the current domain. *)
bguillaum's avatar
bguillaum committed
109
  val check_feature_name: ?loc:Loc.t -> ?domain:t -> feature_name -> unit
110 111 112 113 114
end

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

117 118
  (** [match_list p_label_list g_label] returns [true] iff [g_label] match at least one of the p_label of [p_label_list] *)
  val match_list: t list -> t -> bool
bguillaum's avatar
bguillaum committed
119

bguillaum's avatar
bguillaum committed
120
  val to_string: ?domain:Domain.t -> t -> string
bguillaum's avatar
bguillaum committed
121

bguillaum's avatar
bguillaum committed
122
  val is_void: ?domain: Domain.t -> t -> bool
123

bguillaum's avatar
bguillaum committed
124
  val to_dep: ?domain: Domain.t -> ?deco:bool -> t -> string
125

bguillaum's avatar
bguillaum committed
126
  val to_dot: ?domain: Domain.t -> ?deco:bool -> t -> string
127

bguillaum's avatar
bguillaum committed
128
  val from_string: ?loc:Loc.t -> ?domain: Domain.t -> ?locals:Label_domain.decl array -> string -> t
129
end (* module Label *)
130

131 132
(* ================================================================================ *)
module Feature_value: sig
bguillaum's avatar
bguillaum committed
133
  val build_disj: ?loc:Loc.t -> ?domain: Domain.t -> feature_name -> feature_atom list -> value list
134

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

138 139

(* ================================================================================ *)
bguillaum's avatar
bguillaum committed
140
(** module for rules that are lexically parametrized *)
141 142 143 144 145 146 147
module Lex_par: sig
  type t

  val append: t -> t -> t

  val dump: t -> unit

bguillaum's avatar
bguillaum committed
148 149 150 151 152
  val size: t -> int

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

153 154 155 156 157 158
  (** [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
159
  (** [select index atom t] returns the subset of [t] which contains only entries
160
      which refers to [atom] at the [index]^th pattern_var.
bguillaum's avatar
bguillaum committed
161
      [None] is returned if no such entry s founded.
162
   *)
bguillaum's avatar
bguillaum committed
163
  val select: int -> string -> t -> t option
164 165 166 167 168 169 170 171 172

  (** [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
173 174 175 176 177 178 179 180
(* ================================================================================ *)
module Concat_item : sig
  type t =
  | Feat of (Gid.t * feature_name)
  | String of string
end (* module Concat_item *)


181