Commit 2cee37c8 authored by Bruno Guillaume's avatar Bruno Guillaume

Fix highlight for combine search: f=v/g=u

parent a9d46186
...@@ -280,8 +280,18 @@ module G_fs = struct ...@@ -280,8 +280,18 @@ module G_fs = struct
(* ---------------------------------------------------------------------- *) (* ---------------------------------------------------------------------- *)
let to_dot ?(decorated_feat=("",[])) ?main_feat t = 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 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 | pid -> bprintf buff "<TR><TD COLSPAN=\"3\" BGCOLOR=\"yellow\"><B>[%s]</B></TD></TR>\n" pid in
...@@ -289,7 +299,7 @@ module G_fs = struct ...@@ -289,7 +299,7 @@ module G_fs = struct
match get_main ?main_feat t with match get_main ?main_feat t with
| (None, sub) -> sub | (None, sub) -> sub
| (Some (feat_name,atom), 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) 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); else bprintf buff "<TR><TD COLSPAN=\"3\"><B>%s</B></TD></TR>\n" (string_of_value atom);
sub in sub in
...@@ -321,7 +331,15 @@ module G_fs = struct ...@@ -321,7 +331,15 @@ module G_fs = struct
(* ---------------------------------------------------------------------- *) (* ---------------------------------------------------------------------- *)
let to_dep ?(decorated_feat=("",[])) ?position ?main_feat ?filter t = 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 (main_opt, sub) = get_main ?main_feat t in
let sub = List.sort G_feature.print_cmp sub in let sub = List.sort G_feature.print_cmp sub in
...@@ -330,10 +348,11 @@ module G_fs = struct ...@@ -330,10 +348,11 @@ module G_fs = struct
| None -> [] | None -> []
| Some (feat_name, atom) -> | Some (feat_name, atom) ->
let esc_atom = escape_sharp (string_of_value atom) in 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 then sprintf "%s:B:#8bf56e" esc_atom
else esc_atom] in else esc_atom] in
(* add the pattern identifier *)
let word_list = match pid_name with let word_list = match pid_name with
| "" -> main | "" -> main
| _ -> (sprintf "[%s]:B:#8bf56e" pid_name)::main in | _ -> (sprintf "[%s]:B:#8bf56e" pid_name)::main in
...@@ -349,7 +368,7 @@ module G_fs = struct ...@@ -349,7 +368,7 @@ module G_fs = struct
let lines = List.fold_left let lines = List.fold_left
(fun acc (feat_name, atom) -> (fun acc (feat_name, atom) ->
let esc_atom = escape_sharp (G_feature.to_string (decode_feat_name feat_name, atom)) in 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 then (sprintf "%s:B:#8bf56e" esc_atom) :: acc
else else
match filter with match filter with
...@@ -419,7 +438,11 @@ module P_fs = struct ...@@ -419,7 +438,11 @@ module P_fs = struct
let unsorted = List.map (P_feature.build ?domain ?pat_vars) ast_fs in let unsorted = List.map (P_feature.build ?domain ?pat_vars) ast_fs in
List.sort P_feature.compare unsorted 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 let to_string t = List_.to_string P_feature.to_string "\\n" t
......
...@@ -47,9 +47,9 @@ module G_fs: sig ...@@ -47,9 +47,9 @@ module G_fs: sig
val get_float_feat: string -> t -> float option val get_float_feat: string -> t -> float option
val to_gr: t -> string 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_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_string: ?exclude: string list -> t -> string
val to_conll: ?exclude: string list -> t -> (string * string) list val to_conll: ?exclude: string list -> t -> (string * string) list
val to_json: t -> json val to_json: t -> json
...@@ -84,7 +84,7 @@ module P_fs: sig ...@@ -84,7 +84,7 @@ module P_fs: sig
val to_dot: t -> string val to_dot: t -> string
val feat_list: t -> string list val feat_list: t -> (string * string option) list
exception Fail exception Fail
......
...@@ -212,8 +212,11 @@ end (* module P_graph *) ...@@ -212,8 +212,11 @@ end (* module P_graph *)
(* ================================================================================ *) (* ================================================================================ *)
module G_deco = struct 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 = { 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 *) edges: (Gid.t * G_edge.t * Gid.t) list; (* an edge list *)
} }
......
...@@ -32,10 +32,13 @@ end (* module P_deco *) ...@@ -32,10 +32,13 @@ end (* module P_deco *)
(* ================================================================================ *) (* ================================================================================ *)
module G_deco: sig module G_deco: sig
type t = (* value is (f, Some g) for combined request "f=v/g=u" and (j, None) else *)
{ nodes: (Gid.t * (string * string list)) list; type highlighted_feat = string * string option
edges: (Gid.t * G_edge.t * Gid.t) list;
} 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 val empty:t
end (* module G_deco *) end (* module G_deco *)
......
...@@ -591,7 +591,8 @@ module Rule = struct ...@@ -591,7 +591,8 @@ module Rule = struct
Pid_map.fold Pid_map.fold
(fun pid gid acc -> (fun pid gid acc ->
let pnode = P_graph.find pid (fst pattern).graph in 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 []; ) matching.n_match [];
G_deco.edges = List.fold_left (fun acc (_,edge) -> edge::acc) [] matching.e_match; G_deco.edges = List.fold_left (fun acc (_,edge) -> edge::acc) [] matching.e_match;
} }
...@@ -617,14 +618,15 @@ module Rule = struct ...@@ -617,14 +618,15 @@ module Rule = struct
) Gid_map.empty commands in ) 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.nodes = List.map (fun (gid,feat_list) ->
G_deco.edges = List.fold_left (gid, ("", (List.map (fun x -> (x,None)) feat_list)))
(fun acc -> function ) (Gid_map.bindings feat_to_highlight);
| (Command.ADD_EDGE (src_cn,tar_cn,edge),loc) -> G_deco.edges = List.fold_left (fun acc -> function
(find src_cn (matching, created_nodes), edge, find tar_cn (matching, created_nodes)) :: acc | (Command.ADD_EDGE (src_cn,tar_cn,edge),loc) ->
| _ -> acc (find src_cn (matching, created_nodes), edge, find tar_cn (matching, created_nodes)) :: acc
) [] commands | _ -> acc
} ) [] commands;
}
exception Fail exception Fail
type partial = { 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