Hi Ernest,

I believe this is just another instance of the "a-STRING-is-not-a-SYMBOL"
problem.

I have been avoiding commenting on this thread because I still think that
strings and symbols should be kept separate, though I can certainly
understand the opposing view.

FWIW -- One of the things that I like about how you've constructed the Jess
language is that it is ... pure.  That is to say it is uncluttered by
schizophrenic overloading; it's not dripping with syntactic sugar or
labyrinths of esoteric complexity -- Perl comes to mind.  It seems to me
relaxing language paradigms like this is a slippery slope -- where does it
end?  It is this cleanliness of syntax and grammar that make programming in
Jess fun, like Java is to me as well.

It is not so much for a Jess user to learn to properly apply symbols vs.
strings.  In fact, I've mentioned in the past that Jess's ability to compute
symbolically (as opposed to trying to compute everything with database-like
data) is one of it's under appreciated strengths.  I'd even go so far as to
suggest that newbies learn symbolic reasoning before they attempt more
complicated pattern matching.  The analogy that comes to mind is how I was
taught algebra and physics:  solve the problem symbolically first, then
substitute your data to find a numerical solution.  I think this is one
reason why so many people seem to overlook using the connective and
predicate constraints in Sec 6.3 and instead rely on (test).

My $0.02.

Cheers,
Jason

-----------------------------------------------------------
Jason C. Morris
Worcester Polytechnic Institute     Phone: (508) 831-5006
Department of Computer Science      FAX:   (508) 831-5776
Fuller Laboratories - Room 312      [EMAIL PROTECTED]
Artificial Intelligence Lab (AIRG)
100 Institute Road
Worcester, MA 01609-2280
-----------------------------------------------------------


On 3/7/07, Ernest Friedman-Hill <[EMAIL PROTECTED]> wrote:

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




--

Reply via email to