In addition to what Ernest has said, let me tell you that better help could be
provided if you describe your *original* problem, rather than asking
for technical
details of this or that.

You say that your function would change over time. Except for the "natural"
ones such as time() or date(), this is better avoided, especially in a rule base
system. One way to achieve the effect (I think) you are looking for is to have
a single *fact* containing the result of your function, and if this
should change,
you simply update the fact. Instead of (test (functioncall)) you write a plain
old pattern:

   (function (result ...))

Moreover, userfunctions are primarily intended for extening the Jess language.
Using them for (again, what I think) simple data representation is an overkill.

HTH
-W


On 28 July 2010 11:42, Ana Rossello Busquet <[email protected]> wrote:
> 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
>
>




--------------------------------------------------------------------
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