Hi Nirajkumar,
As the saying goes, "...you can't get there from here."

First, you'd be better off learning Jess from its command line scripting
environment, then move to programming the API when you have the basics
mastered.

In your example, you have a few things incorrect:

1. You need to use the Jess (reset) command before running the rule engine.
2. Only rules in the module having the focus will activate and fire,
provided that their left-hand side (LHS) patterns are satisfied.  In this
case, your (test ...) fact is always TRUE, but you don't have the right-hand
side (RHS) doing anything (so you won't see any effect of the rule firing if
it did, other than what the (watch) command produces.
3.  Use "eq" to compare symbols, objects, and references.  Use plain vanilla
"=" for numbers.  The danger is that you could write some code like:

  (bind ?x 2)
  (bind ?y 2.0)
  (if (eq ?x ?y) then ...

expecting the condition to be TRUE, but it is really FALSE.  Jess is
comparing both value AND type, and since an INT is never the same type as a
FLOAT, the condition is false.  If you had said (= ?x ?y) then it would have
been TRUE.  You can easily prove this yourself by running this program:

;; is-equal-or-not.clp
(clear)
(watch all)
(defrule is-equal-or-not
"Will always fire since it matches the (MAIN::initial-fact)"
=>
  (bind ?x 2)
  (bind ?y 2.0)
  (printout t "x eq y :" (eq ?x ?y) crlf)
  (printout t "x = y :" (= ?x ?y) crlf))
(reset)
(run)

Back to your example, I'd recommend this approach instead:

1. Copy this sample code below, and save it as test.clp in the same folder
as jess.jar or somewhere on Jess's CLASSPATH.

;; test.clp ;;;;;;;;;;;;;;;;;;;;;
(clear)
(defrule equality-test
  (test (= 1 1))
=>
  (printout t "equality test performed OK" crlf))
(reset)
(focus MAIN)
(run)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

2.  Run it by typing (batch test.clp) at the Jess command line. You should
see something like:

  Jess> (batch test.clp)
  MAIN::equality-test: +1+1+2+t
   ==> Focus MAIN
   ==> f-0 (MAIN::initial-fact)
  ==> Activation: MAIN::equality-test :  f-0,
  FIRE 1 MAIN::equality-test f-0,
  equality test performed OK
   <== Focus MAIN
  1
  Jess>

My point is:  Keep working many small examples like this until you are
comfortable with the Jess language, then try writing Java with the Jess API.
You'll learn Jess much better and more quickly.

Oh... and buy a copy of "Jess In Action"
http://www.manning.com/friedman-hill !

Cheers,

-Jason
------------------------

Jason Morris
Morris Technical Solutions
[EMAIL PROTECTED]
www.morristechnicalsolutions.com
fax/phone: 503.692.1088




> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Behalf Of nirajkumar motwani
> Sent: Monday, August 02, 2004 2:33 PM
> To: [EMAIL PROTECTED]
> Subject: JESS: new to jess
>
>
> Hi All,
> I am new to using jess and was having some problems when i wrote
> a small java code...
> when i do the following (below is part of the code), i donot get
> any fired rules, why is that:
> ...
> engine.executeCommand("(watch rules)");
> String rule3 ="(defrule euality-rule (test (eq 1 1)) => )";
> engine.executeCommand(rule3);
> engine.executeCommand("(run)");
> System.out.println("run command executed...");
> ...
>
> The system.out statement is printed but thw watch rules does not
> indicate that any rule was fired? what am i doing wrong?
>
> Thanks
>
> Nirajkumar Motwani
> Graduate Student
> Computer Science Department
> University Of Southern California
>

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