I think [EMAIL PROTECTED] wrote:
>
> //in a file hello.clp
> (defrule startup =>
> (assert (num1 (fetch A)))
> (assert (num2 (fetch B)))
> (assert (num3 (fetch C))) )
>
This is fine
>
>
>
> (defrule sum_rule (cmp ?numb) => (if(> ?numb 10) then (bind ?sum (+ ?sum
> ?numb))))
>
?sum is a local variable defined on the RHS of this rule. Yes, Jess
does have "top-level variables", but they're not globals, and they're
not visible here. If you need a variable to persist across multiple
firings of a rule, you need to use a defglobal -- i.e.,
(defglobal ?*sum* = 0)
and then use ?*sum* on the RHS of your rule.
>
> (assert (cmp num1))
> (assert (cmp num2))
> (assert (cmp num3))
These "cmp" facts contain the symbols "num1", "num2", and "num3"; if
you try to do math on these symbols, you'll get the error shown below.
You're kind of assuming that a fact is like a variable, and you can
somehow pull the data from the "numX" facts here into the "cmp" facts,
but you can't. I can't tell why you're using both numX and cmp, so I
can't tell you exactly what to do, but if you want sum_rule to act on
the facts asserted by the startup rule, then it needs to match those
facts. WHy not have startup simply assert the "cmp" facts as
(assert (cmp (fetch A)))
(assert (cmp (fetch B)))
(assert (cmp (fetch C)))
Then your rule would work (with the defglobal change, of course.
> (store result ?sum)
>
Again, the variable ?sum from the RHS of the rule is not available
here, but a defglobal would be. But in any case, if you batch the
hellop.clp file, this "store" happens before any of the rules
fire. You need to call "run" for any rules to actually fire.
>
> /////////java program
> public static void testAddition() {
> Rete rete = new Rete();
>
> try {
>
> rete.reset();
>
>
> rete.watchAll();
>
>
> rete.store("A",new Value(11, RU.INTEGER));
> rete.store("B",new Value(15, RU.INTEGER));
> rete.store("C",new Value(13, RU.INTEGER));
> rete.executeCommand("(batch hello.clp)");
> System.out.println("rule name"+rete.getThisRuleName());
>
>
> rete.run();
Here you call "run", but the "store" function has already executed,
you see. You could have a low-salience rule that fired after all the
summing was done, and do the store from that.
A final note: Jess 7 has this wonderful new invention called the
"accumulate" conditional element which will allow you to do this sort
of sum over facts all on the LHS of a single rule, and have the full sum
available to the RHS of the same rule.
> Value v = rete.fetch("result");
> System.out.println("value " + v);
>
> } catch (JessException e) {
>
> e.printStackTrace();
> }
>
> }
> //exception
> Jess reported an error in routine Value.numericValue
> while executing (> ?numb 10)
> while executing (if (> ?numb 10) then (bind ?sum (+ ?sum ?numb)))
> while executing defrule MAIN::sum_rule.
> Message: Not a number: "num3" (type = ATOM).
> at jess.Value.a(Unknown Source)
> at jess.Value.a(Unknown Source)
> at jess.Value.numericValue(Unknown Source)
> at jess.Variable.numericValue(Unknown Source)
> at jess.ek.call(Unknown Source)
> at jess.ep.a(Unknown Source)
> at jess.Funcall.execute(Unknown Source)
> at jess.FuncallValue.resolveValue(Unknown Source)
> at jess.dw.call(Unknown Source)
> at jess.ep.a(Unknown Source)
> at jess.Funcall.execute(Unknown Source)
> at jess.Defrule.a(Unknown Source)
> at jess.Activation.if(Unknown Source)
> at jess.a8.a(Unknown Source)
> at jess.a8.int(Unknown Source)
> at jess.Rete.run(Unknown Source)
>
> Any ideas?
>
>
>
>
>
>
> [EMAIL PROTECTED]
>
> .gov To: [EMAIL PROTECTED]
>
> Sent by: cc:
>
> owner-jess-users@ Subject: Re: JESS: running rules
> from java program
> sandia.gov
>
>
>
>
>
> 06/18/04 02:22 PM
>
> Please respond to
>
> jess-users
>
>
>
>
>
>
>
>
>
> I think [EMAIL PROTECTED] wrote:
> >
> > Is there any example of setting the variables in java program for the
> rules
> > in a file and getting the results in java program.
> >
> > I am getting varibales not initialized problem!
> >
>
> You generally don't communicate with Jess by setting variables, but
> rather by asserting facts, or else by putting things in the global
> storage area (see section 4.4.4 of the manual.)
>
>
> ---------------------------------------------------------
> Ernest Friedman-Hill
> Science and Engineering PSEs Phone: (925) 294-2154
> Sandia National Labs FAX: (925) 294-2234
> PO Box 969, MS 9012 [EMAIL PROTECTED]
> Livermore, CA 94550 http://herzberg.ca.sandia.gov
>
> --------------------------------------------------------------------
> 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]
> --------------------------------------------------------------------
>
---------------------------------------------------------
Ernest Friedman-Hill
Science and Engineering PSEs Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
PO Box 969, MS 9012 [EMAIL PROTECTED]
Livermore, CA 94550 http://herzberg.ca.sandia.gov
--------------------------------------------------------------------
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]
--------------------------------------------------------------------