grew_graph.mli 7.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 12
open Conll

13 14 15
open Grew_base
open Grew_types

bguillaum's avatar
bguillaum committed
16
open Grew_ast
17
open Grew_fs
pj2m's avatar
pj2m committed
18 19
open Grew_edge
open Grew_node
bguillaum's avatar
bguillaum committed
20
open Grew_command
pj2m's avatar
pj2m committed
21

bguillaum's avatar
bguillaum committed
22
(* ================================================================================ *)
23 24 25
module P_deco: sig
  type t =
      { nodes: Pid.t list;
26
        edges: (Pid.t * P_edge.t * Pid.t) list;
pj2m's avatar
pj2m committed
27
      }
28 29

  val empty:t
bguillaum's avatar
bguillaum committed
30
end (* module P_deco *)
31

bguillaum's avatar
bguillaum committed
32
(* ================================================================================ *)
33 34
module G_deco: sig
  type t =
35
      { nodes: (Gid.t * (string * string list)) list;
36
        edges: (Gid.t * G_edge.t * Gid.t) list;
37 38
      }

pj2m's avatar
pj2m committed
39
  val empty:t
bguillaum's avatar
bguillaum committed
40
end (* module G_deco *)
pj2m's avatar
pj2m committed
41

bguillaum's avatar
bguillaum committed
42
(* ================================================================================ *)
43 44
module P_graph: sig
  type t = P_node.t Pid_map.t
45

pj2m's avatar
pj2m committed
46
  val empty: t
bguillaum's avatar
bguillaum committed
47

48 49
  val find: Pid.t -> t -> P_node.t

bguillaum's avatar
bguillaum committed
50 51
  val roots: t -> Pid.t list

52 53
  type extension = {
      ext_map: P_node.t Pid_map.t; (* node description for new nodes and for edge "Old -> New"  *)
bguillaum's avatar
bguillaum committed
54
      old_map: P_node.t Pid_map.t; (* a partial map for new constraints on old nodes "Old [...]" *)
55
    }
pj2m's avatar
pj2m committed
56

57
  (** It raises [P_fs.Fail_unif] exception in case of inconsistent feature structures. *)
pj2m's avatar
pj2m committed
58
  val build:
bguillaum's avatar
bguillaum committed
59
      ?domain:Domain.t ->
bguillaum's avatar
bguillaum committed
60
      ?pat_vars: string list ->
bguillaum's avatar
bguillaum committed
61
      ?locals: Label_domain.decl array ->
bguillaum's avatar
bguillaum committed
62 63
      Ast.node list ->
      Ast.edge list ->
64
      (t * Id.table)
pj2m's avatar
pj2m committed
65

66
  (** It raises [P_fs.Fail_unif] exception in case of inconsistent feature structures. *)
67
  val build_extension:
bguillaum's avatar
bguillaum committed
68
      ?domain:Domain.t ->
bguillaum's avatar
bguillaum committed
69
      ?pat_vars: string list ->
bguillaum's avatar
bguillaum committed
70
      ?locals: Label_domain.decl array ->
pj2m's avatar
pj2m committed
71
      Id.table ->
bguillaum's avatar
bguillaum committed
72 73
      Ast.node list ->
      Ast.edge list ->
74
      (extension * Id.table)
bguillaum's avatar
bguillaum committed
75
end (* module P_graph *)
76

bguillaum's avatar
bguillaum committed
77
(* ================================================================================ *)
78
module G_graph: sig
79
  type t
80 81

  val empty: t
pj2m's avatar
pj2m committed
82

83 84
  (** [find gid graph] return the g_node associated with [gid] in [graph].
      [Not_found] is raised if [gid] is not defined in [graph]. *)
85 86
  val find: Gid.t -> t -> G_node.t

bguillaum's avatar
bguillaum committed
87 88
  val equals: t -> t -> bool

89 90 91 92
  val node_exists: (G_node.t -> bool) -> t -> bool

  val fold_gid: (Gid.t -> 'a -> 'a) -> t -> 'a -> 'a

bguillaum's avatar
bguillaum committed
93 94
  val get_highest: t -> int

95
  (** [edge_out label_domain t id label_cst] returns true iff there is an out-edge from the node [id] with a label compatible with [label_cst] *)
bguillaum's avatar
bguillaum committed
96
  val edge_out: ?domain:Domain.t -> t -> Gid.t -> Label_cst.t -> bool
bguillaum's avatar
bguillaum committed
97

bguillaum's avatar
bguillaum committed
98 99 100 101 102
  (** [get_annot_info graph] searches for exactly one node with an annot-feature (with name starting with "__").
      It returns the annot-feature name without the prefix "__" together with the position.
      raise an [Build] exception if there is not exactly one annot-feature (with name starting with "__")  *)
  val get_annot_info: t -> (string * float)

bguillaum's avatar
bguillaum committed
103 104 105 106
  (* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)
  (* Build functions *)
  (* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)

bguillaum's avatar
bguillaum committed
107
  val build: ?domain:Domain.t -> ?grewpy: bool -> ?locals: Label_domain.decl array -> Ast.gr -> t
bguillaum's avatar
bguillaum committed
108

bguillaum's avatar
bguillaum committed
109
  val of_conll: ?domain:Domain.t -> Conll.t -> t
bguillaum's avatar
bguillaum committed
110

111 112
  (** input : "Le/DET/le petit/ADJ/petit chat/NC/chat dort/V/dormir ./PONCT/." 
      It supposes that "SUC" is defined in current relations *)
