I think that Indira Meshram wrote:
>> I am developing a workflow agent in Jade, using Jess for reasoning, etc.
>> But I'm facing a problem with the 'Value' class, in fetching values from
>> Jess to my Java program.
>> I know its probably a silly mistake, but I'm just beginning to use Jess,
>> so can't quite figure it out
Hi Indira,
In My Humble Opinion: Be sure that you're not "biting off more than you can
chew" -- Jess is complex enough in its own right without adding the
complexity of embedding it in Jade if you're a Jess newbie. If you're not
comfortable with Jess basics, you may want to invest some time studying Jess
a bit more before you build an agent around it. Ironically, I'm actually
studying Jade now, and I'm really glad that I've invested the time in Jess
first -- I wouldn't want to do them both at once.
All that said, I modified your code a bit, and I think I have it working.
My notes are in the code:
;;====================================
;;jade.clp
;; Put this in the same classpath as
;; your MyBasicBehavior class
(watch all)
(defrule match-a-b
"Matches if facts (a) and (b) exist"
;; No need to use (and), Jess does
;; this implicitly
(a) (b)
=>
(store RESULT 1))
;;====================================
import jess.*;
public class MyBasicBehavior {
// Obviously this isn't a true behavior since we aren't
// extending the Behaviour class
private Rete engine;
private String jessfile;
private boolean finished = false;
public MyBasicBehavior() {
// No need to include this now, put it back when you
// extend an abstract Behaviour
//super();
// Pass the class reference to the Rete constructor
// so that Jess can use the classloader to find
// your Jess batch files
engine = new Rete(this);
}
// This is just for testing purposes -- enter "jade.clp" as the argument
public static void main(String[] args) {
if (args.length == 1) {
MyBasicBehavior mbb = new MyBasicBehavior();
mbb.jessfile = args[0];
mbb.action();
} else {
System.err.println("Enter the Jess batch filename!");
}
}
public boolean done() {
return finished;
}
/*
Notice that I'm not using the Jesp class --
Ernest makes the point on pp. 417 of JIA that it is
only for reading from unusual sources.
*/
// I'll just mimic a real behaviour action method.
public void action() {
try {
// Load your rules
engine.executeCommand("(batch " + jessfile + ")");
// Reset working memory
engine.reset();
// Assert your facts
engine.executeCommand("(assert (a))");
engine.executeCommand("(assert (b))");
// Run Jess to process the facts
engine.run();
// Rete store/fetch mechanism
// See pp. 308-309 in Jess In Action
Value v = engine.fetch("RESULT");
int i = v.intValue(engine.getGlobalContext());
System.out.println("The answer is: " + i);
finished = true;
} catch (JessException jex) {
jex.printStackTrace(System.err);
}
}
}
Running this in Eclipse 3.0, Jess 7.0a2 prints out:
MAIN::match-a-b: +1+1+1+1+1+2+t
==> Focus MAIN
==> f-0 (MAIN::initial-fact)
==> f-1 (MAIN::a)
==> f-2 (MAIN::b)
==> Activation: MAIN::match-a-b : f-1, f-2
FIRE 1 MAIN::match-a-b f-1, f-2
<== Focus MAIN
The answer is: 1
Hope this helps!
Cheers,
Jason
----------------------------------------------
Jason Morris - Assistant Moderator
Jess Listserver - [EMAIL PROTECTED]
email: [EMAIL PROTECTED]
www.morristechnicalsolutions.com
fax/phone: 503.692.1088
--------------------------------------------------------------------
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]
--------------------------------------------------------------------