Commit 1b159bf5 authored by bguillaum's avatar bguillaum
Browse files

complete graph with implicitly defined nodes

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/semagramme/libcaml-grew/trunk@9096 7838e531-6607-4d57-9587-6c381814729c
parent a79b0d69
......@@ -95,6 +95,11 @@ module Ast = struct
}
type feature = u_feature * Loc.t
let default_fs ?loc lab =
match loc with
| None -> [({name="label"; kind=Equality [lab]}, Loc.empty)]
| Some l -> [({name="label"; kind=Equality [lab]}, l)]
type u_node = {
node_id: Id.name;
position: float option;
......@@ -199,11 +204,6 @@ module Ast = struct
let new_pat_negs = List.map (complete_basic aux) pattern.pat_negs in
{ pat_pos = new_pat_pos; pat_negs = new_pat_negs;}
type graph = {
nodes: (Id.name * node) list;
edge: edge list;
}
type concat_item =
| Qfn_item of feature_ident
| String_item of string
......@@ -345,6 +345,23 @@ module Ast = struct
edges: edge list;
}
let complete id nodes =
let rec loop n = match n with
| [] -> [{node_id=id; position=None; fs=default_fs id},Loc.empty]
| ({ node_id = head_id },_)::_ when head_id = id -> n
| head::tail -> head :: (loop tail)
in loop nodes
let complete_graph gr =
let new_nodes =
List.fold_left
(fun acc (edge,_) ->
acc
|> (complete edge.src)
|> (complete edge.tar)
) gr.nodes gr.edges in
{ gr with nodes = new_nodes }
let empty_grs = { domain = None; modules = []; strategies= [] }
(* phrase structure tree *)
......
......@@ -63,6 +63,8 @@ module Ast : sig
}
type feature = u_feature * Loc.t
val default_fs: ?loc:Loc.t -> string -> feature list
type u_node = {
node_id: Id.name;
position: float option;
......@@ -204,6 +206,8 @@ module Ast : sig
edges: edge list;
}
val complete_graph: gr -> gr
val empty_grs: grs
(* phrase structure tree *)
......
......@@ -187,6 +187,7 @@ ineq_value_with_loc:
gr:
| GRAPH LACC items=separated_list_final_opt(SEMIC,gr_item) RACC EOF
{
Ast.complete_graph
{
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;
......@@ -204,6 +205,9 @@ gr_item:
| id_loc=node_id_with_loc position=option(delimited(LPAREN, FLOAT ,RPAREN)) feats=delimited(LBRACKET,separated_list_final_opt(COMA,node_features),RBRACKET)
{ let (id,loc) = id_loc in
Graph_node ({Ast.node_id = id; position=position; fs=feats}, loc) }
| id_loc=node_id_with_loc
{ let (id,loc) = id_loc in
Graph_node ({Ast.node_id = id; position=None; fs=Ast.default_fs ~loc id}, loc) }
(* A -[x]-> B *)
| n1_loc=node_id_with_loc label=delimited(LTR_EDGE_LEFT,label_ident,LTR_EDGE_RIGHT) n2=node_id
......
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