Hello List,

I have a problem with a query that I have written. For an Automatic Course Scheduling System, I have created a query that checks each fact in the working memory (which is a shadow fact of a Java-Course-object) for the instructor name. Unfortunately, something goes wrong, but I don't know what. Another query that finds all courses starting at the same time works, though.

Let me show you an example. I am running the following code in a main-method in a random class:

First, I create an Rete-object, an array that stores my query-results and a vector of courses.

   try {
       Rete r = new Rete();
       QueryResult[] results = new QueryResult[2];
       Vector<Course> courseVector = new Vector<Course>();

I fill the vector with plain old java Course-objects. The first field in each course is an course-ID (int), the second is the start time (int) and the last one is the Instructor (String). Nothing else is in the class (besides the get-methods for the above fields).


       courseVector.addElement(new Course(1,  800, "Hawkins"));
       courseVector.addElement(new Course(2, 800, "Einstein"));
       courseVector.addElement(new Course(3, 1000, "Hawkins"));
Then, I define the Course-class in Jess and add the Course-objects as shadow-facts to the working memory.


       r.defclass("Course", "AutomaticScheduler.engine.Course", null);
for (int i = 0; i < courseVector.size(); i++) {
           r.definstance("Course", courseVector.elementAt(i), false);
       }
After that, I define the queries... one for the start-time-collision-detection and one to show every course by the same instructor.

r.eval("(defquery detect-starttime-collision (declare (variables ?var)) (Course (time_start ?var) (CRN ?crn)))"); r.eval("(defquery find-instructor (declare (variables ?var)) (Course (instructor ?var) (CRN ?crn)))");

I run the queries and store the results in the array.
results[0] = r.runQueryStar("detect-starttime-collision", new ValueVector().add(800)); results[1] = r.runQueryStar("find-instructor", new ValueVector().add("Hawkins"));

Last, but not least, for every position in the array, I print out the position number and the outcome of the result. At the end, it is necessary to catch some exceptions, of course. for (int i = 0; i < results.length; i++) {
           System.out.println("results[" + i + "]:");
           while (results[i].next()) {
System.out.println(results[i].getString("crn") + " " + results[i].getString("var"));
           }
       }
   }
   catch (JessException je) {
       je.printStackTrace();
   }
   }

So far so good. When I execute the code, the following lines are output to the console:

results[0]:
1 800
2 800
results[1]:

That's it! The two courses with "Hawkins" as the instructor do not come up! Although the result[] at position 1 is NOT null, it seems to be empty; i.e. no course with that instructor name can be found. This is still the case, if I do not query for the start time and/or when I FIRST query for the instructor, THEN for the start time.
Actually, I expected the following as the output:

results[0]:
1 800
2 800
results[1]:
1 "Hawkins"
3 "Hawkins"

What is wrong? I believe it has got something to do with the fact that I am query-ing for a String instead of an int (because the two queries are basically the same). I really appreciate any help I can get because at this point I seem not to be able to see the forest due to all the trees ;-)

Thank you very much in advance for your help!

Bastian

Reply via email to