Commit 27b0629a authored by bguillaum's avatar bguillaum

version 0.15: add meta-information to the G_graph type

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/semagramme/libcaml-grew/trunk@7526 7838e531-6607-4d57-9587-6c381814729c
parent 8da9a038
VERSION = 0.14
VERSION = 0.15
INSTALL_DIR_LIB = @OCAMLLIB@
INSTALL_DIR = @prefix@/bin/
......
......@@ -56,12 +56,6 @@ module Ast = struct
pat_const: const list;
}
type graph = {
nodes: (Id.name * node) list;
edge: edge list;
}
type concat_item =
| Qfn_item of (string * string)
| String_item of string
......@@ -138,7 +132,8 @@ module Ast = struct
}
type gr = {
nodes: node list;
edges: edge list;
}
meta: (string * string) list;
nodes: node list;
edges: edge list;
}
end (* module Ast *)
......@@ -126,7 +126,8 @@ module Ast : sig
}
type gr = {
nodes: node list;
edges: edge list;
}
meta: (string * string) list;
nodes: node list;
edges: edge list;
}
end (* module Ast *)
This diff is collapsed.
......@@ -68,14 +68,23 @@ end (* module Concat_item *)
(* ==================================================================================================== *)
module G_graph: sig
type t = G_node.t Gid_map.t
type t
val empty: t
(** [find gid graph] return the g_node associated with [gid] in [graph].
[Not_found] is raised if [gid] is not defined in [graph]. *)
val find: Gid.t -> t -> G_node.t
val equals: t -> t -> bool
val node_exists: (G_node.t -> bool) -> t -> bool
val fold_gid: (Gid.t -> 'a -> 'a) -> t -> 'a -> 'a
(** raise ??? *)
val max_binding: t -> int
(** [edge_out t id edge] returns true iff there is an out-edge from the node [id] with a label compatible with [edge] *)
val edge_out: t -> Gid.t -> P_edge.t -> bool
......
......@@ -25,9 +25,7 @@ module Instance = struct
let from_graph graph =
{empty with
graph = graph;
free_index = match (Gid_map.max_binding graph) with
| (Gid.Old i,_) -> i+1
| _ -> Error.bug "[Instance.from_graph]"
free_index = (G_graph.max_binding graph) + 1;
}
let rev_steps t =
......@@ -362,14 +360,14 @@ module Rule = struct
check = pattern.constraints;
}
(* Ocaml < 3.12 doesn't have exists function for maps! *)
exception True
let gid_map_exists fct map =
try
Gid_map.iter (fun k v -> if fct k v then raise True) map;
false
with True -> true
(* Ocaml < 3.12 doesn't have exists function for maps! *)
(* (\* Ocaml < 3.12 doesn't have exists function for maps! *\) *)
(* exception True *)
(* let gid_map_exists fct map = *)
(* try *)
(* Gid_map.iter (fun k v -> if fct k v then raise True) map; *)
(* false *)
(* with True -> true *)
(* (\* Ocaml < 3.12 doesn't have exists function for maps! *\) *)
let fullfill graph matching = function
......@@ -378,13 +376,13 @@ module Rule = struct
G_graph.edge_out graph gid edge
| Cst_in (pid,edge) ->
let gid = Pid_map.find pid matching.n_match in
gid_map_exists (* should be Gid_map.exists with ocaml 3.12 *)
(fun _ node ->
G_graph.node_exists
(fun node ->
List.exists (fun e -> P_edge.compatible edge e) (Massoc_gid.assoc gid (G_node.get_next node))
) graph
| Feature_eq (pid1, feat_name1, pid2, feat_name2) ->
let gnode1 = Gid_map.find (Pid_map.find pid1 matching.n_match) graph in
let gnode2 = Gid_map.find (Pid_map.find pid2 matching.n_match) graph in
let gnode1 = G_graph.find (Pid_map.find pid1 matching.n_match) graph in
let gnode2 = G_graph.find (Pid_map.find pid2 matching.n_match) graph in
(match (G_fs.get_atom feat_name1 (G_node.get_fs gnode1),
G_fs.get_atom feat_name2 (G_node.get_fs gnode2)
) with
......@@ -392,7 +390,7 @@ module Rule = struct
| _ -> false)
| Filter (pid, fs) ->
let gid = Pid_map.find pid matching.n_match in
let gnode = Gid_map.find gid graph in
let gnode = G_graph.find gid graph in
P_fs.filter fs (G_node.get_fs gnode)
(* returns all extension of the partial input matching *)
......@@ -444,8 +442,8 @@ module Rule = struct
) candidates
end
| [], pid :: _ ->
Gid_map.fold
(fun gid _ acc ->
G_graph.fold_gid
(fun gid acc ->
(extend_matching_from (positive,neg) graph pid gid partial) @ acc
) graph []
......
......@@ -10,6 +10,7 @@ type pat_item =
| Pat_const of Ast.const
type graph_item =
| Graph_meta of (string * string)
| Graph_node of Ast.node
| Graph_edge of Ast.edge
......@@ -94,22 +95,33 @@ let localize t = (t,get_loc ())
| x=X; separator { [x] }
| x=X; separator; xs = separated_nonempty_list_final_opt(separator,X) { x :: xs }
/*=============================================================================================*/
/* GREW GRAPH */
/* BASIC DEFINITIONS */
/*=============================================================================================*/
value:
| v = IDENT { v }
| v = STRING { v }
| v = INT { string_of_int v }
/*=============================================================================================*/
/* GREW GRAPH */
/*=============================================================================================*/
gr:
| GRAPH LACC items = separated_list_final_opt(SEMIC,gr_item) RACC EOF
{
{
Ast.meta = List_.opt_map (function Graph_meta n -> Some n | _ -> None) items;
Ast.nodes = List_.opt_map (function Graph_node n -> Some n | _ -> None) items;
Ast.edges = List_.opt_map (function Graph_edge n -> Some n | _ -> None) items;
}
}
gr_item:
(* sentence = "Jean dort." *)
| id = IDENT EQUAL value = value
{ Graph_meta (id, value) }
(* B (1) [phon="pense", lemma="penser", cat=v, mood=ind ] *)
| id = IDENT position = option(delimited(LPAREN,index,RPAREN)) feats = delimited(LBRACKET,separated_list_final_opt(COMA,node_features),RBRACKET)
{ Graph_node (localize {Ast.node_id = id; position=position; fs=feats}) }
......@@ -187,9 +199,9 @@ features_group:
%inline feature:
| name = feature_name DDOT values = features_values
{
if List.length values == 1 && List.hd values = "*"
if values = ["*"]
then Ast.Open name
else Ast.Closed (name,List.sort Pervasives.compare values)
else Ast.Closed (name, List.sort Pervasives.compare values)
}
feature_name:
......@@ -197,7 +209,7 @@ feature_name:
features_values:
| STAR { ["*"] }
| x = separated_nonempty_list(COMA,feature_value) { x }
| x = separated_nonempty_list(COMA,value) { x }
/*=============================================================================================*/
......@@ -379,24 +391,16 @@ pat_node:
| id = IDENT feats = delimited(LBRACKET,separated_list_final_opt(COMA,node_features),RBRACKET)
{ localize ({Ast.node_id = id; position=None; fs= feats}) }
node_features:
| name = IDENT EQUAL STAR
{ localize {Ast.kind = Ast.Disequality []; name=name; } }
| name = IDENT EQUAL values = separated_nonempty_list(PIPE,feature_value)
| name = IDENT EQUAL values = separated_nonempty_list(PIPE,value)
{ localize {Ast.kind = Ast.Equality values; name=name; } }
| name = IDENT DISEQUAL values = separated_nonempty_list(PIPE,feature_value)
| name = IDENT DISEQUAL values = separated_nonempty_list(PIPE,value)
{ localize {Ast.kind = Ast.Disequality values; name=name; } }
| name = IDENT EQUAL p = PAT
{ localize {Ast.kind = Ast.Param p; name=name; } }
feature_value:
| v = IDENT { v }
| v = STRING { v }
| v = INT { string_of_int v }
pat_edge:
(* "e: A -> B" OR "e: A -[*]-> B" *)
| id = edge_id n1 = IDENT GOTO_NODE n2 = IDENT
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment