JESS: How to use a Userfunction returning boolean in a LHS of a Jess rule

"Ana Rossello Busquet" <[email protected]>
Newsgroups gmane.comp.java.jess
Message-ID <14401_1280315761_o6SBG0XY015083_401DFAA0C5795B4AAB1B80DD400C39AD21016E72F5@WINEXCHANGE4.win.dtu.dk>
Hi,

I am beginner in Jess. I have a java application that uses jess.Rete. I want to define a rule in jess that calls a Userfunction in LHS. If the Userfunction returns true, the rule should be fired. I have mainly two problems: 1- how do I write this rule in jess 2- how do I notify my engine that the return value of the function has changed.


1-      How do I write the rule in jess:
I have created a this class that implements Userfunction:

public class ReturnTrue implements Userfunction {
@Override
public Value call(ValueVector arg0, Context arg1) throws JessException {
return new Value(Funcall.TRUE);
}
@Override
public String getName() {return "returnTrue";}
}

My main code, where jess.Rete is initialized and my rules and Userfunctions are loaded:

Rete engine = new Rete();
engine.addUserpackage(new JessTabFunctions());
try {
           //my database is an ontology created with protege
engine.executeCommand("(load-project  file:/M:/MyJessTest/osgi.myjesstest.test/simple-owl.pprj)");
           Batch.batch("myrules.clp", engine);
           engine.addUserfunction(new ReturnTrue());
} catch (JessException e) {
e.printStackTrace();
}

I have write my rule like this, but it does not seem to be working:
(defrule trueFunction
   "True Function"
   (test (returnTrue))
   =>
    ((System.out) println "True"))

What am I doing wrong?


2-  - how do I notify my engine that the return value of the Userfunction has changed


I have found a post that actually talks about this: Userfunction on LHS called only once. In this post ejfried suggests two options: idle-rule or JavaBean which support PropertyChangeEvents. Can some on give more information on how to use PropertyChangeEvents or even better an example code?

Thanks!

Ana
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.