grew_rule.mli 5.23 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                                                   *)
(**********************************************************************************)

Bruno Guillaume's avatar
Bruno Guillaume committed
11
open Yojson.Basic
bguillaum's avatar
bguillaum committed
12
open Grew_base
13
open Grew_types
14
open Grew_domain
bguillaum's avatar
bguillaum committed
15 16
open Grew_graph
open Grew_command
pj2m's avatar
pj2m committed
17 18
open Grew_edge
open Grew_fs
bguillaum's avatar
bguillaum committed
19
open Grew_ast
pj2m's avatar
pj2m committed
20

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

Bruno Guillaume's avatar
Bruno Guillaume committed
30 31
  val swap: t -> t

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

35 36
  (** [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
37 38
  val rev_steps: t -> t

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

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

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

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

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

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

60 61 62 63 64 65
  (** [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
66 67 68 69
  (** [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

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

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

Bruno Guillaume's avatar
Bruno Guillaume committed
76 77
  val to_json: ?domain:Domain.t -> t -> Yojson.Basic.json

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

81
  (** [build domain ?local dir ast_rule] returns the Rule.t value corresponding to [ast_rule].
82
      [dir] is used for localisation of lp files *)
Bruno Guillaume's avatar
Bruno Guillaume committed
83
  val build: ?domain:Domain.t -> string -> Ast.rule -> t
pj2m's avatar
pj2m committed
84

Bruno Guillaume's avatar
Bruno Guillaume committed
85
  (** [normalize domain module_name ?deterministic rule_list instance] returns a set of normal forms *)
pj2m's avatar
pj2m committed
86
  (* raise Stop if some command fails to apply *)
87
  val normalize:
bguillaum's avatar
bguillaum committed
88
    ?domain:Domain.t ->
89
    string -> (* module name *)
90
    ?deterministic:bool ->
91
    t list -> (* rule list *)
pj2m's avatar
pj2m committed
92
    Instance.t ->
Bruno Guillaume's avatar
Bruno Guillaume committed
93
      Instance_set.t
bguillaum's avatar
bguillaum committed
94

Bruno Guillaume's avatar
Bruno Guillaume committed
95 96
  val one_step: ?domain: Domain.t -> Instance.t -> t list -> Instance_set.t
  val conf_one_step: ?domain: Domain.t -> Instance.t -> t list -> Instance.t option
bguillaum's avatar
bguillaum committed
97

bguillaum's avatar
bguillaum committed
98 99
  (** 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
100
  type matching
101 102
  type pattern

103
  val pid_name_list: pattern -> Id.name list
104

Bruno Guillaume's avatar
Bruno Guillaume committed
105
  val to_python: pattern -> G_graph.t -> matching -> json
106

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

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

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

115
  (** [match_deco rule matching] builds the decoration of the [graph] illustrating the given [matching] of the [rule] *)
bguillaum's avatar
bguillaum committed
116
  (* NB: it can be computed independly from the graph itself! *)
117
  val match_deco: pattern -> matching -> G_deco.t
Bruno Guillaume's avatar
Bruno Guillaume committed
118 119 120 121 122 123 124 125




  val apply: ?domain: Domain.t -> t -> Instance.t -> Instance_set.t
  val det_apply: ?domain: Domain.t -> t -> Instance.t -> Instance.t option


Bruno Guillaume's avatar
Bruno Guillaume committed
126 127 128
  val wrd_apply: ?domain: Domain.t -> t -> (G_graph.t * Libgrew_types.big_step option) -> (G_graph.t * Libgrew_types.big_step) option


Bruno Guillaume's avatar
Bruno Guillaume committed
129

130 131 132 133 134
  val onf_apply: ?domain: Domain.t -> t -> G_graph.t -> G_graph.t option
  val gwh_apply: ?domain: Domain.t -> t -> Graph_with_history.t -> Graph_with_history_set.t



Bruno Guillaume's avatar
Bruno Guillaume committed
135

136
end (* module Rule *)