Thank you for the quick reply.
But then again, I can avoid salience if I combine your approach with
module definitions.
For instance:
(defrule default-rule
?a <- (a)
(not (processed ?a))
=>
(default-action)
(assert (processed ?a))
)
(defmodule m)
(defrule m-rule
?a <- (a)
(not (processed ?a))
=>
(special-action)
(assert (processed ?a))
)
(assert (a))
(focus m)
(run)
Is this a bad idea?
It seems to fit my purpose, since I may have lots of rules that are best
organized with modules, which conceptualy correspond to contexts that
are created in run-time. Therefore, when a fact arrives (which is
defined using a deftemplate that contains a slot named "context") I
focus on the corresponding module (which was previously created).
Something like:
(defrule change-focus
(foo (context ?ctx))
=>
(focus ?ctx)
)
(defrule default-rule
?foo <- (foo)
(not (processed ?foo))
=>
(default-action)
(assert (processed ?foo))
)
Should I avoid this by using auto-focus? By the way, can I apply the
auto-focus property to all rules inside a module at once, or must I
define this property in every rule inside a module?
Henrique
---
[EMAIL PROTECTED] wrote:
You don't need to avoid salience at all costs; you should avoid
excessive use of it, and you should avoid trying to force all rules to
fire in some specified order using it.
The higher-priority rules need to make some change in working memory
that the lower-priority rules can detect. For example
(defrule default-rule
?a <- (a)
(not (processed ?a))
=>
(default-action)
(assert (processed ?a)))
(defrule special-rule
(declare (salience 100))
?a <- (a)
(not (processed ?a))
=>
(special-action)
(assert (processed ?a)))
For each fact ?a, special-rule will fire, and default-rule won't.
I think Henrique Lopes Cardoso wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
Hi,
I am trying to develop a Jess program that considers the use of default
rules.
Here goes a simple example.
I have a rule in the MAIN module, but I want that rule to fire only if
no other rule fires.
Since the Jess 6 manual discourages the use of salience definitions, I
am thinking on using modules.
That is, I have a module where I have some rules that are meant to fire
when a fact appears in MAIN. If no rule fires, then the default rule in
MAIN should fire.
Example:
(defrule default-rule (a) => (printout t "This is the default rule." crlf))
(defmodule m)
(defrule m-rule (a) => (printout t "This is the rule in m." crlf))
(assert (a))
(focus m)
(run)
Now, both rules fire: first the one inside module m and then the
default-rule in MAIN. If I do not want the default-rule to fire, must I
retract fact (a)?
(defrule m-rule
?x<- (a)
=>
(retract ?x) (printout t "This is the rule in m." crlf)
)
What if I want to keep a history of all the facts?
Thanks.
Henrique
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------
---------------------------------------------------------
Ernest Friedman-Hill
Advanced Software Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
PO Box 969, MS 9012 [EMAIL PROTECTED]
Livermore, CA 94550 http://herzberg.ca.sandia.gov
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------