RoolZ QuickStart++

10 views
Skip to first unread message

cappelaere

unread,
Jul 12, 2007, 9:32:32 AM7/12/07
to Rools Users
John Mettraux posted a good example that needs some explanation:

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.

John Mettraux

unread,
Jul 12, 2007, 11:00:19 AM7/12/07
to rools...@googlegroups.com
On 7/12/07, cappelaere <cappe...@gmail.com> wrote:
>
>
> rules.delete_facts

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

Pierre

unread,
Jul 16, 2007, 2:42:30 AM7/16/07
to Rools Users
Hi Pat,

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 Cappelaere

unread,
Jul 16, 2007, 8:04:29 AM7/16/07
to rools...@googlegroups.com
If you reload the ruleset that contains rules+facts, doesn't it have that
same effect?

Pat.

Pierre

unread,
Jul 17, 2007, 2:22:09 AM7/17/07
to Rools Users
Sure, but we have the rules in files for various reasons, and I'd like
to stay away from disk IO if I can since we're looking at a fairly
high volume of transactions that need rules applied. We can go for
something like memcached to cache the files in memory but again that
seems to be a major step for what seems to be a smallish issue.

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>

Reply all
Reply to author
Forward
0 new messages