Commit b64e2f58 authored by bguillaum's avatar bguillaum

take grewpy node ordering into account in Graph.of_gr

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/semagramme/libcaml-grew/trunk@9063 7838e531-6607-4d57-9587-6c381814729c
parent e91ca0cf
......@@ -102,6 +102,8 @@ module Ast = struct
}
type node = u_node * Loc.t
let grewpy_compare (n1,_) (n2,_) = Id.grewpy_compare n1.node_id n2.node_id
type edge_label = string
type edge_label_cst =
......
......@@ -70,6 +70,8 @@ module Ast : sig
}
type node = u_node * Loc.t
val grewpy_compare: node -> node -> int
type edge_label = string (* p_obj.agt:suj *)
type edge_label_cst =
......
......@@ -560,6 +560,20 @@ module Id = struct
let build_opt key table =
try Some (Array_.dicho_find key table)
with Not_found -> None
let get_float name =
try
let len = String.length name in
let index = Str.search_forward (Str.regexp "[0-9]") name 0 in
let sub = String.sub name index (len-index) in
try Some (float_of_string sub) with _ -> None
with Not_found -> None
let grewpy_compare name1 name2 =
match (get_float name1, get_float name2) with
| Some f1, Some f2 -> Pervasives.compare f1 f2
| _ -> Pervasives.compare name1 name2
end (* module Id *)
(* ================================================================================ *)
......
......@@ -267,6 +267,7 @@ module Id: sig
val build_opt: name -> table -> t option
val grewpy_compare: name -> name -> int
end
(* ================================================================================ *)
......
......@@ -273,10 +273,14 @@ module G_graph = struct
| None -> None
(* -------------------------------------------------------------------------------- *)
let build domain ?(locals=[||]) gr_ast =
let full_node_list = gr_ast.Ast.nodes
let build domain ?(grewpy=false) ?(locals=[||]) gr_ast =
let full_node_list =
if grewpy
then List.sort (Ast.grewpy_compare) gr_ast.Ast.nodes
else gr_ast.Ast.nodes
and full_edge_list = gr_ast.Ast.edges in
let rec loop already_bound index prec = function
| [] -> (Gid_map.empty,[])
......
......@@ -104,7 +104,7 @@ module G_graph: sig
(* Build functions *)
(* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)
val build: Domain.t -> ?locals: Label_domain.decl array -> Ast.gr -> t
val build: Domain.t -> ?grewpy: bool -> ?locals: Label_domain.decl array -> Ast.gr -> t
val of_conll: Domain.t -> Conll.t -> t
......
......@@ -136,8 +136,8 @@ type t = Grew_graph.G_graph.t
loop [load_gr; load_conll; load_brown]
) ()
let of_gr domain gr_string =
handle ~name:"Graph.of_gr" (fun () -> Grew_graph.G_graph.build domain (Grew_loader.Parser.gr gr_string)) ()
let of_gr domain ?(grewpy=false) gr_string =
handle ~name:"Graph.of_gr" (fun () -> Grew_graph.G_graph.build domain ~grewpy (Grew_loader.Parser.gr gr_string)) ()
let of_conll domain conll =
handle ~name:"Graph.of_conll" (fun () -> Grew_graph.G_graph.of_conll domain conll) ()
......
......@@ -87,7 +87,7 @@ module Graph : sig
@raise File_not_found if the file doesn't exists. *)
val load: Domain.t -> string -> t
val of_gr: Domain.t -> string -> t
val of_gr: Domain.t -> ?grewpy:bool -> string -> t
val of_conll: Domain.t -> Conll.t -> t
......
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