First off, I assume that there must be more to MyBean than properties A
& B to make the facts unique, otherwise you could never have multiple
MyBean facts with the same propertyA with all propertyB values true.

For your firt premise you could use the (not) construct to exclude any
MyBean instance with a propertyB value other than TRUE.  For the second
premise, I usually use some sort of indicator or 'stop' fact to preclude
further processing, and another (not) construct to disqualify subsequent
activations.

Does the following script demonstrate a possible solution to your
problem?:

(clear)

;; you'll be using defclass here
(deftemplate MyBean (slot propertyA)(slot propertyB)(slot propertyC))

;; and definstance here
(deffacts initial-facts
  (MyBean (propertyA foo)(propertyB true)(propertyC 0))
  (MyBean (propertyA foo)(propertyB true)(propertyC 1))
  (MyBean (propertyA foo)(propertyB true)(propertyC 2))
  (MyBean (propertyA bar)(propertyB true)(propertyC 0))
  (MyBean (propertyA bar)(propertyB true)(propertyC 1))
  (MyBean (propertyA bar)(propertyB false)(propertyC 2)))

;; here is the rule
(defrule process-distinct-a-with-all-b-true
  (MyBean (propertyA ?a)(propertyB ?b&true))
  (not (MyBean (propertyA ?a)(propertyB ?b2&~true)))
  (not (MyBeanProcessed ?a))
=>
  (assert (MyBeanProcessed ?a))
  (printout t "Do something with " ?a crlf)
)

(reset)
(run)

This script processes a single MyBean fact per propertyA value where the
propertyB value of all similar facts are true.

-Mitch

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Carlos Pedrinaci
Sent: Wednesday, January 19, 2005 6:06 AM
To: Lista Jess
Subject: JESS: How to match this set of Beans?


Hi,

I'm currently trying to implement a rule that would support the
following:

Let us imagine the following JavaBean:

MyBean
------
String propertyA
boolean propertyB

(With the accessors, modifiers and propertyChangeListener etc)

I would like to retrieve the value(s) of propertyA for which propertyB
is _always_ TRUE. Moreover, I would like it to match just once per
propertyA.

I have tried to do so in many ways but I don't manage to get it working.
Right now, I just check for the value of propertyB for all the beans,
but this is obviously far from my requirements! I have miserably failed
in any other attempt to approach the problem...

I guess one of my problems is likely to be related to this thread
http://www.mail-archive.com/[email protected]/msg02019.html about
(exists) and variable bindings..

Could anyone point me the right direction?

Thanks in advance,

Carlos



--------------------------------------------------------------------
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]
--------------------------------------------------------------------

Reply via email to