• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

jess

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

I have developed a Web app which deploys simple use of jess statements, i have stored the jess statements in a clp file which is called by my servlet as follows

******
BufferedReader br = new BufferedReader(new FileReader("points.clp"));
Jesp j = new Jesp(br, rete);
******
however when i come to retirieve parameters from the clp file it doesnt happen i get the following error message



Exception in thread "main" Jess reported an error in routine Context.getVariable


********************************************************
while executing (call ?result).
Message: No such variable result.
Program text: ( ?result ) at line 1.
at jess.Context.getVariable(Unknown Source)
at jess.Variable.resolveValue(Unknown Source)
at jess.v.call(Unknown Source)
at jess.ep.a(Unknown Source)
at jess.Funcall.execute(Unknown Source)
at jess.Jesp.a(Unknown Source)
at jess.Jesp.for(Unknown Source)
at jess.Jesp.parse(Unknown Source)
at jess.Rete.executeCommand(Unknown Source)
at jess.Rete.executeCommand(Unknown Source)
at testjess.main(testjess.java:31)
Press any key to continue...

*****************************************************

bear in mind i have followed the procedure u recommended for sarah which was

Value result = engine.executeCommand("(+ 2 2)");

however since in my case the variable im retrieving is defined in the .clp file and is refered to as result

***********
Value result=rete.executeCommand("(?result)");
**********

can u help me plz

thanks greatly appreciated
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

The executeCommand() method takes a bit of Jess code as an argument. (?result) isn't valid code; you're trying to execute a variable as if it were a function, and of course, it's not. The parentheses around (?result) make it a function call.

So it looks like you've got a value in a variable at the end of your computation in Jess, and you want to get it out into Java. The canonical way to do this is to use the "store/fetch" mechanism; see here for more information on that.
 
hussain mousa
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks alot for the help, that was really fast and helpful, thanks again
 
hussain mousa
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi its me again
sorry to bother u but i tried the fetch and store functionality suggested to me earlier, however when i store from the java code i can retrieve the result from the clp file and the java code itself, however when i store the data which is a simple integer in the clp file i get null when i retrieve it in the java code, the way i store and fetch is shown below.


this works fine
***********
Value result = rete.executeCommand("(store points 232)");
System.out.println(rete.fetch("points"));

***********

when i set it in the clp file as follows, this also works fine
***********
(store result 1)

(fetch result)
***********

HOWEVER WHEN I STORE THE DATA IN THE CLP FILE AS FOLLOWS
***********
(store result 1)

AND ATTEMPT TO FETCH IT AS FOLLOWS

System.out.println(rete.fetch("result"));

i get null which is weird

any help is greatly appreciated
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, most likely the "store" function in the clp file isn't being executed. Is it, for example, on the RHS of a rule that's never actually fired? Use the "watch" facility to get a better idea of what Jess is doing.
 
hussain mousa
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no it isnt and the rule store statement fires, this is the code might give u a better idea i made this to test the store fetch functionality

************
(bind ?ce_points 250)
(bind ?tele_points 260)
(bind ?ic_points 300)
(bind ?result 2)




(store T yyT)

(store b yyya)

(fetch a)

(printout t "(fetch T) "(fetch T)"" crlf)
(printout t "(fetch a) "(fetch b)"" crlf)
******************
 
hussain mousa
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
forgot to mention i also fetch the data in the java program and thats were it doesnt work, it work in the clp file.
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I really can't tell what you're trying to show me. This program stores a few things, fetches "nil" using names (i.e., "a") that were never used for storing anything, and sets a bunch of unused variables.

But anyway, there's a Java program, which you haven't shown me, which runs a Jess program, which you haven't shown me, which stores something under the name "result"; then the Java program fetches that value, and gets "null" -- which means that either the Jess program stored "null", or the "store" never executed. I can't tell you what's wrong if you don't show me what you actually did!

There's actually one more possibility -- are you using multiple jess.Rete objects? Each one has its own separate rulebase, working memory, etc, and separate store used by store/fetch.
 
hussain mousa
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, yeah sorry its just that ive been punching variables in and testing it. ive simplified both programs to the bone for simplicity purposes, however they still dont work and i get null the programs are both listed below.

testjess.clp
********************************************

(store T 3)


(printout t "(fetch T) "(fetch T)"" crlf)

********************************************



c.java
********************************************

import jess.*;
import java.io.*;

public class c
{

public static void main(String[] unused) throws JessException
{
try {


// Create a Jess engine
Rete rete = new Rete();


BufferedReader br = new BufferedReader(new FileReader("testjess.clp"));
Jesp j = new Jesp(br, rete);

System.out.println("T "+rete.fetch("T"));

try
{ // parse and execute one construct, without printing a prompt
j.parse(false);
rete.reset();
rete.run();
}
catch (JessException re)
{
// All Jess errors are reported as 'JessException's.
re.printStackTrace(rete.getErrStream());
}

}catch(IOException e){}
}
}


********************************************
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. The problem is that you're calling fetch() before you read the contents of the file using parse(), so of course fetch() will return null. As I suggested, at the time you call fetch(), the (store) hasn't executed yet.

Just constructing the Jesp object doesn't do anything. You'll need to call parse() in a loop to parse the whole file -- or a far better alternative would just be to use the "batch" function, as in

rete.executeCommand("(batch testjess.clp)");

If you do this, you don't need the Jesp object at all, and the above line will read and execute the whole contents of the file. Then afterwards you can make your fetch() call.

Finally, note that reset() initializes working memory, and run() fires rules. Since you haven't defined any rules or working memory elements, you don't need either of these here.
 
hussain mousa
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks ever so much for your help.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic