grew_rule.mli 5.14 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
  }

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

32 33
  (** [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
34 35
  val rev_steps: t -> t

36 37 38 39
  (** [refresh t] returns a fresh representation of the graph.
      Graphs are refreshed after each module. *)
  val refresh: t -> t

40
  (** [to_gr t] returns a string which contains the "gr" code of the current graph *)
bguillaum's avatar
bguillaum committed
41
  val to_gr: ?domain:Domain.t -> t -> string
42

43
  (** [to_conll_string t] returns a string which contains the "conll" code of the current graph *)
bguillaum's avatar
bguillaum committed
44
  val to_conll_string: ?domain:Domain.t -> t -> string
bguillaum's avatar
bguillaum committed
45

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

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

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

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

62 63 64 65 66 67
  (** [set_max_depth_det value] set the maximum rewriting depth in deterministic application of a module. *)
  val set_max_depth_det: int -> unit

  (** [set_max_depth_non_det value] set the maximum rewriting depth in non-deterministic application of a module. *)
  val set_max_depth_non_det: int -> unit

bguillaum's avatar
bguillaum committed
68 69 70 71
  (** [set_debug_loop ()] turns the debug mode on for loop: when the bound is reached, the graph is considered as a normal form.
      This is a kind of hack to be able to explore loops in GUI. *)
  val set_debug_loop: unit -> unit

72
  (** [get_name t] returns the name of the rule [t]. *)
bguillaum's avatar
bguillaum committed
73 74
  val get_name: t -> string

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

78
  (** [is_filter t] returns [true] iff the rule [t] is a filter rule. *)
79 80
  val is_filter: t -> bool

bguillaum's avatar
bguillaum committed
81
  (** [to_dep t] returns a string in the [dep] language describing the match basic of the rule *)
bguillaum's avatar
bguillaum committed
82
  val to_dep: ?domain:Domain.t -> t -> string
bguillaum's avatar
bguillaum committed
83

84
  (** [build domain ?local dir ast_rule] returns the Rule.t value corresponding to [ast_rule].
85
      [dir] is used for localisation of lp files *)
bguillaum's avatar
bguillaum committed
86
  val build: ?domain:Domain.t -> ?locals:Label_domain.decl array -> string -> Ast.rule -> t
pj2m's avatar
pj2m committed
87

88
  (** [normalize domain module_name ?confluent rule_list filter_list instance] returns two sets of good normal forms and bad normal forms *)
pj2m's avatar
pj2m committed
89
  (* raise Stop if some command fails to apply *)
90
  val normalize:
bguillaum's avatar
bguillaum committed
91
    ?domain:Domain.t ->
92
    string -> (* module name *)
bguillaum's avatar
bguillaum committed
93
    ?confluent:bool ->
94 95
    t list -> (* rule list *)
    t list -> (* filter list *)
pj2m's avatar
pj2m committed
96 97
    Instance.t ->
      Instance_set.t * Instance_set.t
bguillaum's avatar
bguillaum committed
98

bguillaum's avatar
bguillaum committed
99 100
  val one_step: ?domain: Domain.t -> string -> Instance.t -> t list -> Instance.t list

bguillaum's avatar
bguillaum committed
101 102
  (** the type matching encodes the graph morphism from a pattern to a graph *)
  (* NB: it was made public for the grep mode *)
bguillaum's avatar
bguillaum committed
103
  type matching
104 105
  type pattern

bguillaum's avatar
bguillaum committed
106
  val build_pattern: ?domain:Domain.t -> Ast.pattern -> pattern
bguillaum's avatar
bguillaum committed
107

108 109 110
  (** [node_matching pattern graph matching] return a assoc list (pid_name, gid.position) *)
  val node_matching: pattern -> G_graph.t -> matching -> (string * int) list

bguillaum's avatar
bguillaum committed
111
  (** [match_in_graph rule graph] returns the list of matching of the pattern of the rule into the graph *)
bguillaum's avatar
bguillaum committed
112
  val match_in_graph: ?domain:Domain.t -> ?param:Lex_par.t -> pattern -> G_graph.t -> matching list
bguillaum's avatar
bguillaum committed
113

114
  (** [match_deco rule matching] builds the decoration of the [graph] illustrating the given [matching] of the [rule] *)
bguillaum's avatar
bguillaum committed
115
  (* NB: it can be computed independly from the graph itself! *)
116
  val match_deco: pattern -> matching -> G_deco.t
117
end (* module Rule *)