Palmer P.
Palmer P.

Reputation: 21

Is it possible to answer multiple questions using the same rule?

I am evaluating business rules engines. I played a little bit with Drools, but it seems, I am rather looking for a query driven, backward chaining system.

So to be more specific, let's see a simple business rule like this:

when
    (amount > 1000 AND amount < 2000 AND currency == USD)
    OR
    (amount > 750 AND amount < 1500 AND currency == EUR)
then
   approve loan

Is it possible to use only this rule and "ask" Drools to answer these questions:

  1. What are the required conditions to get a loan approved, if the currency is USD? I would expected a result something like this: (amount > 1000) AND (amount < 2000)

  2. Is it possible to get a 2000 EUR loan? (expected answer: false)

  3. If not possible, then what were the key reasons of rejection? (expected answer: amount >= 1500 )

Is Drools capable of answering such kind of questions using only one rule? In theory, those information are all stored in the rule, but I don't know how to "extract" from it.

If Drools is not the best rules engine for this scenario, then are there any engines that provides this kind of functionality?

Upvotes: 2

Views: 260

Answers (2)

Arash Aghlara
Arash Aghlara

Reputation: 350

In a RETE engine a production contains multiple conditions so basically we can define your rule as:

P1= C1 ^ C2 ^ C3 where C1=amount > 1000; C2=amount < 2000;C3=currency == USD

I also recommend you to split your OR condition to two different productions. P2=C4 ^ C5 ^ C6 where C4=amount > 750; C5=amount < 1500; C6=currency == EUR;

(Note that in production systems you don't really have OR and some of them do not even let you write OR conditions because of tracability requirements)

And to answer your questions:

  1. You simply can query all the productions that sharing C3 as part of your conditions.
  2. Execute your rule with your input and you get the result
  3. Query against your beta memories that do not have a token and the have the discrimination condition for C5 passed in the corresponding alpha memory of network.

Not all the rules engine would let you query against beta memory and tokens. Check if Drools allow you to retrieve alpha, beta memories and stored tokens. Basically you need to traverse the internal RETE graph.

Upvotes: 0

ali k&#246;ksal
ali k&#246;ksal

Reputation: 1227

Drools, like many other rule engines, uses RETE algorithm to decide which consequences to run, all of the when part of your rule must match to the then part to run.

For your questions 1 and 2: If you want multiple "answers" you can either use multiple rules, or use accumulate function.

For 3: You cannot know why a rule did not invoked, you need to express the rejection case as a separate rule that fires when the specific condition for the rejection case met.

Upvotes: 0

Related Questions