私はジェスでそのようなことをしたい:
(bind ?instance (this))
私がそれを機能させる唯一の方法は、「this」の代わりに「new Object」を使用することです。
どうすれば機能しますか?
私はジェスでそのようなことをしたい:
(bind ?instance (this))
私がそれを機能させる唯一の方法は、「this」の代わりに「new Object」を使用することです。
どうすれば機能しますか?
実際、Jess 環境から Pojo にアクセスするには 3 つの方法があり、シングルトンの場合は 4 つ目の方法があります。
public class Main {
public static Main theInstance;
public static Main getInstance(){ return theInstance; }
private String user = "Joe";
public String getUser(){ return user; }
public static void main( String[] args ) throws Exception {
Main main = new Main();
Main.theInstance = main;
Rete rete = new Rete();
// as a global
Defglobal glob = new Defglobal( "*main*", new Value( main ) );
glob.reset( rete );
// as a store member
rete.store( "main", main );
// as a fact
rete.add( main );
// execute demo clp
rete.batch( "two.clp" );
}
}
そして、.clp は次のとおりです。
(printout t "?*main* = " ?*main* crlf)
(printout t "?*main*.user = " (?*main* getUser) crlf)
(printout t "main = " (fetch main) crlf)
(printout t "main.user = " ((fetch main) getUser) crlf)
(defrule get-main-user
(Main (user ?user))
=>
(printout t "a Main(slot user) = " ?user crlf)
)
(run)
(printout t "Main.theInstance = " ((call Main getInstance) getUser) crlf)
出力:
?*main* = <Java-Object:Main>
?*main*.user = Joe
main = <Java-Object:Main>
main.user = Joe
a Main(slot user) = Joe
Main.theInstance = Joe