I am new to rule engines but not to
java. I have been experimenting for about 2 weeks now with Jess 7.1. Specifically I am trying to implement something similar to the Pricing Engine example.
I have the two problems listed below, but really I am just trying to solve #1 but I think that #2 may be a hindrance.
(please see end of this post for relevant code snippets). #1)
Error occurred in Obligation Engine: No such slot availAmount in template MAIN::BalS at token 'availAmount' Every example I try tells me that I don't have the proper slot available, however unless I completely misunderstood the documentation, the whole purpose of the "from-class" construct is that JESS can dynamically analyze java objects and build the required slots, etc.
#2) I thought that perhaps since I changed my original property from "_amount" to "availAmount" (I thought perhaps the underscore was causing issues) that I now need to remove my previously defined template. The API and manual both claim that "removeDeftemplate" is a valid function (it takes a
string argument for the name) however the JESS.jar file I downloaded (from herzberg.ca.sandia.gov) definitely does not support that method.
-------------
My .clp file: ;; templates for the model classes
(import pkgBusinessObjects.*)
(deftemplate BalanceSheet (declare (from-class BalanceSheet)))
;; rules
(defrule Halve-Available-Balance
"Cut the Available Balance in half if its more than 1000"
(BalanceSheet {availAmount > 1000})
=>
(BalanceSheet setAmount((/ ?availAmount 2))))
My Balance Sheet Class: public class BalanceSheet {
public String balAccountCode;
public float availAmount;
public void setAccountCode(String inACC)
{
balAccountCode = inACC;
}
public String getAccountCode()
{
return balAccountCode;
}
public void setAmount(float inAmnt)
{
availAmount = inAmnt;
}
public double getAmount()
{
return availAmount;
}
}
And finally my Engine: public ObligationEngine(BalSht BS, TravelObligation TA)
{
try
{
// Create a Jess rule engine
engine = new Rete();
engine.reset();
// Load the pricing rules
engine.batch("Obligation.clp");
}
catch (Exception e)
{
System.out.println("Error occured in Obligation Engine: " + e.getMessage());
System.out.println("Stack Trace: ");
e.printStackTrace(System.out);
}