grew_ast.mli 5.24 KB
Newer Older
bguillaum's avatar
bguillaum committed
1 2 3 4 5 6 7 8 9 10
(**********************************************************************************)
(*    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                                                   *)
(**********************************************************************************)

11
open Libgrew_utils
12

bguillaum's avatar
bguillaum committed
13
module Ast : sig
14 15 16
  type feature_name = string (* cat, num, ... *)
  type feature_atom = string (* V, N, inf, ... *)
  type feature_value = string (* V, 4, "free text", ... *)
17
  type suffix = string
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

  (* -------------------------------------------------------------------------------- *)
  (* complex_id: V, V#alpha, V.cat, V#alpha.cat, p_obj.loc *)
  type complex_id =
    | No_sharp of string
    | Sharp of string * string
  val complex_id_to_string: complex_id -> string

  (* simple_id: V *)
  type simple_id = Id.name
  val simple_id_of_ci: complex_id -> string
  val is_simple: complex_id -> bool

  (* label_id: V *)
  type label_id = Id.name
  val label_id_of_ci: complex_id -> string

  (* act_id: V, V#alpha *)
  type act_id = Id.name * string option
  val act_id_of_ci: complex_id -> act_id
  val act_id_to_string: act_id -> string

  (* simple_qfn: V.cat *)
  type simple_qfn = Id.name * feature_name
  val simple_qfn_of_ci: complex_id -> simple_qfn
  val simple_qfn_to_string: simple_qfn -> string

  (* act_id: V.cat, V#alpha.cat *)
  type act_qfn = act_id * feature_name
  val act_qfn_of_ci: complex_id -> act_qfn


50
  type feature_spec =
51 52 53
    | Closed of feature_name * feature_atom list (* cat:V,N *)
    | Open of feature_name (* phon, lemma, ... *)
    | Int of feature_name (* position *)
bguillaum's avatar
bguillaum committed
54

bguillaum's avatar
bguillaum committed
55
  type domain = feature_spec list
bguillaum's avatar
bguillaum committed
56
  val normalize_domain: domain -> domain
57

58
  type feature_kind =
59 60 61
    | Equality of feature_value list
    | Disequality of feature_value list
    | Param of string (* $ident *)
bguillaum's avatar
bguillaum committed
62
    | Absent
bguillaum's avatar
bguillaum committed
63 64

  type u_feature = {
65 66 67
    name: feature_name;
    kind: feature_kind;
  }
bguillaum's avatar
bguillaum committed
68 69 70 71
  type feature = u_feature * Loc.t

  type u_node = {
      node_id: Id.name;
72
      position: float option;
bguillaum's avatar
bguillaum committed
73 74 75 76
      fs: feature list;
    }
  type node = u_node * Loc.t

77 78
  type edge_label = string (* p_obj.agt:suj *)

bguillaum's avatar
bguillaum committed
79 80 81
  type u_edge = {
      edge_id: Id.name option;
      src: Id.name;
82
      edge_labels: edge_label list;
bguillaum's avatar
bguillaum committed
83 84 85 86 87
      tar: Id.name;
      negative: bool;
    }
  type edge = u_edge * Loc.t

88

bguillaum's avatar
bguillaum committed
89 90 91
  type ineq = Lt | Gt | Le | Ge
  val string_of_ineq: ineq -> string

92
  type u_const =
93 94 95 96 97 98 99
    | Start of Id.name * edge_label list (* (source, labels) *)
    | Cst_out of Id.name
    | End of Id.name * edge_label list (* (target, labels) *)
    | Cst_in of Id.name
    | Feature_eq of simple_qfn * simple_qfn
    | Feature_diseq of simple_qfn * simple_qfn
    | Feature_ineq of ineq * simple_qfn * simple_qfn
bguillaum's avatar
bguillaum committed
100 101 102 103 104 105 106 107 108
  type const = u_const * Loc.t

  type pattern = {
      pat_nodes: node list;
      pat_edges: edge list;
      pat_const: const list;
    }

  type concat_item =
109
    | Qfn_item of complex_id
bguillaum's avatar
bguillaum committed
110
    | String_item of string
111
    | Param_item of string
112

113
  type u_command =
114
    | Del_edge_expl of (act_id * act_id * edge_label)
bguillaum's avatar
bguillaum committed
115
    | Del_edge_name of string
116 117 118 119 120 121 122 123 124 125 126
    | Add_edge of (act_id * act_id * edge_label)
    | Shift_in of (act_id * act_id)
    | Shift_out of (act_id * act_id)
    | Shift_edge of (act_id * act_id)
    | Merge_node of (act_id * act_id)
    | New_neighbour of (Id.name * act_id * edge_label)
    | Del_node of act_id
    | Activate of act_id

    | Del_feat of act_qfn
    | Update_feat of act_qfn * concat_item list
bguillaum's avatar
bguillaum committed
127
  type command = u_command * Loc.t
bguillaum's avatar
bguillaum committed
128

bguillaum's avatar
bguillaum committed
129 130 131 132 133
  type rule = {
      rule_id:Id.name;
      pos_pattern: pattern;
      neg_patterns: pattern list;
      commands: command list;
134 135
      param: (string list * string list) option; (* (files, vars) *)
      lp: string list option; (* lexical parameters in the file *)
bguillaum's avatar
bguillaum committed
136
      rule_doc:string list;
bguillaum's avatar
bguillaum committed
137 138
      rule_loc: Loc.t;
    }
139

bguillaum's avatar
bguillaum committed
140 141
  type modul = {
      module_id:Id.name;
142
      local_labels: (string * string list) list;
143
      suffixes: string list;
bguillaum's avatar
bguillaum committed
144 145
      rules: rule list;
      confluent: bool;
bguillaum's avatar
bguillaum committed
146
      module_doc:string list;
bguillaum's avatar
bguillaum committed
147
      mod_loc:Loc.t;
148
      mod_dir: string; (* the directory where the module is defined (for lp file localisation) *)
bguillaum's avatar
bguillaum committed
149
    }
150

bguillaum's avatar
bguillaum committed
151 152 153
  type sequence = {
      seq_name:string;
      seq_mod:string list;
bguillaum's avatar
bguillaum committed
154
      seq_doc:string list;
bguillaum's avatar
bguillaum committed
155 156
      seq_loc:Loc.t;
    }
157 158 159

(**
    a GRS: graph rewriting system
bguillaum's avatar
bguillaum committed
160
 *)
161
  type module_or_include =
bguillaum's avatar
bguillaum committed
162
    | Modul of modul
163
    | Includ of (string * Loc.t)
bguillaum's avatar
bguillaum committed
164 165 166

  type grs_with_include = {
      domain_wi: domain;
167
      labels_wi: (string * string list) list;    (* the list of global edge labels *)
168
      modules_wi: module_or_include list;
bguillaum's avatar
bguillaum committed
169 170 171 172 173
      sequences_wi: sequence list;
    }

  type grs = {
      domain: domain;
174
      labels: (string * string list) list;
bguillaum's avatar
bguillaum committed
175 176 177 178 179
      modules: modul list;
      sequences: sequence list;
    }

  type gr = {
180 181 182 183
    meta: (string * string) list;
    nodes: node list;
    edges: edge list;
  }
bguillaum's avatar
bguillaum committed
184 185

  val empty_grs: grs
bguillaum's avatar
bguillaum committed
186
end (* module Ast *)