Hello everyone again,
so, I figured out that my problem is probably not solveable the way I
approached it. So, I thought, in order to query every single element in
the Vector (reminder: which is a property of a shadow fact) to check
whether or not it is equal to a given argument, I would need to query
the Vector as a multislots. But, Vectors of shadow facts are not
multislots. Arrays, however are. Before I continue and re-write the
whole object and change the Vectors to arrays, please let me know if my
train of thought here is wrong to begin with...
Following the Jess documentation, I could write a query that checks if
one given argument is in a multislot like this:
(defquery my-query (declare (variables ?param)) (myObject (myArray $?
?param $?) (id ?objectID)))
Running this query should give me every fact in the working memory that
has the variable param as an element in myArray, right?
As you might imagine, I would like to omit changing the object, so is
there another way to do that?
I am really sorry to bother all you guys with my problem, but I am
really eager to get this done, and looking into the Docs did not help me
further than that...
Have a great day,
Basti
Ernest Friedman-Hill wrote:
> If your Java object contains a Vector as a property, then it won't
> match a ValueVector; the Jess fact's slot will just contain the
> Vector. Since Vector implements equals(), the proper query parameter
> would be just "new Value(myVector)".
>
> The NPE is probably happening because you're not calling hasNext() on
> the QueryResult first to check whether or not next() will advance to
> a valid record.
>
> On Apr 13, 2007, at 5:30 PM, B. Tenbergen wrote:
>
>> Hello List,
>>
>> I am not sure if I am using Jess right in my little application. I
>> have written some code to query an Java Object's (the objct was
>> asserted to Jess's Working Memory) variable that happens to be a
>> java.util.Vector. What I essentially want to do is to check if each
>> element in a given argument-list is element of the Vector of the
>> Java object.
>>
>> In order to do that, I believe that the argument-list needs to be
>> added to a ValueVector so that I can run a query*, right? The
>> argument-list must then be a Value of type RU.LIST. So, I add each
>> element of the argument-list to a ValueVector, create a Value by
>> using the constructor that takes a ValueVector and an int (i.e.
>> RU.LIST) and add that Value to a new ValueVector.
>> Is that the right procedure? It seems a little redunant to me to
>> create add a Value, that consists of a ValueVector to a
ValueVector...
>>
>> However, here is some code I have written to accomplish this task.
>> The object looks like this:
>>
>> public class myObject {
>>
>> Vector<String> myVector = new Vector<String>();
>>
>> ...
>> }
>>
>> And here is the code, I wrote to query this vector:
>>
>> Rete r = new Rete();
>> myObject o = new myObject();
>>
>> r.defclass("myObject", "PATH/TO/myObject.class", null);
>> r.definstance("myObject", o, false);
>> r.eval("(defquery myQuery (declare (variables ?var)) (myObject
>> (myVector ?var) (crn ?crn)))");
>> ValueVector vv = new ValueVector();
>>
>> for (int i = 0; i < parameters.length; i++) {
>> vv.add(new Value(parameters[i], RU.STRING));
>> }
>> ValueVector vv2 = new ValueVector();
>> vv2.add(new Value(vv, RU.LIST));
>> QueryResult result = r.runQueryStar
>> ("myQuery", vv2);
>>
>> "parameters" is the argument-list I have mentioned above.
>> The code compliles and executes. However, when I try to access the
>> QueryResult-object, I always get a NullPointerException.
>> Unfortunately, I am not sure if this is because I pass the wrong
>> ValueVector to the query of because none of the elements in the
>> argument-list are in the slot... (that argument-list is passed from
>> another program into my application and the Java object is created
>> elsewhere too, so I have no influence about it...).
>>
>> I would greatly appreciate any help that can tell me if I am on the
>> right track.
>> Thank you all very much in advance!
>>
>> Bastian
>>
>> --------------------------------------------------------------------
>> 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 owner-jess-
>> [EMAIL PROTECTED]
>> --------------------------------------------------------------------
>
>
> ---------------------------------------------------------
> 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]
--------------------------------------------------------------------