I was baffled as well by this question, but I resolved it
by just using the function executeCommand(String cmd) for the rule.
It is odd that the Defrule API doesn't support the methods for building a
rule in this manner (could/would be faster and more precise than string
parsing). However, not that big of a deal, because in order to create the
string you need to have your own representation of patterns, LHS, RHS,
etc.(that will get more complicated based on your program), so what you
are suggesting might not be that worthwhile to implement in JESS.

As far as doing this in a rule based system, I would highly recommend it.
You just need to be careful to make sure the initial overhead is not to
processor intensive (meaning, the number of matching template facts is not
too high, because JESS compares the new rule with every possible fact in
the KB it should.)

If you don't keep the option open to develop a rule dynamically, then it
is likely that you will start re-developing a Rete engine in the facts so
that the facts will start representing partial-orders. This gave me a
headache for a while, and it probably still does. :)  Since JESS evaluates
changes (or modifications) to facts as a retraction and an assertion
(instead of just evaluating the rules that are dependent on the slots
changed, which will hopefully change in Version 7.0), the tendency for
developing what I described above exists for performance reasons.  You do
not want a rule to re-evaluate a slot that isn't changed, so this leads
to changing the representation of that slot to a fact. This will perform
better in JESS for each fact evaluation, but it could perform worse
because there will be many more facts.

Creating rules dynamically will eliminate the need for the fact
evaluations for the rule (if the rule doesn't exist), but it will need to
re-evaluate everything it depends on when you create it. It is always a
trade-off between when comparisons get evaluated. If you know facts/slots
are going to change ALOT (meaning more than the number of that type
exists, possibly) and you don't depend on them, then the rule shouldn't
exist in the Knowledge-base. You might as well save the time by not
processing them (i.e. take the rule out), then add the rule in when they
need to be processed.

Sorry for the long email. hope it helps,

Blaine

On Sun, 31 Mar 2002, Anup Marwadi wrote:

>
>
> hi there,
> i need to create a rule using JAVA API instead of the JESS code embedded in
> r.executeCommand statement. The reason is that I am dynamically changing the
> rule depending upon the input from the user and I am pretty sure that JESS
> does not allow me with that flexibility.
> I really am at loss on how to create rules like the one given below using
> JESS API. any kind of a help will be much appreciated.
> eg rule:
>
> (defrule example-3
>     (not-b-and-c ?n1&~b ?n2&~c)
>     (different ?d1 ?d2&~?d1)
>     (same ?s ?s)
>     (more-than-one-hundred ?m&:(> ?m 100))
>     (red-or-blue red|blue)
>     =>
>     (printout t "Found what I wanted!" crlf))
>
>
>
> regards,
> anup
>
>
>
>
> _________________________________________________________________
> Join the world�s largest e-mail service with MSN Hotmail.
> http://www.hotmail.com
>
>
> --------------------------------------------------------------------
> 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]
> --------------------------------------------------------------------
>


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