Question

Is there a way to get a list of rules that have been added to an ERESYE rules engine? Imagine I have a function like this:

start () ->
  eresye:start(engine),
  eresye:add_rule(engine, {module, a_rule_function}),
  eresye:add_rule(engine, {module, another_rule_function}),
  %% do some other stuff
  ok.

Is there a way, given the name of the engine, to retrieve an array of all the rule functions that have been added? I could keep track of this myself but it would be easier if I could just do something like eresye:list_rules(engine).

Thanks in advance!

Was it helpful?

Solution

Looking at the source code, it looks like the rules are stored in the form of a eresye_tree_list in the process state. You could fetch the entire "rete" and extract the tree with something like:

[_, _, Tree, _, _] = eresye:get_rete(engine).

Then, you could use the functions from the eresye_tree_list module to traverse the Tree and to convert it into a list. It probably makes sense to implement this as part of the eresye module itself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top