Log time ago with version 5-6 I was doing it as below... It may help...
you can improve further...


Somewhere in java I first introduce the classes to jess...

Class aClass = null;
aClass = Class.forName(classPath + s);
try {
   String shortClassName =
aClass.getName().substring(aClass.getName().lastIndexOf(".")+1,
aClass.getName().length());
   rete.executeCommand("( defclass " + shortClassName + " " +
aClass.getName() + " )");

   } catch (Exception ke) {
          System.out.println("Error: Defclass in Rete");
}

Somewhere I store my instances as hash or vector or something else below
is for old hashtable ... if I create new instance I add to jess as
well...

// define in jess and add to hashtable
        public synchronized void put(Object str, Object simp) {

                synchronized(this) {
                        groupData.put(str, simp);
                        try{
                                Funcall f = null;
                                Object obj = simp;
                                
                                        f = new Funcall( "definstance",
jessList[i] );
                                        f.add(new Value(
simp.getClass().getName(), RU.ATOM ) );
                                        f.add(new Value( simp ) );
                                        f.add(new Value( "dynamic",
RU.ATOM ) );
                                        f.execute(
jess.getGlobalContext( ) );
                                
                        }catch(Exception ex){
                                System.err.println("Error : in hashtable
put to KEngine ! "+ ex);
                        }
                }
        }
// define in jess and remove from hashtable
        public synchronized void remove(Object str) {

                try {
                        synchronized (this) {
                                Object obj = groupData.get(str);
                                groupData.remove(str);
                                Funcall f = null; Value v = null;
        
v = new Value( obj );
                                        f = new Funcall(
"undefinstance", jess );
                                        f.add( v );
                                        f.execute(
jess.getGlobalContext( ) );
                                
                        }
                }catch(Exception ex){
                        System.err.println("Error : in Project hashtable
put to KEngine ! "+ ex);
                }
        }



Then it's simple to write rules in jess

(defrule R1 "for 50-90 mw configuration"
  (Door (name ?name) (otherProperyIfNeededToMatch ?p) (OBJECT ?o))
  (test (eq ?name "A1")) // this can be any test condition with new
version I think....
  =>
  (set ?o state "open" )
)





-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of John Chrysakis
Sent: Wednesday, December 03, 2008 12:38 PM
To: Wolfgang Laun
Cc: [email protected]
Subject: Re: JESS: Updating Specific Shadow Fact


I found getObjects easier since I use jess java api,
so in one class I request some Objects, in another
class I need to get/update only a specific one,
so perhaps the assignment to facts  and the
calling of modify could not be donw in my opinion on
general way.

Anyway, thanks again!

-John-
> You could write a defquery and run this.
>
> Better still, you define a template
>    (deftemplate DoorNameState (slot name)(slot state))
> and a rule
>    (defrule UpdateDoorState
>      ?dns <- (DoorNameState (name ?n)(state ?s))
>      ?d  <- (Door (name ?n))
>  =>
>     (modify ?d (state ?s))
>    (retract ?dns)
> )
>
> To update, just assert a DoorNameState fact.
>
> -W
>



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