Commit 75e39c75 authored by Bruno Guillaume's avatar Bruno Guillaume
Browse files

improve error localisation

parent 7556851f
...@@ -760,6 +760,7 @@ module Edge = struct ...@@ -760,6 +760,7 @@ module Edge = struct
src: Id.t; src: Id.t;
label: Conllx_label.t; label: Conllx_label.t;
tar: Id.t; tar: Id.t;
line_num: int option;
} }
(* ---------------------------------------------------------------------------------------------------- *) (* ---------------------------------------------------------------------------------------------------- *)
...@@ -802,13 +803,19 @@ module Edge = struct ...@@ -802,13 +803,19 @@ module Edge = struct
| (Some "-", Some "-") -> [] | (Some "-", Some "-") -> []
(* PARSEME-IT@1.1 and PARSEME-IT@1.1 has the pair ("0", "_") as HEAD/DEPREL *) (* PARSEME-IT@1.1 and PARSEME-IT@1.1 has the pair ("0", "_") as HEAD/DEPREL *)
| (Some "0", None) -> [{ src=Id.of_string ?file ?sent_id ?line_num "0"; label=Conllx_label.of_string ~config "root"; tar }] | (Some "0", None) -> [
{ src=Id.of_string ?file ?sent_id ?line_num "0";
label=Conllx_label.of_string ~config "root";
tar;
line_num;
}
]
| (Some srcs, Some labels) -> | (Some srcs, Some labels) ->
let src_id_list = List.map (Id.of_string ?file ?sent_id ?line_num) (Str.split (Str.regexp "|") srcs) in let src_id_list = List.map (Id.of_string ?file ?sent_id ?line_num) (Str.split (Str.regexp "|") srcs) in
let label_list = List.map (Conllx_label.of_string ~config) (Str.split (Str.regexp "|") labels) in let label_list = List.map (Conllx_label.of_string ~config) (Str.split (Str.regexp "|") labels) in
begin begin
try List.map2 (fun src label -> { src; label; tar}) src_id_list label_list try List.map2 (fun src label -> { src; label; tar; line_num}) src_id_list label_list
with Invalid_argument _ -> Error.error ?file ?sent_id ?line_num "different number of items in HEAD/DEPREL spec" with Invalid_argument _ -> Error.error ?file ?sent_id ?line_num "different number of items in HEAD/DEPREL spec"
end end
| (None, None) -> [] | (None, None) -> []
...@@ -820,7 +827,7 @@ module Edge = struct ...@@ -820,7 +827,7 @@ module Edge = struct
List.fold_left List.fold_left
(fun acc sec -> (fun acc sec ->
match Str.bounded_split (Str.regexp ":") sec 2 with match Str.bounded_split (Str.regexp ":") sec 2 with
| [src_string;label] -> { src=Id.of_string ?file ?sent_id ?line_num src_string; label = Conllx_label.of_string_deps ?file ?sent_id ?line_num ~config label; tar} :: acc | [src_string;label] -> { src=Id.of_string ?file ?sent_id ?line_num src_string; label = Conllx_label.of_string_deps ?file ?sent_id ?line_num ~config label; tar; line_num} :: acc
| _ -> Error.error ?file ?sent_id ?line_num "Cannot parse secondary edges `%s`" sec | _ -> Error.error ?file ?sent_id ?line_num "Cannot parse secondary edges `%s`" sec
) head_dep_edges (Str.split (Str.regexp "|") deps) ) head_dep_edges (Str.split (Str.regexp "|") deps)
...@@ -844,6 +851,7 @@ module Edge = struct ...@@ -844,6 +851,7 @@ module Edge = struct
src = Id.Raw (json |> member "src" |> to_string); src = Id.Raw (json |> member "src" |> to_string);
label = json |> member "label" |> Conllx_label.of_json; label = json |> member "label" |> Conllx_label.of_json;
tar = Id.Raw (json |> member "tar" |> to_string); tar = Id.Raw (json |> member "tar" |> to_string);
line_num = None;
} }
with Type_error _ -> Error.error ~fct:"Edge.of_json" ~data:json "illformed json" with Type_error _ -> Error.error ~fct:"Edge.of_json" ~data:json "illformed json"
...@@ -1145,8 +1153,8 @@ module Conllx = struct ...@@ -1145,8 +1153,8 @@ module Conllx = struct
let check_edge ?file ?sent_id nodes edge = let check_edge ?file ?sent_id nodes edge =
match (List.exists (fun n -> n.Node.id = edge.Edge.src) nodes, List.exists (fun n -> n.Node.id = edge.Edge.tar) nodes) with match (List.exists (fun n -> n.Node.id = edge.Edge.src) nodes, List.exists (fun n -> n.Node.id = edge.Edge.tar) nodes) with
| (true, true) -> () | (true, true) -> ()
| (false, _) -> Error.error ?file ?sent_id "Unknown identifier `%s`" (Id.to_string edge.Edge.src) | (false, _) -> Error.error ?file ?sent_id ?line_num:edge.Edge.line_num "Unknown src identifier `%s`" (Id.to_string edge.Edge.src)
| (_, false) -> Error.error ?file ?sent_id "Unknown identifier `%s`" (Id.to_string edge.Edge.tar) | (_, false) -> Error.error ?file ?sent_id ?line_num:edge.Edge.line_num "Unknown tar identifier `%s`" (Id.to_string edge.Edge.tar)
(* ---------------------------------------------------------------------------------------------------- *) (* ---------------------------------------------------------------------------------------------------- *)
let of_string_list_rev ~config ?file ~columns string_list_rev = let of_string_list_rev ~config ?file ~columns string_list_rev =
......
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