Hi Celine,
The manual still needs more detail on this. It does include examples
of working with defqueries both in Java and Jess, but they're not
explained very well. Here's a better explanation:
The items returned by Iterator.next() are jess.Token objects. (see
manual section 4.9):
(bind ?token (call ?listeOrdres next))
The jess.Fact (manual section 4.7) matched by patterns on your rule's
LHS will start at index 1 within the token. If there's only one
pattern, as here, then you can get the jess.Fact object with
(bind ?fact (call ?token fact 1))
Now you've got a jess.Fact. I think you're saying that (order) is a
defclass, so this jess.Fact is a "shadow fact." It has an OBJECT slot
that contains the actual Java "order" object that was
definstanced. You can retrieve this with fact-slot-value:
(bind ?order (fact-slot-value ?fact OBJECT))
Then your code below for fetching the properties of ?order is
correct.
I think =?iso-8859-1?Q?LOUIS_C=E9line?= wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
> Hello jess users.
> I am evaluating jess for using it in online-trading.
> I have a java class called "order" in my jess code, which has
> "order_type"(BUY or SELL) and "qty"(number of shares) attributes.Supposing a
> client has made several buy orders on the same share, I want to sum all
> quantities of these orders. I made a defquery which returns all buy or sell
> orders. The problem is that when I get the elements of the defquery, they
> are not recognized as instances of 'order' class, so I get the following
> error: "No method named 'getQty' found" when I try to call the "getQty"
> method on it.
> Is there a way to cast the elements of a defquery into a class?
> thank you in advance
>
> Celine
>
> here is part of my jess code:
>
> (defquery searchOrders
> (declare (variables ?BUYorSELL))
> (order (order_type ?BUYorSELL)))
>
> (deffunction sumBuyQuantities ()
> (bind ?listeOrdres (run-query searchOrders "BUY"))
> (bind ?result 0)
> (while (?listeOrdres hasNext)
> (bind ?order (?listeOrdres next))
> (bind ?qty (?order getQty))
> (bind ?result (+ ?result ?qty))
> )
> (return ?result)
> )
---------------------------------------------------------
Ernest Friedman-Hill
Distributed Systems Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
Org. 8920, MS 9012 [EMAIL PROTECTED]
PO Box 969 http://herzberg.ca.sandia.gov
Livermore, CA 94550
---------------------------------------------------------------------
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]
---------------------------------------------------------------------