grew_ast.mli 5.26 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
bguillaum's avatar
bguillaum committed
12 13
 
module Ast : sig
14 15 16 17 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
  type feature_name = string (* cat, num, ... *)
  type feature_atom = string (* V, N, inf, ... *)
  type feature_value = string (* V, 4, "free text", ... *)

  (* -------------------------------------------------------------------------------- *)
  (* 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


bguillaum's avatar
bguillaum committed
49
  type feature_spec = 
50 51 52
    | 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
53

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

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

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

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

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

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

87

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

bguillaum's avatar
bguillaum committed
91
  type u_const = 
92 93 94 95 96 97 98
    | 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
99 100 101 102 103 104 105 106 107
  type const = u_const * Loc.t

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

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

bguillaum's avatar
bguillaum committed
112
  type u_command = 
113
    | Del_edge_expl of (act_id * act_id * edge_label)
bguillaum's avatar
bguillaum committed
114
    | Del_edge_name of string
115 116 117 118 119 120 121 122 123 124 125
    | 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
126
  type command = u_command * Loc.t
bguillaum's avatar
bguillaum committed
127

bguillaum's avatar
bguillaum committed
128 129 130 131 132
  type rule = {
      rule_id:Id.name;
      pos_pattern: pattern;
      neg_patterns: pattern list;
      commands: command list;
133 134
      param: (string list * string list) option; (* (files, vars) *)
      lp: string list option; (* lexical parameters in the file *)
bguillaum's avatar
bguillaum committed
135
      rule_doc:string list;
bguillaum's avatar
bguillaum committed
136 137 138 139 140
      rule_loc: Loc.t;
    }
        
  type modul = {
      module_id:Id.name;
141
      local_labels: (string * string list) list;
142
      new_node_names: string list;
bguillaum's avatar
bguillaum committed
143 144
      rules: rule list;
      confluent: bool;
bguillaum's avatar
bguillaum committed
145
      module_doc:string list;
bguillaum's avatar
bguillaum committed
146
      mod_loc:Loc.t;
147
      mod_dir: string; (* the directory where the module is defined (for lp file localisation) *)
bguillaum's avatar
bguillaum committed
148 149 150 151 152
    }
        
  type sequence = {
      seq_name:string;
      seq_mod:string list;
bguillaum's avatar
bguillaum committed
153
      seq_doc:string list;
bguillaum's avatar
bguillaum committed
154 155 156 157 158 159 160 161
      seq_loc:Loc.t;
    }
        
(** 
    a GRS: graph rewriting system 
 *)
  type module_or_include = 
    | Modul of modul
162
    | Includ of (string * Loc.t)
bguillaum's avatar
bguillaum committed
163 164 165

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

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

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

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