Hi!

> The key question is this:
> Metagraf_object o;
> Metagraf_general_framework g;
> Rete r;
> 
> How can I do this ?
> <Clips side>
> =>
> ( update_the_metagraf_object_x_coordinate  o  20 ) 
> (create_a_metagraf_object g (new Metagraf_object )
> ...

You can't do that for a very simple syntactic reason!!! In Jess (and CLIPS), local 
variables have the form 

        ?<variable-name>, e.g. ?a or ?g. 

By convention, global variables (declared using defglobal) have the form 

        ?*<variable-name>*, e.g. ?*a*.

a and o are simply atoms, not variables.

Now let me sum up the basic interaction techniques first. Some of them have been 
mentioned in preceding messages. I'll use the following declarations for illustration 
purposes:

> Metagraf_object o;
> Metagraf_general_framework g;
> Rete r;

(1) Using Java objects in Jess scripts

Jess provides a very neat Java integration. Basically, you can 

- create objects,
- get and set members, and
- call any method,

no matter how you get hold of the object's reference. An object can be made available 
to the engine by the following means:

- using the Rete::store(String, Object) operation (see store/fetch below)
- defining an instance (see defclass/definstance)
- defining a global variable (see defglobal)
- defining a Userfunction that returns that object (cf. (engine))

In case object creation has to trigger rule execution defining instances is the only 
mechanism you can use. 

> ( update_the_metagraf_object_x_coordinate  o  20 ) 

I'm not sure whether you want/need that update_the_metagraf_object_x_coordinate 
function. Assuming Metagraf_object provides a setXCoordinate method you can also write

        (call ?o setXCoordinate 20)

or even shorter

        (?o setXCoordinate 20)

The Jess variable ?o represents your Java Metagraf_object o that has been made 
available to the engine by one of the mechanisms mentioned above.

(2) store/fetch

Java-side operations

- Rete::store(String, Object) and 
- Rete::fetch(String) : Object

and corresponding Jess functions

- (store <string-or-atom> <external-address-value>)
- (fetch <string-or-atom>)

can be used in order to exchange Java objects between Java and Jess in case you don't 
want/need to pattern-match these objects. The mechanism can be used for exchanging 
global variables, though.

<Java>

r.store("FRAMEWORK", g);

<Jess>

(create_a_metagraph_object (fetch FRAMEWORK) (new Metagraph_object))

(3) defclass/definstance

In case your Java objects need to trigger rule execution you have to use the 
defclass/definstance mechanism.

Let's assume we have a wrapper class MetagraphEngine that 
- wraps your Rete object and 
- provides some auxiliary methods that are useful for Metagraph integration

One method would be the following:

  /**
   * definstance for object that supports PropertyChangeListeners
   */
  public void definstance(String className, Object bean)
    throws JessException
  {
    Funcall f = new Funcall("definstance", rete);
    f.add(new Value(className, RU.ATOM));
    f.add(new Value(bean));
    f.execute(rete.getGlobalContext());
  }

On the Java side you'd then be able to say

MetagraphEngine me = new MetagraphEngine();
Metagraf_object o = new Metagraph_object();

me.definstance("metagraph-object", o);

On the Jess side you'd have something like the following:

(defclass metagraph-object <metagraph-package>.Metagraf_object)

(defrule process-metagraph-object
        ?instance <- (metagraph-object (OBJECT ?o) (<member-1> ?m-1) ...)
        ...
        =>
        ;; Call a method
        (call ?o <any-metagraph-object-method> <param-1> ... <param-n>)

        ;; Process slot values
        (printout t "<member-1> value is " ?m-1 crlf)

        ;; Change slot/member values using update
        (update ?instance (<member-1> "new value"))

        ;; Change slot/member using get/set methods
        (call ?o setXCoordinate (+ (call ?o getXCoordinate) 1)))
        
(4) Global variables

<Java>

r.addDefglobal(new Defglobal("*o*", o);

<Jess>

(call ?*o* <any-metagraph-object-method> <param-1> ... <param-n>)

(5) Userfunctions

Generally, userfunctions could be used in order to provide utilities simplifying the 
interaction with Metagraph. Refer to the documentation for details. See the (engine) 
Userfunction for an example of how to provide access to an object by using a 
Userfunction.

> The difficult I see, it's that you *HAVE* to fetch values from
> a *entire* execution, and you can't get partial result.
> And that it's easy to instantate new objects but those objects
> *remain* inside of Clips, and I'd need them in the "main" java
> program.

I assume Metagraph classes are associated to each other. So, even if an object is 
created on the Jess side it should be reachable by traversing the links.

Then again, the whole expert system shell is a collection of Java objects. There are 
mechanisms to get hold of each and everything from the Java side.

Greetings, Thomas
---------------------------------------------------------------------
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