G'day everyone,

I'm looking to create a java object, and monitor this via its javabeans compatibility. Then if the object's properties meet certain criteria, then a rule fires. I have done this with no problems using the Jess command line, but am now interested in doing the equivalent via the Jess API.

I understand how to do this, but have a queston regarding the storing of rules. I want to store my rules in a .clp file, which if using the Jess command line, i would just use (batch).
How do I create the bean complient object in Java, but ensure the rules in the .clp file know what I'm referring to?

my code for a simple java class is:

---------------------------------------------------------
import jess.*;

public class JessDemo {

    public static void main(String[] args) {
       
        Rete engine = new Rete();
        try
        {
            engine.clear();
            engine.executeCommand("(batch jess_test.clp)"); //this line causes an error
            engine.defclass("address", "Address", null);
            Address inputAddress = new Address(null, null, null, null, "36","marlow", "street", "wembley", "wa", "6014");
            System.out.println(inputAddress.toString() );
            engine.definstance("address", inputAddress, false);
        }
        catch (JessException error)
        {
            System.out.println("Error!");
            System.out.println(error.toString() );
        }

    }

}
------------------------------------------------------------------

the clp file to be used with the javabean contains:

------------------------------
(defrule complete-address (newAddress (locality ~nil) (number ~nil) (postCode ~nil) (state ~nil) (streetName ~nil) ) => (printout t "thunderbirds are go" crlf) )
--------------------------------

any my original clp file, which i used at the jess command line, was:
----------------------------------------
(clear)
(defclass newAddress Address)
(ppdeftemplate newAddress)
(bind ?na (new Address nil nil nil nil "36" "marlow" "street" "wembley" "wa" "6014" ))
(definstance newAddress ?na static)
(reset)
(defrule complete-address (newAddress (locality ~nil) (number ~nil) (postCode ~nil) (state ~nil) (streetName ~nil) ) => (printout t "thunderbirds are go" crlf) )
--------------------------------------------
obviously I  typed (run), too. it worked no problems.
 

I know enough that because I have removed the defclass, ppdeftemplate, bind and definstance commands from the top clp file, the rule has no idea about what's going on...


so in a nutshell: how do you store rules in a clp file about an object that is not yet instantiated?

Cheers,
Matt



 

--
Matthew Hutchinson
Ph.D. Candidate
Department of Spatial Sciences
Curtin University of Technology
GPO Box U1987
Perth, Western Australia 6845 G'day everyone,

I'm looking to create a java object, and monitor this via its javabeans compatibility. Then if the object's properties meet certain criteria, then a rule fires. I have done this with no problems using the Jess command line, but am now interested in doing the equivalent via the Jess API.

I understand how to do this, but have a queston regarding the storing of rules. I want to store my rules in a .clp file, which if using the Jess command line, i would just use (batch).
How do I create the bean complient object in Java, but ensure the rules in the .clp file know what I'm referring to?

my code for a simple java class is:

---------------------------------------------------------
import jess.*;

public class JessDemo {

    public static void main(String[] args) {
       
        Rete engine = new Rete();
        try
        {
            engine.clear();
            engine.executeCommand("(batch jess_test.clp)"); //this line causes an error
            engine.defclass("address", "Address", null);
            Address inputAddress = new Address(null, null, null, null, "36","marlow", "street", "wembley", "wa", "6014");
            System.out.println(inputAddress.toString() );
            engine.definstance("address", inputAddress, false);
        }
        catch (JessException error)
        {
            System.out.println("Error!");
            System.out.println(error.toString() );
        }

    }

}
------------------------------------------------------------------

the above clp file contains:

------------------------------
(defrule complete-address (newAddress (locality ~nil) (number ~nil) (postCode ~nil) (state ~nil) (streetName ~nil) ) => (printout t "launching" crlf) )
--------------------------------

any my original clp file, which i used at the jess command line, was:
----------------------------------------
(clear)
(defclass newAddress Address)
(ppdeftemplate newAddress)
(bind ?na (new Address nil nil nil nil "36" "marlow" "street" "wembley" "wa" "6014" ))
(definstance newAddress ?na static)
(reset)
(defrule complete-address (newAddress (locality ~nil) (number ~nil) (postCode ~nil) (state ~nil) (streetName ~nil) ) => (printout t "launching" crlf) )
--------------------------------------------

I know enough that because I have removed the defclass, ppdeftemplate, bind and definstance commands from the clp file, the rule has no idea about what's going on...


so in a nutshell: how do you store rules in a clp file about an object that is not yet instantiated?

Cheers,
Matt



 

--
Matthew Hutchinson
Ph.D. Candidate
Department of Spatial Sciences
Curtin University of Technology
GPO Box U1987
Perth, Western Australia 6845

Reply via email to