Commit c4f645a3 authored by Bruno Guillaume's avatar Bruno Guillaume

resolve confictts

parents 9203b116 27498c75
# 0.49.0 (2018/07/05)
* Add new syntax in pattern node "f=u/g=v" (mainly for MWEPOS handling in relations consistency checks)
# 0.48.0 (2018/06/19)
* remove `conll_fields` mechanism (names of conll fields 2, 4 and 5 are `form`, `upos`, `xpos`)
......
......@@ -100,6 +100,7 @@ module Ast = struct
| Disequal_lex of string * string
| Equal_param of string (* $ident *)
| Absent
| Else of (feature_value * feature_name * feature_value)
let feature_kind_to_string = function
| Equality fv_list -> sprintf " = %s" (String.concat "|" fv_list)
......@@ -109,6 +110,7 @@ module Ast = struct
| Disequal_lex (lex,fn) -> sprintf " <> %s.%s" lex fn
| Equal_param param -> sprintf " = $%s" param
| Absent -> " <> *"
| Else (fv1, fn2, fv2) -> sprintf " = %s/%s = %s" fv1 fn2 fv2
type u_feature = {
name: feature_name;
......
......@@ -64,6 +64,7 @@ module Ast : sig
| Disequal_lex of string * string
| Equal_param of string (* $ident *)
| Absent
| Else of (feature_value * feature_name * feature_value)
type u_feature = {
name: feature_name;
......
......@@ -80,6 +80,7 @@ module P_feature = struct
| Different of value list
| Equal_lex of string * string
| Different_lex of string * string
| Else of (value * feature_name * value)
(* NB: in the current version, |in_param| ≤ 1 *)
type v = {
......@@ -98,7 +99,9 @@ module P_feature = struct
| Equal l -> "=" ^ (String.concat "|" (List.map string_of_value l))
| Equal_lex (lex,fn) -> sprintf "= %s.%s" lex fn
| Different_lex (lex,fn) -> sprintf "≠ %s.%s" lex fn
| Absent -> " must be Absent!");
| Absent -> " must be Absent!"
| Else (fv1,fn2,fv2) -> sprintf " = %s/%s = %s" (string_of_value fv1) fn2 (string_of_value fv2));
printf "in_param=[%s]\n" (String.concat "," (List.map string_of_int in_param));
printf "%!"
......@@ -111,6 +114,7 @@ module P_feature = struct
| Different val_list -> ("different", `List (List.map (fun x -> `String (string_of_value x)) val_list))
| Equal_lex (lex,fn) -> ("equal_lex", `String (sprintf "%s.%s" lex fn))
| Different_lex (lex,fn) -> ("different_lex", `String (sprintf "%s.%s" lex fn))
| Else (fv1,fn2,fv2) -> ("else", `List [`String (string_of_value fv1); `String fn2; `String (string_of_value fv2)]);
)
]
......@@ -176,6 +180,10 @@ module P_feature = struct
| ({Ast.kind=Ast.Disequal_lex (lex,fn); name=name}, loc) ->
Lexicons.check ~loc lex fn lexicons;
(name, {cst=Different_lex (lex,fn); in_param=[];})
| ({Ast.kind=Ast.Else (fv1,fn2,fv2); name=name}, loc) ->
let v1 = match Feature_value.build_disj ~loc ?domain name [fv1] with [one] -> one | _ -> failwith "BUG Else" in
let v2 = match Feature_value.build_disj ~loc ?domain name [fv2] with [one] -> one | _ -> failwith "BUG Else" in
(name, {cst=Else (v1,fn2,v2);in_param=[];})
| ({Ast.kind=Ast.Equal_param var; name=name}, loc) ->
begin
match pat_vars with
......@@ -283,8 +291,18 @@ module G_fs = struct
(* ---------------------------------------------------------------------- *)
let to_dot ?(decorated_feat=("",[])) ?main_feat t =
let (pid_name, highlighted_feat_list) = decorated_feat in
let is_highlithed feat_name =
(List.mem_assoc feat_name highlighted_feat_list) ||
(List.exists (function
| (f, Some g) when g = feat_name && (not (List.mem_assoc f t)) && (List.mem_assoc g t) -> true
| _ -> false
) highlighted_feat_list
) in
let buff = Buffer.create 32 in
let () = match (fst decorated_feat) with
let () = match pid_name with
| "" -> ()
| pid -> bprintf buff "<TR><TD COLSPAN=\"3\" BGCOLOR=\"yellow\"><B>[%s]</B></TD></TR>\n" pid in
......@@ -292,7 +310,7 @@ module G_fs = struct
match get_main ?main_feat t with
| (None, sub) -> sub
| (Some (feat_name,atom), sub) ->
if List.mem feat_name (snd decorated_feat)
if is_highlithed feat_name
then bprintf buff "<TR><TD COLSPAN=\"3\" BGCOLOR=\"yellow\"><B>%s</B></TD></TR>\n" (string_of_value atom)
else bprintf buff "<TR><TD COLSPAN=\"3\"><B>%s</B></TD></TR>\n" (string_of_value atom);
sub in
......@@ -324,7 +342,15 @@ module G_fs = struct
(* ---------------------------------------------------------------------- *)
let to_dep ?(decorated_feat=("",[])) ?position ?main_feat ?filter t =
let (pid_name, feat_list) = decorated_feat in
let (pid_name, highlighted_feat_list) = decorated_feat in
let is_highlithed feat_name =
(List.mem_assoc feat_name highlighted_feat_list) ||
(List.exists (function
| (f, Some g) when g = feat_name && (not (List.mem_assoc f t)) && (List.mem_assoc g t) -> true
| _ -> false
) highlighted_feat_list
) in
let (main_opt, sub) = get_main ?main_feat t in
let sub = List.sort G_feature.print_cmp sub in
......@@ -333,10 +359,11 @@ module G_fs = struct
| None -> []
| Some (feat_name, atom) ->
let esc_atom = escape_sharp (string_of_value atom) in
[ if List.mem feat_name (snd decorated_feat)
[ if is_highlithed feat_name
then sprintf "%s:B:#8bf56e" esc_atom
else esc_atom] in
(* add the pattern identifier *)
let word_list = match pid_name with
| "" -> main
| _ -> (sprintf "[%s]:B:#8bf56e" pid_name)::main in
......@@ -352,7 +379,7 @@ module G_fs = struct
let lines = List.fold_left
(fun acc (feat_name, atom) ->
let esc_atom = escape_sharp (G_feature.to_string (decode_feat_name feat_name, atom)) in
if List.mem feat_name (snd decorated_feat)
if is_highlithed feat_name
then (sprintf "%s:B:#8bf56e" esc_atom) :: acc
else
match filter with
......@@ -422,7 +449,11 @@ module P_fs = struct
let unsorted = List.map (P_feature.build lexicons ?domain ?pat_vars) ast_fs in
List.sort P_feature.compare unsorted
let feat_list t = List.map P_feature.get_name t
let feat_list t =
List.map (function
| (fn, {P_feature.cst=P_feature.Else (_,fn2,_)}) -> (fn, Some fn2)
| (fn, _) -> (fn, None)
) t
let to_string t = List_.to_string P_feature.to_string "\\n" t
......@@ -450,7 +481,19 @@ module P_fs = struct
| ((fn_pat, {P_feature.cst=P_feature.Absent})::t_pat, []) -> loop acc (t_pat, [])
| ((fn_pat, {P_feature.cst=P_feature.Absent})::t_pat, (fn, fa)::t) when fn_pat < fn -> loop acc (t_pat, (fn, fa)::t)
(* Two next cases: each feature_name present in p_fs must be in instance: [] means unif failure *)
(* look for the second part of an Else construction*)
| ((_, {P_feature.cst=P_feature.Else (_,fn2,fv2)})::t_pat,[]) ->
begin
try if (List.assoc fn2 g_fs) <> fv2 then raise Fail
with Not_found -> raise Fail
end; loop acc (t_pat, [])
| ((fn_pat, {P_feature.cst=P_feature.Else (_,fn2,fv2)})::t_pat,(fn, fv)::t) when fn_pat < fn ->
begin
try if (List.assoc fn2 g_fs) <> fv2 then raise Fail
with Not_found -> raise Fail
end; loop acc (t_pat, t)
(* Two next cases: each feature_name present in p_fs must be in instance *)
| _, [] -> raise Fail
| ((fn_pat, _)::_, (fn, _)::_) when fn_pat < fn -> raise Fail
......@@ -474,6 +517,40 @@ module P_fs = struct
| (_::p_tail, _::g_tail) -> loop acc (p_tail,g_tail) in
loop lexicons (p_fs_wo_pos,g_fs)
(* ------------------------------------------------------------------------------ *)
(*
| ((_, {P_feature.cst=cst; P_feature.in_param=in_param})::t_pat, (_, atom)::t) ->
(* check for the constraint part and fail if needed *)
let () = match cst with
| P_feature.Absent -> raise Fail
| P_feature.Equal fv when not (List_.sort_mem atom fv) -> raise Fail
| P_feature.Different fv when List_.sort_mem atom fv -> raise Fail
| P_feature.Else (fv1,_,_) when fv1 <> atom -> raise Fail
| _ -> () in
(* if constraint part don't fail, look for lexical parameters *)
match (acc, in_param) with
| (_,[]) -> loop acc (t_pat,t)
| (None,_) -> Log.bug "[P_fs.match_] Parametrized constraint in a non-parametrized rule"; exit 2
| (Some param, [index]) ->
(match Lex_par.select index (string_of_value atom) param with
| None -> raise Fail
| Some new_param -> loop (Some new_param) (t_pat,t)
)
| _ -> Error.bug "[P_fs.match_] several different parameters contraints for the same feature is not implemented" in
loop param (p_fs_wo_pos,g_fs)
*)
(* ------------------------------------------------------------------------------ *)
exception Fail_unif
let unif fs1 fs2 =
let rec loop = function
......
......@@ -47,9 +47,9 @@ module G_fs: sig
val get_float_feat: string -> t -> float option
val to_gr: t -> string
val to_dot: ?decorated_feat:(string * string list) -> ?main_feat: string -> t -> string
val to_dot: ?decorated_feat:(string * (string * string option) list) -> ?main_feat: string -> t -> string
val to_word: t -> string option
val to_dep: ?decorated_feat:(string * string list) -> ?position:float -> ?main_feat: string -> ?filter: (string -> bool) -> t -> string
val to_dep: ?decorated_feat:(string * (string * string option) list) -> ?position:float -> ?main_feat: string -> ?filter: (string -> bool) -> t -> string
val to_conll_string: ?exclude: string list -> t -> string
val to_conll: ?exclude: string list -> t -> (string * string) list
val to_json: t -> json
......@@ -84,7 +84,7 @@ module P_fs: sig
val to_dot: t -> string
val feat_list: t -> string list
val feat_list: t -> (string * string option) list
exception Fail
......
......@@ -206,8 +206,11 @@ end (* module P_graph *)
(* ================================================================================ *)
module G_deco = struct
(* value is (f, Some g) for combined request "f=v/g=u" and (j, None) else *)
type highlighted_feat = string * string option
type t = {
nodes: (Gid.t * (string * string list)) list; (* a list of (node, (pattern_id, features of nodes implied in the step)) *)
nodes: (Gid.t * (string * highlighted_feat list)) list; (* a list of (node, (pattern_id, features of nodes implied in the step)) *)
edges: (Gid.t * G_edge.t * Gid.t) list; (* an edge list *)
}
......
......@@ -32,10 +32,13 @@ end (* module P_deco *)
(* ================================================================================ *)
module G_deco: sig
type t =
{ nodes: (Gid.t * (string * string list)) list;
edges: (Gid.t * G_edge.t * Gid.t) list;
}
(* value is (f, Some g) for combined request "f=v/g=u" and (j, None) else *)
type highlighted_feat = string * string option
type t = {
nodes: (Gid.t * (string * highlighted_feat list)) list; (* a list of (node, (pattern_id, features of nodes implied in the step)) *)
edges: (Gid.t * G_edge.t * Gid.t) list; (* an edge list *)
}
val empty:t
end (* module G_deco *)
......
......@@ -139,6 +139,7 @@ and label_parser target = parse
| '}' { Global.label_flag := false; RACC }
| ',' { COMA }
| '|' { PIPE }
| '/' { SLASH }
| '@' general_ident as cmd_var { AROBAS_ID cmd_var }
| "@#" color as col { COLOR col }
......@@ -249,6 +250,8 @@ and standard target = parse
| ">=" | "≥" { GE }
| '|' { PIPE }
| '/' { SLASH }
| "->" { EDGE }
| "-[^" { Global.label_flag := true; LTR_EDGE_LEFT_NEG }
| "-[" { Global.label_flag := true; LTR_EDGE_LEFT }
......
......@@ -48,6 +48,7 @@ let localize t = (t,get_loc ())
%token EQUAL /* = */
%token DISEQUAL /* <> */
%token BANG /* ! */
%token SLASH /* / */
%token STAR /* * */
%token LT /* < */
%token GT /* > */
......@@ -612,6 +613,11 @@ node_features:
| BANG name_loc=simple_id_with_loc
{ let (name,loc) = name_loc in ({Ast.kind = Ast.Absent; name=Ast.to_uname name}, loc) }
/* mwepos=ADV/upos=ADV */
| name1_loc=simple_id_with_loc EQUAL fv1=feature_value SLASH name2=simple_id EQUAL fv2=feature_value
{ let (name1,loc) = name1_loc in ({Ast.kind = Ast.Else (fv1,name2,fv2); name=Ast.to_uname name1}, loc) }
/*=============================================================================================*/
/* COMMANDS DEFINITION */
/*=============================================================================================*/
......
......@@ -665,7 +665,8 @@ module Rule = struct
Pid_map.fold
(fun pid gid acc ->
let pnode = P_graph.find pid (fst pattern).graph in
(gid, (P_node.get_name pnode, P_fs.feat_list (P_node.get_fs pnode))) ::acc
let pattern_feat_list = P_fs.feat_list (P_node.get_fs pnode) in
(gid, (P_node.get_name pnode, pattern_feat_list)) ::acc
) matching.n_match [];
G_deco.edges = List.fold_left (fun acc (_,edge) -> edge::acc) [] matching.e_match;
}
......@@ -691,14 +692,15 @@ module Rule = struct
) Gid_map.empty commands in
{
G_deco.nodes = List.map (fun (gid,feat_list) -> (gid, ("",feat_list))) (Gid_map.bindings feat_to_highlight);
G_deco.edges = List.fold_left
(fun acc -> function
| (Command.ADD_EDGE (src_cn,tar_cn,edge),loc) ->
(find src_cn (matching, created_nodes), edge, find tar_cn (matching, created_nodes)) :: acc
| _ -> acc
) [] commands
}
G_deco.nodes = List.map (fun (gid,feat_list) ->
(gid, ("", (List.map (fun x -> (x,None)) feat_list)))
) (Gid_map.bindings feat_to_highlight);
G_deco.edges = List.fold_left (fun acc -> function
| (Command.ADD_EDGE (src_cn,tar_cn,edge),loc) ->
(find src_cn (matching, created_nodes), edge, find tar_cn (matching, created_nodes)) :: acc
| _ -> acc
) [] commands;
}
exception Fail
type partial = {
......
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