Commit 5d3bf2f2 authored by bguillaum's avatar bguillaum

matching as a separate function

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/semagramme/libcaml-grew/trunk@8336 7838e531-6607-4d57-9587-6c381814729c
parent 20aeb9d6
...@@ -791,35 +791,49 @@ module Rule = struct ...@@ -791,35 +791,49 @@ module Rule = struct
| x -> false | x -> false
(** [one_step instance rules] computes the list of one-step reduct with rules *) (* ================================================================================ *)
(* ================================================================================ *)
(* ================================================================================ *)
(* ================================================================================ *)
let match_in_graph rule graph =
let pos_graph = rule.pos.graph in
(* get the list of partial matching for positive part of the pattern *)
let matching_list =
extend_matching
(pos_graph,P_graph.empty)
graph
(init rule.param rule.pos) in
let filtered_matching_list =
List.filter
(fun (sub, already_matched_gids) ->
List.for_all
(fun without ->
let neg_graph = without.graph in
let new_partial_matching = update_partial pos_graph without (sub, already_matched_gids) in
fulfill (pos_graph,neg_graph) graph new_partial_matching
) rule.neg
) matching_list in
List.map fst filtered_matching_list
(* ================================================================================ *)
(* ================================================================================ *)
(* ================================================================================ *)
(* ================================================================================ *)
(** [one_step instance rules] computes the list of one-step reduct with rules *)
let one_step instance rules = let one_step instance rules =
List.fold_left List.fold_left
(fun acc rule -> (fun acc rule ->
let pos_graph = rule.pos.graph in let matching_list = match_in_graph rule instance.Instance.graph in
(* get the list of partial matching for positive part of the pattern *)
let matching_list =
extend_matching
(pos_graph,P_graph.empty)
instance.Instance.graph
(init rule.param rule.pos) in
let filtered_matching_list =
List.filter
(fun (sub, already_matched_gids) ->
List.for_all
(fun without ->
let neg_graph = without.graph in
let new_partial_matching = update_partial pos_graph without (sub, already_matched_gids) in
fulfill (pos_graph,neg_graph) instance.Instance.graph new_partial_matching
) rule.neg
) matching_list in
List.fold_left List.fold_left
(fun acc1 (matching,_) -> (fun acc1 matching ->
try (apply_rule instance matching rule) :: acc1 try (apply_rule instance matching rule) :: acc1
with Command_execution_fail -> Printf.printf "******\n%!"; acc1 with Command_execution_fail -> acc1
) acc filtered_matching_list ) acc matching_list
) [] rules ) [] rules
(** [conf_one_step instance rules] computes one Some (one-step reduct) with rules, None if no rule apply *) (** [conf_one_step instance rules] computes one Some (one-step reduct) with rules, None if no rule apply *)
......
...@@ -85,4 +85,8 @@ module Rule : sig ...@@ -85,4 +85,8 @@ module Rule : sig
t list -> (* filter list *) t list -> (* filter list *)
Instance.t -> Instance.t ->
Instance_set.t * Instance_set.t Instance_set.t * Instance_set.t
type matching
val match_in_graph: t -> G_graph.t -> matching list
end (* module Rule *) end (* module Rule *)
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