[rules-users] How to define keywords that represent objects(in facts) to be able to use in rules

Wolfgang Laun wolfgang.laun at gmail.com
Fri Aug 10 05:35:45 EDT 2012


On 10/08/2012, san_drools <pathasantosh at yahoo.co.in> wrote:
> Hello Laune,
>                    Yes, we can use parameters in DSL phrases. But the
> problem here is rule author doesn't know which object to refer.

Consider this DSL definition:
   [when][]ThereIsProgramHistoryData = ProgramHistory ()
   [when][]- where {VarName} is {AttributeName} and is {operator} {value}=
             {VarName}: {AttributeName}  {operator}  {value}

So you can write in DSLR
   ThereIsProgramHistoryData
    - where  lpy  is levelPriorYear and is greater than 0

Note that the author can choose the name ("lpy") with which the field
("levelPriorYear") can be referred to in subsequent conditions. You
can
add more DSL phrases, or raw DRL (using '>' as the first character):

   ThereIsProgramHistoryData
       - where  lpy  is levelPriorYear and is greater than 0
   >  eval( lpy < 1000 )

or you can even use DRL without the '>' provided you add this *as the
last definition* to your DSL:
   [condition][] {anything} = {anything}

   ThereIsProgramHistoryData
       - where  lpy  is levelPriorYear and is greater than 0
       eval( lpy < 1000 )

>
>                      And, can we translate a business rule with keywords
> into DRL?

This is what happens anyway.  To see the result, add this as the first
line to your DSL definitions:
   #/ result

>
>  You can use "$ContactNum" from the DRL translation. It's not "hidden".
> -->
> means, can we write in translated DRL for further actions?

I think that's clear, by now?


>
>  I think per my knowledge, we can write use keywords in business rule but
> not directly in technical rule(DRL).

Distinguish DSLR and DRL. DSLR is where you write rules with phrases you
define in an DSL definition, and this is translated into DRL. DRL is
translated into the (internal) representation of rules for building
the Knowledge Base.

If you write DRL, there's no translation before the one from DRL to
"internal", so you cannot use anything that's not in the DRL syntax.


> And when i write businessrule using
> keywords, the total rule can be using keywords only as the actual objects
> will not be available to this rule. Am i right?

What you write doesn't make sense to me.

A "keyword" is translated into a chunk of text anywhere, a DSL
definition with "when" represents a conditional element or constraint
in the "when" part, and a DSL definition with "then" expands into a
statement in the "then" part.

Thus, a "keyword" can be used to represent any piece of text.

Make sure to read the documentation. Experiment, using "#/ result" and
see what you get.

-W

>
>    Could you lease make me to understad the things clearly in this context.
>
>
>
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/How-to-define-keywords-that-represent-objects-in-facts-to-be-able-to-use-in-rules-tp4019065p4019081.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>


More information about the rules-users mailing list