Commit e752f6fa authored by bguillaum's avatar bguillaum

[libcaml-grew] - it is now possible to copy feature values with different feature_name

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/semagramme/libcaml-grew/trunk@6410 7838e531-6607-4d57-9587-6c381814729c
parent c67c36eb
......@@ -20,7 +20,7 @@ module Command = struct
| DEL_EDGE_EXPL of (cnode * cnode *Edge.t)
| DEL_EDGE_NAME of string
| ADD_EDGE of (cnode * cnode * Edge.t)
| CPY_FEAT of (cnode * cnode * string)
| COPY_FEAT of (cnode * cnode * string * string)
| ADD_FEAT of (cnode * string * string)
| DEL_FEAT of (cnode *string)
| NEW_NEIGHBOUR of (string * Edge.t * pid)
......@@ -35,7 +35,7 @@ module Command = struct
| H_DEL_EDGE_EXPL of (gid * gid *Edge.t)
| H_DEL_EDGE_NAME of string
| H_ADD_EDGE of (gid * gid * Edge.t)
| H_CPY_FEAT of (gid * gid * string)
| H_COPY_FEAT of (gid * gid * string * string)
| H_ADD_FEAT of (gid * string * string)
| H_DEL_FEAT of (gid *string)
| H_NEW_NEIGHBOUR of (string * Edge.t * gid)
......@@ -96,8 +96,9 @@ module Command = struct
| [node_1; feat_name_1] ->
begin
match Str.split (Str.regexp "\\.") feat2 with
| [node_2; feat_name_2] when feat_name_1 = feat_name_2 -> (CPY_FEAT (get_pid node_1, get_pid node_2, feat_name_1), loc)
| [node_2; feat_name_2] -> Log.fcritical "[GRS] Copy feat through different feature name not implemented %s" (Loc.to_string loc)
| [node_2; feat_name_2] (* when feat_name_1 = feat_name_2 *) ->
(COPY_FEAT (get_pid node_1, get_pid node_2, feat_name_1, feat_name_2), loc)
(* | [node_2; feat_name_2] -> Log.fcritical "[GRS] Copy feat through different feature name not implemented %s" (Loc.to_string loc) *)
| _ -> Log.fcritical "[GRS] \"%s\" is not a feature %s" feat2 (Loc.to_string loc)
end
| _ -> Log.fcritical "[GRS] \"%s\" is not a feature %s" feat1 (Loc.to_string loc)
......
......@@ -15,7 +15,7 @@ module Command : sig
| DEL_EDGE_EXPL of (cnode * cnode *Edge.t)
| DEL_EDGE_NAME of string
| ADD_EDGE of (cnode * cnode * Edge.t)
| CPY_FEAT of (cnode * cnode * string)
| COPY_FEAT of (cnode * cnode * string * string)
| ADD_FEAT of (cnode * string * string)
| DEL_FEAT of (cnode *string)
| NEW_NEIGHBOUR of (string * Edge.t * pid)
......@@ -29,7 +29,7 @@ module Command : sig
| H_DEL_EDGE_EXPL of (gid * gid *Edge.t)
| H_DEL_EDGE_NAME of string
| H_ADD_EDGE of (gid * gid * Edge.t)
| H_CPY_FEAT of (gid * gid * string)
| H_COPY_FEAT of (gid * gid * string * string)
| H_ADD_FEAT of (gid * string * string)
| H_DEL_FEAT of (gid *string)
| H_NEW_NEIGHBOUR of (string * Edge.t * gid)
......
......@@ -302,13 +302,14 @@ module Graph = struct
Some {se_graph with map = new_map}
| None -> None
let cpy_feat graph src_id tar_id feat_name =
(* TODO: with copy_feat from different feature name, correctness of fs wrt domain can be broken: add the check against domain *)
let cpy_feat graph src_id tar_id src_feat_name tar_feat_name =
let src = IntMap.find src_id graph.map in
let tar = IntMap.find tar_id graph.map in
let new_f =
try Feature_structure.set_feat feat_name
(Feature_structure.get feat_name src.Node.fs) tar.Node.fs
with Not_found -> Log.fcritical "[RUN] [Graph.cpy_feat] no feature \"%s\" in node \"%s\"" feat_name (Node.to_string src) in
try Feature_structure.set_feat tar_feat_name
(Feature_structure.get src_feat_name src.Node.fs) tar.Node.fs
with Not_found -> Log.fcritical "[RUN] [Graph.cpy_feat] no feature \"%s\" in node \"%s\"" src_feat_name (Node.to_string src) in
{graph with map = IntMap.add tar_id {tar with Node.fs = new_f} graph.map}
let add_feat graph node_id feat_name feat_value =
......
......@@ -54,9 +54,9 @@ module Graph : sig
val merge_node : Loc.t -> t -> int -> int -> t option
val shift_edges : Loc.t -> t -> int -> int -> t
(** [cpy_feat src_id tar_id feat_name] copy the feature value associated with [feat_name] from
the node [src_id] to the node [tar_id] *)
val cpy_feat : t -> int -> int -> string -> t
(** [cpy_feat src_id tar_id src_feat_name tar_feat_name] copy the feature value associated with [src_feat_name] from
the node [src_id] to the node [tar_id] with feature name [tar_feat_name] *)
val cpy_feat : t -> int -> int -> string -> string -> t
val add_feat : t -> int -> string -> string -> t
val del_feat : t -> int -> string -> t
......
......@@ -83,16 +83,20 @@ module Feature_structure = struct
(function Feature.Equal (f, _) | Feature.Different (f, _) when f=main -> true | _ -> false)
t
) with
| Feature.Equal (_,[ph]) | Feature.Different (_,[ph]) -> Str.global_replace (Str.regexp_string "//PV//") ";" ph
| Feature.Equal (_,[ph]) | Feature.Different (_,[ph]) ->
Str.global_replace (Str.regexp_string "//PV//") ";"
(Str.global_replace (Str.regexp_string "//AND//") "&" ph)
| _ -> raise Not_found
with Not_found -> "" in
let fs =
Str.global_replace (Str.regexp_string "//PV//") ";"
(Str.global_replace (Str.regexp_string "__") ":C:"
(List_.to_string string_of_feature "#"
(List.filter
(function Feature.Equal (f, _) | Feature.Different (f, _) when f=main -> false | _ -> true) t)
)
(Str.global_replace (Str.regexp_string "//AND//") "&"
(Str.global_replace (Str.regexp_string "__") ":C:"
(List_.to_string string_of_feature "#"
(List.filter
(function Feature.Equal (f, _) | Feature.Different (f, _) when f=main -> false | _ -> true) t)
)
)
) in
match fs with
| "" -> Printf.sprintf " word=\"%s\"; " wordform
......
......@@ -165,7 +165,7 @@ module Rule = struct
{
Deco.nodes = List.fold_left
(fun acc -> function
| (Command.CPY_FEAT (tar_cn,_,_),loc)
| (Command.COPY_FEAT (tar_cn,_,_,_),loc)
| (Command.ADD_FEAT (tar_cn,_,_),loc)
| (Command.DEL_FEAT (tar_cn,_),loc)
| (Command.SHIFT_EDGE (_,tar_cn),loc) ->
......@@ -397,13 +397,13 @@ module Rule = struct
| None -> raise Command_execution_fail
)
| Command.CPY_FEAT (tar_cn,src_cn,feat_name) ->
| Command.COPY_FEAT (tar_cn,src_cn,tar_feat_name, src_feat_name) ->
let src_gid = node_find src_cn in
let tar_gid = node_find tar_cn in
(
{instance with
Instance.graph = Graph.cpy_feat instance.Instance.graph src_gid tar_gid feat_name;
commands = List_.sort_insert (Command.H_CPY_FEAT (tar_gid,src_gid,feat_name)) instance.Instance.commands
Instance.graph = Graph.cpy_feat instance.Instance.graph src_gid tar_gid src_feat_name tar_feat_name;
commands = List_.sort_insert (Command.H_COPY_FEAT (tar_gid,src_gid,tar_feat_name,src_feat_name)) instance.Instance.commands
},
created_nodes
)
......
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