Well, there's at least one thing wrong with the code you show below:
you're creating an ordered fact using the __data slot, which is
correct, but you're setting its value to an atom, which is not. __data
is a multislot, so you have to set the slot value to a ValueVector
containing the slot values, as an RU.LIST -- i.e., something like
ValueVector slot = new ValueVector();
slot.add(new Value(val, RU.ATOM));
f.setSlotValue("__data", new Value(slot, RU.LIST));
Jess's behavior in the face of the code below is undefined.
I think Jerry Hoe wrote:
> Hi,
>
> I am stucked here for too long and can't resist making a post here. Hope that
> someone can clear my mind.
>
> I have written the following code segment in my program. Basically, what I
> want to do is just:
>
> 1) Bind a hashtable to a global variable.
> 2) Run the rules.
> 3) Access the results in the hashtable from inside the program.
>
> I am getting some unexpected results when I run the program. The story
> begins here. The program returns me 4 elements in the hashtable.
> Unconvinced, I tried running the following Jess commands exactly in
> the same sequence using the same files in the Jess console. Executing
> the commands directly in the Jess environment returns me the results
> that I am expecting.
>
> Can someone please explain to me why I am getting inconsistent results?
> I am short of ideas now... :(. Thanks in advance!
>
> engine.executeCommand("(batch ../rules/scriptlib.clp)");
> engine.executeCommand("(defglobal ?*result* = (new java.util.Hashtable))");
> engine.executeCommand("(batch ../rules/axis1.clp)");
> engine.reset();
> while (/*more facts*/) {
> Fact f=new Fact(fact, engine);
> f.setSlotValue("__data", new Value(val, RU.ATOM));
> engine.assert(f);
> }
> engine.run();
> Context env=engine.getGlobalContext();
> Value val=env.getVariable("*result*");
> Hashtable results=(Hashtable)val.externalAddressValue(env);
>
> --
> Regards,
> Jerry
>
>
> ---------------------------------------------------------------------
> 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
Org. 8920, MS 9012 [EMAIL PROTECTED]
PO Box 969 http://herzberg.ca.sandia.gov
Livermore, CA 94550
---------------------------------------------------------------------
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]
---------------------------------------------------------------------