There are many different ways you might do this. The classic (if
ugly) solution would be to assert a fact like
(done ?interation ?query)
on the right hand side of this rule, and add a "not" condition for
this fact to the left hand side of the rule; then remove the "no-
loop" declaration. Then the rule would fire only once for each
combination. This is what you usually do in CLIPS and CLIPS-like
systems, but there are a couple of other solutions available in Jess.
Another way would be to use Jess's "accumulate" conditional element;
for each query, you could accumulate all the interactions, then do
the modify on the rule right hand side. Make the rule a no-loop rule,
and that would work fine. I guess the thing you'd accumulate should
be a Jess list; that would make it relatively easy to increment the
list elements, since you'll be summing up three numbers for the three
slots that will be modified.
A third way would be to use a defquery. Use a no-loop rule that
simply matched each query, and then on the RHS of the rule invoke a
defquery which matched all the interactions for that query. Iterate
over them explicitly and then modify the query fact once at the end.
On Dec 30, 2006, at 6:11 AM, rim wrote:
Hi,
I need to write a rule which iterates on 2 sets of facts of different
templates,
below the code
(defrule Compute-Queries-Weights
(declare (no-loop TRUE))
?I <- (Interaction (name ?Iname) (queries $?Iqueries) (w-
browsing ?Iwb)
(w-shopping ?Iws) (w-ordering ?Iwo))
(test (<> (length$ $?Iqueries) 0))
?Q <-(Query (name ?Qname) (w-browsing ?Qwb) (w-shopping ?Qws) (w-
ordering
?Qwo))
(test (member$ ?Qname $?Iqueries))
=>
(printout t ?Iname " " ?Qname crlf)
(modify ?Q (w-browsing (+ ?Qwb ?Iwb)) (w-shopping (+ ?Qws ?Iws))
(w-ordering (+ ?Qwo ?Iwo)))
)
the problem is the following,
without (declare (no-loop TRUE)) there'is a loop on one combination
and with (declare (no-loop TRUE)) once used a fact query is not
used again
in the problem specification a fact 'query' belongs to many facts
'intercation' and needs to be updated from all of them,
thanks and happy new year
--
View this message in context: http://www.nabble.com/iterations-
tf2898209.html#a8097199
Sent from the Jess mailing list archive at Nabble.com.
--------------------------------------------------------------------
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 owner-jess-
[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://www.jessrules.com
--------------------------------------------------------------------
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]
--------------------------------------------------------------------