Hi!
If you didn't leave anything out from the code snippet below that piece of
code doesn't work because you never parsed the script (using the batch
command) and reset the engine. The (reset) command will assert the facts
that are declared by the (deffacts ...) construct.
>// here is the code
>Rete r= new Rete();
>//functios
>r.executeCommand("(defglobal ?*v* = (new Vector)) ");
>r.executeCommand("(store RESULT ?*v* )");
>r.executeCommand("(defrule urs (ask (paper one )(code ?z)) \
=> (call ?*v* addElement ?z))
>Vector sk=new Vector();
>sk= (Vector)r.fetch("RESULT").externalAddressValue(null);
>System.out.println("Element 1 " + sk.elementAt (0));
The example below will do what you want.
public void run() throws Exception {
Rete r = new Rete();
// Load script
r.executeCommand("(batch <your-jess-script>)");
// Define rule
// This could also be done in the script above
String rule = "";
rule += "(defrule urs";
rule += " (ask (paper one) (code ?z))";
rule += " =>";
rule += " (call (fetch RESULT) addElement ?z))";
r.executeCommand(rule);
// Create vector and make it accessible to the rule
Vector sk = new Vector();
r.store("RESULT", sk);
// OK, go...
r.reset(); // This will assert the facts
r.run(); // This will fire the rule
// Print result
Enumeration e = sk.elements();
while (e.hasMoreElements()) {
System.out.println("Element = " + e.nextElement());
}
}
The method will produce the following output:
Element = code3
Element = code1
I hope that helped.
Greetings
Thomas
________________________________
Dipl.-Inform. Thomas Barnekow
phone: +49 (0) 172 / 7126018
email: [EMAIL PROTECTED]
devdatt
<devdatt@harrowga An: [EMAIL PROTECTED]
te.co.in> Kopie:
Gesendet von: Thema: JESS: retrieving more
owner-jess-users@ elements from single fetch
sandia.gov
14.07.00 13:47
Bitte antworten
an devdatt
hai all
i am getting a problem in getting the Vector elements.
i have a clip file:
(deftemplate ask (slot paper)(slot code))
(deffacts again (ask (paper one)(code code1))
(ask (paper two)(code code2))
(ask (paper one)(code code3))
(ask (paper one)(code code3)))
in jess file ....
// when i tried to get the elements matched with paper one in rules RHS i
am geting and ArrayIndexOutOfBounds Exception for the vector to where i
want
to store .
// here is the code
Rete r= new Rete();
//functios
r.executeCommand("(defglobal ?*v* = (new Vector)) ");
r.executeCommand("(store RESULT ?*v* )");
r.executeCommand("(defrule urs (ask (paper one )(code ?z)) => (call
?*v* addElement ?z))
Vector sk=new Vector();
sk= (Vector)r.fetch("RESULT").externalAddressValue(null);
System.out.println("Element 1 " + sk.elementAt (0));
// here the elements are not being added and i am getting
arrayindexoutof bounds exception
//any one please help me......
// lots of thanks in advance
Dev.
---------------------------------------------------------------------
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]
---------------------------------------------------------------------