rules = Rools::RuleSet.new do
rule 'Hello' do
parameter String
consequence { puts "Hello, Rools!" }
end
rule 'Morning' do
parameter Integer
consequence { puts "Morning Rools !" }
end
end
puts "1 :"
rules.assert 'Heya'
rules.delete_facts
puts "2 :"
rules.assert -12
with the following output:
1 :
Hello, Rools!
2 :
Morning Rools !
Hello, Rools!
It appears that asserting an integer also triggers the string rule.
The reason is that assertions are cumulative. Facts get added to the
blackboard. Therefore during the second evaluation, Rools had to
evaluate the rules against 2 known facts and 2 rules triggered.
IF this is not the desired behavior, you can clear the fact list
using:
rules.delete_facts
I hope this helps. I will try to clarify this in the documentation...
V/R,
Pat.
Hi Pat,
thanks for taking the time to explain.
I hope to have some time to play with Rools this week.
Best regards,
--
John Mettraux -///- http://jmettraux.openwfe.org
Just a quick additional comment here - and please correct me if I'm
wrong.
Using delete_facts will delete all the facts, including those
specified "as part of the RuleSet". I'm referring to facts that are
created in code as part of the RuleSet definition as in the RDoc
example (pasted below).
require 'rools'
rules = Rools::RuleSet.new do
facts 'Countries' do
["China", "USSR", "France", "Great Britain", "USA"]
end
rule 'Is it on Security Council?' do
parameter String
condition { countries.include?(string) }
consequence { puts "Yes, #{string} is in the country
list"}
end
end
rules.assert 'France'
I've moved these facts outside the RuleSet definition in my
application to get past having to reload the rule from a file before
each execution even though they are of a more permanent nature than
the facts created when one calls #assert. it would be nice to be able
to reset a rule to it's original state without losing all the facts.
Pierre
Pat.
We'll stick to loading all the facts after loading the rule from file
and after every 'reset' for now. It's not the cleanest implementation
since the ruleset doesn't encapsulate everything it should and
requires the calling program to know all the information used by the
rule(s) and where to find it, but it is workable.
Cheers,
Pierre
On Jul 16, 2:04 pm, Pat Cappelaere <cappela...@gmail.com> wrote:
> If you reload the ruleset that contains rules+facts, doesn't it have that
> same effect?
>
> Pat.> From: Pierre <pierre.vandenb...@gmail.com>