In general, the right way to do things in a rule- based system is to match the facts in a rule, and allow the rule to fire however many times it needs to to complete its task; i.e., instead of a while loop, consider a rule that fires once for each fact.

But if you want to use a while loop, then use a query to find all the matching facts at once. See http://herzberg.ca.sandia.gov/docs/70/ queries.html .

By the way, I don't know what's up with your Userfunction. The variable "?m" will contain the jess.Fact object itself; the two method calls you show in the call() method seem as though you feel you need to search for this object, but you don't; it's already in the argument to the function.


On Feb 25, 2007, at 2:34 PM, Kenan Bilic wrote:

Hello. I have some problems with Jess Facts. I developed a small Ontologie in Protege. With the function mapclass I connect these with Jess. So far so well, now I want to send each Fact to Java. I have e.g. 10 Facts, and I would like to send these to Java. Is there a possibility facts in one while loop successively to send.


I have made an example with one fact and implemented one Userfunction in Java. With this I call a (send ?m) in Jess.

Jess:

 ?m <- (ACLMessage (sender ?n)...............)
 (send ?m)

Java:

public String getName() {
            return ("send");
        }


        public Value call(ValueVector vv, Context context)
            throws JessException {

            if (vv.get(1).type() == RU.VARIABLE) {
             vv.get(1).factValue(context).getFactId());

                vv = context.getEngine().findFactByID(vv.get(1)
.factValue (context)
                                                        .getFactId());

            }


This work with one Fact. How can I send now 10 Facts?
Each Fact has an ID. But I can not read them in Jess. I would like to use an while loop like this.
i=0;
while (i !=9){

        send fact_by_id(i);

i++
}

Is this possible in Jess.


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