Hi All, 
I need some more clarification on creating the rule. my target is to provide
a graphical API where it can be used to define / create rules for a JAVA
application . user should be able to create rule as he wishes. So for the
moment what I am trying to do is create Entities ( Deftemplates ) to
represent business entities like customer, promotion, discount etc. I have
created some classes like entity manager , Fact Manager where I can use for
passing the required attributes. for e.g. 
  FactManager.createEntity(String name,HashMap attributes) take the Entity
name( e.g. Custome ) and a hashmap of attribute - value ( e.g. name=String,
age=float,gender=String) , This will intern create a deftemplate in the JESS
engine. Similarly I have creatd a FactManager class to create the fact. This
will also create the fact using jess.Fact class. 
But when thinking of providing the interface for the RuleManager i am facing
problems. 
I am a bit confused with it right now :-(. 
I have a Rule LHS  generation where i can concatenamte multiple statements
and a RHS generator for the result .  

for e.g. the discount rate applicable FOR  a customer who makes a sale
greater tan 5000$ will get a discount of 10%. 
therefore the LHS would be some thing like 

As per the explanation given by Mr.Friedman, i think that the DISCOUNT would
be a global variable and not for that particular rule. 
( If 2 rules ( for different sales values ) have 2 discount rates , how are
these 2 differentiated.? 

2. Also what I am planning is to provide a cuatomizable interface for
calling/firing a rule from one of my classes. for e.g. 

RuleManager.executeRule("rulename" , HashMap valuer) . for e.g. for the
above discount rule hashmap would hold Name=John,Sale=5500. But what what
the rule return is  10 . ( that is the discount rate applicable for sales
exceeding 5000$) . 
((customer ?name  ) (sale  value>5000) 
I am not sure about the syntax here : the objective is "for any customer
Entity  if the sale Entity  value is >5000 ) 
3. ===== please any one corect the syntax for me please ?? 

4. Also how would the output be retrieved? It could just return a
ValueVector or some other JEss specific wrapper or a basic data type as
given in Mr.Friedman's code example.

Also looking at the code "


    engine.run();
        int discount = engine.fetch("DISCOUNT").intValue(null);
"


 
it seems that just before firing the rule , the rule engine is run.
therefore 
4.1. If I need I can load other deftemplates and facts to the Rete instance
before the rule is fired.Please correct me If I am wrong. 


5. Please clarify whether the approach I am trying out is wrong. If so
please correct me . 

summarising the requirement as per the earlier example. 

  first a Customer Entity would be created using DefTemplate. 
  then a  sale is made by a customer ( i think for this a entity should be
created for representing sales???? 
  OR else 
a new fact could be created with ( custome and sales attributes) and Fact
created for this entity would be loaded in to Rete. 
then a rule should fire and I should get the discount as 10% . I think I can
use the STORE function . pls verify ??? 
But then how is the LHS being constructed ( the syntax ). Please provide me
some help on this regard. 

thanks and best regards,
Saji



-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Thursday, February 13, 2003 12:01 AM
To: [EMAIL PROTECTED]
Subject: Re: JESS: help on Jess Rules



I think Sajindra Jayasena wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
> Hi All, 
> I am new to Jess . 
> I am trying out to develop a customizable rule engine as a university
degree
> project  that could be used by java applications. I have done the
> customizing interfaces for facts etc but facing problrm with working with
> the Rule. 
> I found that (defrule ... ) is the command to create a rule . But facing
> problen in defining the RHS of the rule 
> for e.g. If I create a rule where the LHS is 
> ((customer ?name ?age new ) 
> and the RHS would be 
> 
> => (discount = 35 ) - this syntax is incorrect i think . 

Yes, it is not valid syntax.

> If I explain the scenarion , what would happen is for any customer fact if
> his status is new , the discount that is applied to him is 35 ) . 
> the problems I am facing are : 
> 1. How to define the RHS ? 


This depends on what you want to do, and the answer is tied up with
the answer to the next two questions. First, you have to figure out
what you want to do with the value "discount." Are you going to apply
more rules to it? If so, then you should make another fact out of it
and assert it -- i.e., (assert (discount 35)) . If you're -not- going
to apply more rules to it, but instead just want to send it back to
the user or the main Java program, then you can do that by calling a
Java function, or using the (store) and (fetch) Jess functions
(described in the manual) -- i.e., (this rule doesn't make any sense,
but hopefully you'll get the idea)

(defrule my-rule
        (customer ?name ?age new ) 
        =>
        (store DISCOUNT 35))

and then in Java, if your Rete object is in a variable named "engine",
you can write

        engine.run();
        int discount = engine.fetch("DISCOUNT").intValue(null);


> 2. how can I get the out put of this rule ? 

First you have to write a rule which produces some kind of "output."
The (store) function is a very handy and easy way to send results
back to a Java program.

> 3. do i have to write jess functions? 

Deffunctions, you mean? Only if you want to.


---------------------------------------------------------
Ernest Friedman-Hill  
Distributed Systems Research        Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
PO Box 969, MS 9012                 [EMAIL PROTECTED]
Livermore, CA 94550         http://herzberg.ca.sandia.gov

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