[rules-users] app-dev 'toe in water' help please

FrankVhh frank.vanhoenshoven at agserv.eu
Fri Aug 12 11:46:35 EDT 2011


Hi,

The best way to get started, imho, is to read the Drools Expert guide -
don't worry if some things are not very clear in the beginning - and have a
look at the samples. The basic hello world sample that comes with the
eclipse plugin is basically all you need to get started. From then on, you
can add complexity as you will.

However, instead of populating and returning a loanApplication object, how
would I return just the decision/end result of a rule if it was only one
value (the approved/not approved decision) from the java app?  KnowledgeBase
is loaded from the java app, but struggling with StatefulKnowledgeSession
versus StatelessKnowledgeSession and how to simply get back the rule
decision value (again, preferably without a specific object if it is only
one value)?

To get one misunderstanding out of the way: the rule engine does not return
a "decision value". In fact, it returns nothing at all. You provide the
engine with facts ( insert(myFact) ), then the engine will start
constructing its rete-tree. Once you execute fireAllRules(), the engine will
start reasoning upon the objects and change attributes, add objects to
working memory, remove from wm, creating new objects and all other beautiful
things that java can handle. When there are no more rules to fire, the
engine will stop and the objects will have reached their final state. It is
up to you to fetch the interesting information.

If you want to implement a decision service that only returns true/false,
you have to implement this in your java code and return the correct boolean
value, which you first fetched from your inserted facts. 

The difference between stateful and stateless is basically this:
   - Stateful: the engine will be able to reevaluate the rules during
execution, hereby enabling foreward chaining.
   - Stateless: engine will not do any reevaluations, the state of the facts
as they come in to the engine, will be considered their fixed state, even if
they are modified.


Example:
when customer has 10 items                      when loyal customer
then customer is loyal customer                  then reduction of 10% 

With this ruleset, with A true on rule execution. The *statefull* session
will "acknowledge" the reduction of 10%. The *stateless* session will only
get determine that the customer is loyal. The reduction is not taken into
account, as the loyalty was not established at the point of rule execution.

I'm also looking to only fire/execute one rule at a time for now until we
get comfortable - any help for an app developer trying to ease their way
into drools?

It might be a good idea to get a basic understanding of the internal working
of a rule engine, i.e. get a basic understanding of the Rete algorithm. This
might help in getting rid of the procedural way of thinking, which is often
a "problem" with technical people.

Hope this helps.

Good luck.

Regards,
Frank 


dhartford wrote:
> 
> Hey all,
> I'm trying to dip some toes into the water with Drools, and have an
> application that would be a good start but having some
> understanding/lacking an appropriate example issue.
> 
> The application context, let's say, is Mortgages, and already using the
> Mortgage rules that are stored in a running instance of Guvnor.
> 
> Going back to 'toe in water', lets assume that all 'facts' are loaded on
> call (so nothing is pre-loaded, all data to run a rule is supplied at the
> time the rule is called).  This is to make it easier to get started
> without jumping all-in just yet ;-)
> 
> Using the mortgage business rule 'CreditApproval' that is already loaded
> into Guvnor, I can see passing the Application object, with the
> creditRating field/fact to a rule.  
> 
> However, instead of populating and returning a loanApplication object, how
> would I return just the decision/end result of a rule if it was only one
> value (the approved/not approved decision) from the java app? 
> KnowledgeBase is loaded from the java app, but struggling with
> StatefulKnowledgeSession versus StatelessKnowledgeSession and how to
> simply get back the rule decision value (again, preferably without a
> specific object if it is only one value)?
> 
> I'm also looking to only fire/execute one rule at a time for now until we
> get comfortable - any help for an app developer trying to ease their way
> into drools?
> 
> Sorry if I not overly clear, still trying to learn the appropriate
> terminology :-)
> 
> -Darren
> 


--
View this message in context: http://drools.46999.n3.nabble.com/app-dev-toe-in-water-help-please-tp3249458p3249601.html
Sent from the Drools: User forum mailing list archive at Nabble.com.



More information about the rules-users mailing list