Thank you very much for your eMail. Changing the type of the Value to RU.String brings satisfying results. Boy, that could have taken long for me to find that out, so thanks again for the help!

Bastian

Ernest Friedman-Hill wrote:

I believe this is just another instance of the "a-STRING-is-not-a- SYMBOL" problem. ValueVector.add(String) adds a Value of type RU.SYMBOL to the ValueVector, whereas your JavaBean property is going to be of type RU.STRING. The symbol and the String *don't* match, so the second query returns no results. You want to say

new ValueVector().add(new Value("Hawkins", RU.STRING))

I put it to a vote on the list about 18 months ago whether Jess ought to relax this restriction, and very surprisingly, most people who responded wanted to keep things the way they are; perhaps they misunderstood the question. I may have to make an executive decision on this one and change things anyway.


On Mar 7, 2007, at 5:17 PM, B. Tenbergen wrote:

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


---------------------------------------------------------
Ernest Friedman-Hill
Advanced Software Research          Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
PO Box 969, MS 9012                 [EMAIL PROTECTED]
Livermore, CA 94550                 http://www.jessrules.com

--------------------------------------------------------------------
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]
--------------------------------------------------------------------

Reply via email to