bguillaum's avatar
bguillaum committed
113
  val of_brown: ?domain:Domain.t -> ?sentid: string -> string -> t
114

bguillaum's avatar
bguillaum committed
115
  val of_xml: ?domain:Domain.t -> Xml.xml -> t
bguillaum's avatar
bguillaum committed
116 117 118 119
  (* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)
  (* Update functions *)
  (* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)

120 121 122

  val rename: (Gid.t * Gid.t) list -> t -> t

bguillaum's avatar
bguillaum committed
123 124 125 126 127
  (** [add_edge graph id_src label id_tar] tries to add an edge grom [id_src] to [id_tar] with [label] to [graph].
      if it succeeds, [Some new_graph] is returned
      if it fails (the edge already exists), [None] is returned
  *)
  val add_edge: t -> Gid.t -> G_edge.t -> Gid.t -> t option
pj2m's avatar
pj2m committed
128

bguillaum's avatar
bguillaum committed
129 130
  (** [del_edge ?edge_ident loc graph id_src label id_tar] removes the edge (id_src -[label]-> id_tar) from graph.
     Log.critical if the edge is not in graph *)
bguillaum's avatar
bguillaum committed
131
  val del_edge: ?domain:Domain.t -> ?edge_ident: string -> Loc.t -> t -> Gid.t -> G_edge.t -> Gid.t -> t
132

bguillaum's avatar
bguillaum committed
133 134 135
  (** [del_node graph id] remove node [id] from [graph], with all its incoming and outcoming edges.
      [graph] is unchanged if the node is not in it. *)
  val del_node: t -> Gid.t -> t
136

bguillaum's avatar
bguillaum committed
137
  val add_neighbour: Loc.t -> ?domain:Domain.t -> t -> Gid.t -> G_edge.t -> (Gid.t * t)
bguillaum's avatar
bguillaum committed
138

bguillaum's avatar
bguillaum committed
139 140
  val add_before: Loc.t -> ?domain:Domain.t -> Gid.t -> t -> (Gid.t * t)
  val add_after: Loc.t -> ?domain:Domain.t -> Gid.t -> t -> (Gid.t * t)
bguillaum's avatar
bguillaum committed
141

bguillaum's avatar
bguillaum committed
142
  val merge_node: Loc.t -> ?domain:Domain.t -> t -> Gid.t -> Gid.t -> t option
pj2m's avatar
pj2m committed
143

bguillaum's avatar
bguillaum committed
144
  (** move all in arcs to id_src are moved to in arcs on node id_tar from graph, with all its incoming edges *)
bguillaum's avatar
bguillaum committed
145
  val shift_in: Loc.t -> ?domain:Domain.t -> Gid.t -> Gid.t -> Label_cst.t -> t -> t
146

bguillaum's avatar
bguillaum committed
147
  (** move all out-edges from id_src are moved to out-edges out off node id_tar *)
bguillaum's avatar
bguillaum committed
148
  val shift_out: Loc.t -> ?domain:Domain.t -> Gid.t -> Gid.t -> Label_cst.t -> t -> t
bguillaum's avatar
bguillaum committed
149 150

  (** move all incident arcs from/to id_src are moved to incident arcs on node id_tar from graph, with all its incoming and outcoming edges *)
bguillaum's avatar
bguillaum committed
151
  val shift_edges: Loc.t -> ?domain:Domain.t -> Gid.t -> Gid.t -> Label_cst.t -> t -> t
pj2m's avatar
pj2m committed
152

153
  (** [update_feat domain tar_id tar_feat_name concat_items] sets the feature of the node [tar_id]
154 155
      with feature name [tar_feat_name] to be the contatenation of values described by the [concat_items].
      It returns both the new graph and the new feature value produced as the second element *)
bguillaum's avatar
bguillaum committed
156
  val update_feat: ?loc:Loc.t -> ?domain:Domain.t -> t -> Gid.t -> string -> Concat_item.t list -> (t * string)
pj2m's avatar
pj2m committed
157

bguillaum's avatar
bguillaum committed
158
  val set_feat: ?loc:Loc.t -> ?domain:Domain.t -> t -> Gid.t -> string -> string -> t
bguillaum's avatar
bguillaum committed
159

bguillaum's avatar
bguillaum committed
160 161
  (** [del_feat graph node_id feat_name] returns [graph] where the feat [feat_name] of [node_id] is deleted
      If the feature is not present, [graph] is returned. *)
162
  val del_feat: t -> Gid.t -> string -> t
pj2m's avatar
pj2m committed
163

bguillaum's avatar
bguillaum committed
164 165 166
  (* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)
  (* Output functions *)
  (* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)
bguillaum's avatar
bguillaum committed
167 168
  val to_gr: ?domain:Domain.t -> t -> string
  val to_dot: ?domain:Domain.t -> ?main_feat:string -> ?deco:G_deco.t -> t -> string
bguillaum's avatar
bguillaum committed
169
  val to_sentence: ?main_feat:string -> t -> string
bguillaum's avatar
bguillaum committed
170 171
  val to_dep: ?domain:Domain.t -> ?filter : string list -> ?main_feat:string -> ?deco:G_deco.t -> t -> string
  val to_conll_string: ?domain:Domain.t -> t -> string
172

bguillaum's avatar
bguillaum committed
173
  val to_raw: ?domain:Domain.t -> t ->
174
    string list *
175 176
    (string * string) list list *
    (int * string * int) list
bguillaum's avatar
bguillaum committed
177
end (* module G_graph *)