There is no '=>' separating the RHS and the LHS in your rule "rule_test".

Processing slots containing a java.util.Vector (or a multislot) requires you to write rather complicated rules. It seems that a simple fact that associates, say, a category name with a *single* charge code, and is used repeatedly leads to simpler rules than a single object with some container slot. Let's assume that you have

  (CustCharge (custId Smith)(chargeId c1A))
  (CustCharge (custId Smith)(chargeId c3B))
  (CustCharge (custId Smith)(chargeId c5C))

which could be easily asserted from your customer object. But I would split the Category objects into a sequence of facts, e.g.

  (CatCust  (catId A)(chargeId c1A))
  (CatCust  (catId A)(chargeId c2A))
  (CatCust  (catId B)(chargeId c3B))
  (CatCust  (catId B)(chargeId c3B))
  (CatCust  (catId C)(chargeId c5C))

Then you could write the rule

 (defrule findCat
   (CustCharge (chargeId ?chargeId))
   (CatCust  ((catId ?catId)(chargeId ?chargeId))
=>
  (assert (Have (catId ?catId)))
)

This would give you a set of Have-facts with the categories Smith has.

Then simple rule defining the required combinations could be written as

 (define ABC
   (Have (catId A))
   (Have (catId B))
   (Have (catId C))
=>
  ...)

It fires if the charge combination is valid; not firing can be detected by throwing in
a fact such as (Failure) which is retracted in ABC.

Kind regards
Wolfgang


JimYates wrote:

Purpose:  To find customer charges that do not have required matching
categories.   Matching requirements can change.
Example:   A charge in category A requires a charge in Category B.  Or a
charge in category A requires a charge in Category B and Category C.
Data structure:    Customer object with customer id, a Vector of customer
charge objects,  Category Object with the category name and a Vector of
charge codes, Customer charge object with charge code, charge description,
etc .

I want to use Jess because the matching rules can be changed and/or added by
the application. There will only be 1 customer at a time in working memory, but all the categories will reside in working memory. The matching rules may require multiple categories. If I were to code this
in Java I would do something
like:
while (customer charges)
if category_A contains customer_charge then cat_a_flag = TRUE
if category_B contains customer_charge then
  cat_b_flag = TRUE
end while
if (cat_a_flag and not cat_b_flag) then
  print "charge missing have A without B
end
while (customer charges)
if category_A contains customer_charge then cat_a_flag = TRUE
if category_B contains customer_charge then
  cat_b_flag = TRUE
if category_C contains customer_charge then
  cat_c_flag = TRUE
end while
if (cat_a_flag and not cat_b_flag and not cat_c_flag) then
  print "charge missing have A without B and without C
end

I'm having trouble designing/coding this in Jess.   Specifically getting the
iterator for the vector of customer charges. I'm basically trying to duplicate the pseudo code above.
(deftemplate Customer "Java Object"
   (declare (from-class com.accuserverx.accucharge.batchprocess.Customer)))
(deftemplate ChargeCategory "Java Object"
   (declare (from-class
com.accuserverx.accucharge.batchprocess.ChargeCategory)))
(deftemplate Charges "Java Object"
   (declare (from-class com.accuserverx.accucharge.batchprocess.Charges)))
(deftemplate flags (slot surgflag (default FALSE)) (slot anestflag (default
FALSE)))
(defrule rule_test
; get customer charge vector of Charges where the vector is not null
   (Customer (customerCharges ?chgVect&:(neq ?chgVect nil)))
; get the iterator for the charge vector to use in the while (bind ?chgitr (?chgVect iterator))

I get a "Bad slot value" error on the second parenthesis in the bind.


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