grew_rule.mli 3.69 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 Grew_base
12 13
open Grew_types

bguillaum's avatar
bguillaum committed
14 15
open Grew_graph
open Grew_command
pj2m's avatar
pj2m committed
16 17
open Grew_edge
open Grew_fs
bguillaum's avatar
bguillaum committed
18
open Grew_ast
pj2m's avatar
pj2m committed
19

20
(* ================================================================================ *)
pj2m's avatar
pj2m committed
21 22
module Instance : sig
  type t = {
23 24 25
    graph: G_graph.t;
    history: Command.h list;
    rules: string list;
26
    big_step: Libgrew_types.big_step option;
27 28 29 30 31 32
    free_index: int;
    activated_node: Gid.t list;
  }

  (** [from_graph graph] return a fresh instance based on the input [graph]. *)
  val from_graph: G_graph.t -> t
bguillaum's avatar
bguillaum committed
33

34 35
  (** [rev_steps t] reverses the small step list: during rewriting, the last rule
      is in the head of the list and the reverse is needed for display. *)
pj2m's avatar
pj2m committed
36 37
  val rev_steps: t -> t

38
  (** [flatten inst] returns a fresh representation of the graph where gid created by node
39
      activation are map to basic gid. Graphs are flattened after each module. *)
40
  val flatten: t -> t
pj2m's avatar
pj2m committed
41

42
  (** [to_gr t] returns a string which contains the "gr" code of the current graph *)
43 44
  val to_gr: t -> string

bguillaum's avatar
bguillaum committed
45 46 47
  (** [to_conll t] returns a string which contains the "conll" code of the current graph *)
  val to_conll: t -> string

48
  (** [save_dep_png base t] writes a file "base.png" with the dep representation of [t].
bguillaum's avatar
bguillaum committed
49
      NB: if the Dep2pict is not available, nothing is done *)
50 51
  val save_dep_png: ?filter: string list -> ?main_feat: string -> string -> t -> float option
  val save_dep_svg: ?filter: string list -> ?main_feat: string -> string -> t -> float option
52

53
  (** [save_dot_png base t] writes a file "base.png" with the dot representation of [t] *)
54
  val save_dot_png: ?filter: string list -> ?main_feat: string -> string -> t -> unit
55
end (* module Instance *)
pj2m's avatar
pj2m committed
56

57
(* ================================================================================ *)
pj2m's avatar
pj2m committed
58 59
module Instance_set : Set.S with type elt = Instance.t

60
(* ================================================================================ *)
pj2m's avatar
pj2m committed
61 62 63
module Rule : sig
  type t

64
  (** [get_name t] returns the name of the rule [t]. *)
bguillaum's avatar
bguillaum committed
65 66
  val get_name: t -> string

bguillaum's avatar
bguillaum committed
67
  (** [get_loc t] returns the file location of the rule [t]. *)
68 69
  val get_loc: t -> Loc.t

70
  (** [is_filter t] returns [true] iff the rule [t] is a filter rule. *)
71 72
  val is_filter: t -> bool

73
  (** [to_dep t] returns a string in the [dep] language describing the pattern. *)
bguillaum's avatar
bguillaum committed
74 75
  val to_dep: t -> string

76 77
  (** [build ?local dir ast_rule] returns the Rule.t value corresponding to [ast_rule].
      [dir] is used for localisation of lp files *)
78
  val build: ?locals:Label.decl array -> string list -> string -> Ast.rule -> t
pj2m's avatar
pj2m committed
79

80
  (** [normalize module_name ?confluent rule_list filter_list instance] returns two sets of good normal forms and bad normal forms *)
pj2m's avatar
pj2m committed
81
  (* raise Stop if some command fails to apply *)
82 83
  val normalize:
    string -> (* module name *)
bguillaum's avatar
bguillaum committed
84
    ?confluent:bool ->
85 86
    t list -> (* rule list *)
    t list -> (* filter list *)
pj2m's avatar
pj2m committed
87 88
    Instance.t ->
      Instance_set.t * Instance_set.t
bguillaum's avatar
bguillaum committed
89 90 91

  type matching
  val match_in_graph: t -> G_graph.t -> matching list
92
end (* module Rule *)