Call in Jess manipulated Object from Java

153 Views Asked by At

)

Im writing my Master Thesis and I´ve to use the JESS Platform for it. I want to ask a question.

For example I have this Java Class which is named as "Main":

public class Main {

    private String user = "Joe";
    public String getUser(){ return user; }
    public String setUser(String user){ this.user = user;}
    public static void main( String[] args ) throws Exception {
        Main main = new Main();
        Rete rete = new Rete();
        rete.store( "main", main );
        rete.batch( "two.clp" );
    }
}

Now I want to call the clp-file and manipulate the Main-Class-Object and do this:

(printout t "main.user = " ((fetch main) getUser) crlf) ;; I got for this Joe
((fetch main) setUser "Robin")
(printout t "main.user = " ((fetch main) getUser) crlf) ;; For this I got Robin

But now I want to ask you how can I call this manipulated user named "Robin" from a Java code? If I call in Java like this:

public static void main( String[] args ) throws Exception {
        Main main = new Main();
        Rete rete = new Rete();
        rete.store( "main", main );
        rete.batch( "two.clp" );
        System.out.println(main.getUser());
    }

I got as result "Joe" and not "Robin". Can u please tell me how I can get (or call) the manipulated version of the Javaobject? And why it is not manipulated im my Java class when I manipulate the username from Jess to Robin?

I will be thankful for a message. Thanks.

1

There are 1 best solutions below

3
On

I add the class and the clp.file which I used:

java class:

  package Versuch;
import jess.*;

public class Auto {

    private String marke = "";
    private int ps = 0;

    public Auto(String marke, int ps){
        this.marke = marke;
        this.ps = ps;
    }

    public String getMarke() {
        return marke;
    }

    public void setMarke(String marke) {
        this.marke = marke;
    }


    public int getPs() {
        return ps;
    }



    public void setPs(int ps) {
        this.ps = ps;
    }

    public static void main(String[] args) {
        String getAktuell = "";

        Auto vw = new Auto("VW", 90);
        getAktuell = vw.getMarke();
        System.out.println(" before manipulating " + getAktuell );

        Rete engine = new Rete();
        engine.store("vw", vw);
            try {
                engine.batch("Versuch/rulebase.clp");

                System.out.println(" after manipulating " + getAktuell);



            } catch (JessException e) {
                System.out.println("JESS ERROR");
                e.printStackTrace();
            }       


    }

}

clp.file:

(printout t "vw.getMarke = " ((fetch vw) getMarke) crlf)

((fetch vw) setMarke "Mercedes")


(printout t "vw.getMarke = " ((fetch vw) getMarke) crlf)

output:

before manipulating VW
vw.getMarke = VW
vw.getMarke = Mercedes
 after manipulating VW

The first output and the last output are the system.out.println calls from the java class. the second and the third output are the printout calls from the clp.file. Anyone understand why the last call is not the manipulated one? Sorry im really new to this issue. I will be very thankful for help.