I think Brad Cox, Ph.D. wrote:
> On Fri, 2003-07-25 at 08:13, [EMAIL PROTECTED] wrote:
>
> > Now, I'm not really sure where JUnit fits in.
>
> You're absolutely right. Java/Jess conditionals should suffice.
>
> Thanks for the boost! Hope you don't mind some follow-on questions.
>
> The main one being, I don't understand why the deftemplate rule is
> needed. I know that's Jess's way of defining a jess object with a slot
> (instance var) for the object under test. Is that "just the way it has
> to be in Jess" or is there a deeper reason? In any event, I'd never have
> guessed this on my own, so thanks!
No that's just how it is. I thought that in a fully developed design,
that template might have other slots: a code or name or other
designation for the object, for instance, and perhaps the test
results.
>
> Style question: I got the JessInsideJava style from the examples
> but understand many permutations are possible. Would you recommend this
> style for this application, i.e. where the defrule section will grow
> interminably?
Well, there are two different ways you could go. One would be to have
a small set of very general rules, and represent the tests as
data. This might make sense if there will be a very large set of
tests. The downside is that the whole system will be harder to
understand. The way I wrote it, where each test is a rule, is similar
to how you do things in JUnit, and it's nice because each rule has a
descriptive name, perhaps a comment, and you can easily refine the
test as needed. The problem with the data-driven approach is you have
to figure out every possible thing that could be tested, and have a
way to represent it in the data -- this could be tricky.
>
> Finally, it compiled, ran, but the "subject passes" rule didn't fire.
> Any advice on debugging tips would be great. Feel free to blow me off on
> this one; I'm sure I saw it in the dox somewhere.
The major reason this doesn't work is that the "reset()" call will
erase all of working memory, then assert the (initial-fact) fact. This
erasing includes the test-subject fact you asserted earlier, so
there's nothing for the rule to match. There may be other problems,
but that's the first thing to fix. Assert the fact after the reset,
not before.
Note that it's a lot easier to have all the Jess code in a file and
use executeCommand("(batch myfile.clp)"). In fact, while you're
developing, it's easier to have everything in a file and execute it
from the Jess> prompt using jess.Main. Once it's working, then you can
go ahead and embed it in Java code, if you like.
>
> Here's what I made of what you sent
>
> package edu.virtc.gauges;
> public class Helmet implements MilitaryEquipment
> {
> public Helmet()
> {
> super();
> }
> public double getWeight()
> {
> return 5.0;
> }
> }
> =========
> package edu.virtc.gauges;
> public interface MilitaryEquipment
> {
> double getWeight();
> }
> ==========
> package edu.virtc.gauges;
>
> import jess.JessException;
> import jess.Rete;
>
> public class Rules
> {
> public static void main(String[] argv)
> {
> try
> {
> Rete rete = new Rete();
>
> rete.executeCommand(
> "(deftemplate test-subject (slot object))"
> );
> rete.executeCommand(
> "(assert (test-subject (object (new
> edu.virtc.gauges.Helmet))))"
> );
> rete.executeCommand(
> "(deffunction compareWeights (?n1 ?n2)\n"+
> " (return (< (call Math abs (- ?n1 ?n2))
> 0.000001)))\n"
> );
> rete.executeCommand(
> "(deffunction computeWeight (?o)\n"+
> " (return 5.00))\n"
> );
> rete.executeCommand(
> "(defrule test-get-weight\n"+
> " (test-subject (object
> ?o))\n"+
> " (test (instanceof ?o
> edu.virtc.gauges.MilitaryEquipment))\n"+
> " (test (compareWeights
> (?o getWeight) (computeWeight ?o)))\n"+
> " =>\n"+
> " (printout \"Subject
> passes getWeight test\" crlf))\n"
> );
> rete.reset();
> rete.run();
>
> // System.out.println("The answer is NOT: " +
> rete.fetch("RESULT"));
> }
> catch (JessException re)
> {
> re.printStackTrace();
> }
> }
> }
>
> --------------------------------------------------------------------
> 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
Distributed Systems Research 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]
--------------------------------------------------------------------