Commit 10c1d994 authored by bguillaum's avatar bguillaum

version 0.33.1: fix Conll error locations

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/semagramme/libcaml-grew/trunk@8916 7838e531-6607-4d57-9587-6c381814729c
parent 6a6564e4
......@@ -22,6 +22,9 @@ module Loc = struct
type t = string * int
let file_line f l = (f,l)
let file_opt_line fo l = match fo with
| Some f -> file_line f l
| None -> file_line "No_file" l
let file f = (f, -1)
......
......@@ -49,6 +49,7 @@ module Loc: sig
type t
val file_line: string -> int -> t
val file_opt_line: string option -> int -> t
val file: string -> t
val opt_set_line: int -> t option -> t option
......
......@@ -344,7 +344,8 @@ module G_graph = struct
(* -------------------------------------------------------------------------------- *)
let of_conll ?loc domain conll =
let of_conll domain conll =
let sorted_lines = Conll.root :: (List.sort Conll.compare conll.Conll.lines) in
let gtable = (Array.of_list (List.map (fun line -> line.Conll.id) sorted_lines), string_of_int) in
......@@ -352,33 +353,33 @@ module G_graph = struct
let map_without_edges =
List_.foldi_left
(fun i acc line ->
let loc = Loc.opt_set_line i loc in
Gid_map.add (Gid.Old i) (G_node.of_conll domain ?loc line) acc)
let loc = Loc.file_opt_line conll.Conll.file line.Conll.line_num in
Gid_map.add (Gid.Old i) (G_node.of_conll domain ~loc line) acc)
Gid_map.empty sorted_lines in
let map_with_edges =
List.fold_left
(fun acc line ->
(* add line number information in loc *)
let loc = Loc.opt_set_line line.Conll.line_num loc in
let dep_id = Id.gbuild ?loc line.Conll.id gtable in
let loc = Loc.file_opt_line conll.Conll.file line.Conll.line_num in
let dep_id = Id.gbuild ~loc line.Conll.id gtable in
List.fold_left
(fun acc2 (gov, dep_lab) ->
let gov_id = Id.gbuild ?loc gov gtable in
let edge = G_edge.make domain ?loc dep_lab in
let gov_id = Id.gbuild ~loc gov gtable in
let edge = G_edge.make domain ~loc dep_lab in
(match map_add_edge acc2 (Gid.Old gov_id) edge (Gid.Old dep_id) with
| Some g -> g
| None -> Error.build "[GRS] [Graph.of_conll] try to build a graph with twice the same edge %s %s"
(G_edge.to_string domain edge)
(match loc with Some l -> Loc.to_string l | None -> "")
(Loc.to_string loc)
)
) acc line.Conll.deps
) map_without_edges conll.Conll.lines in
let fusion =
List.map
(fun {Conll.first; last; fusion} ->
( Gid.Old (Id.gbuild ?loc first gtable),
(Gid.Old (Id.gbuild ?loc last gtable),
(fun {Conll.first; last; fusion; mw_line_num} ->
let loc = Loc.file_opt_line conll.Conll.file mw_line_num in
( Gid.Old (Id.gbuild ~loc first gtable),
(Gid.Old (Id.gbuild ~loc last gtable),
fusion)
)
) conll.Conll.multiwords in
......@@ -833,7 +834,7 @@ module G_graph = struct
) graph.map Gid_map.empty in
let buff = Buffer.create 32 in
List.iter (fun v -> bprintf buff "# %s\n" v) graph.meta;
List.iter (fun v -> bprintf buff "%s\n" v) graph.meta;
List.iter
(fun (gid, node) ->
begin
......
......@@ -107,7 +107,7 @@ module G_graph: sig
val build: Domain.t -> ?locals: Label_domain.decl array -> Ast.gr -> t
val of_conll: ?loc:Loc.t -> Domain.t -> Conll.t -> t
val of_conll: Domain.t -> Conll.t -> t
(** input : "Le/DET/le petit/ADJ/petit chat/NC/chat dort/V/dormir ./PONCT/."
It supposes that "SUC" is defined in current relations *)
......
......@@ -108,7 +108,7 @@ type t = Grew_graph.G_graph.t
let load_conll domain file =
handle ~name:"Graph.load_conll" ~file
(fun () ->
Grew_graph.G_graph.of_conll ~loc:(Grew_base.Loc.file file) domain (Conll.load file)
Grew_graph.G_graph.of_conll domain (Conll.load file)
) ()
let load_brown domain file =
......
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