How to create a drl file or decision table dynamically?

classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|

How to create a drl file or decision table dynamically?

shawn
If it is possible to create a drl file or decision table dynamically in drool or java?
Like the drool received data then create drl or decision table based on the data?
Data: Condition 1 AND Condition 2 OR Condition 3 .....
Can the above data be stored in the rule file which also contains the operators "AND", "OR"?
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] How to create a drl file or decision table dynamically?

manstis
Yes.

If the data "defines" the rules then there are numerous options:-
  • Construct a DRL String yourself and pass this to a KnowledgeBuilder
  • Use the fluent API to build rules programmatically
  • Construct an XLS decision table using your favourite XLS (Java) API and look at drools-decisiontables
  • Construct a Guvnor decision table using classes in droolsjbpm-ide-common (bundled with Guvnor)
If the data is to be plugged into place-holders in statically defined rules:-
  • Look at the use of Drools Expert Templates
Decision tables do not lend themselves well to "OR" as there is an implicit "AND" between columns.

There might be other solutions, these are those that came readily to mind.

With kind regards,

Mike

On 24 February 2012 14:31, shawn <[hidden email]> wrote:
If it is possible to create a drl file or decision table dynamically in drool
or java?
Like the drool received data then create drl or decision table based on the
data?
Data: Condition 1 AND Condition 2 OR Condition 3 .....
Can the above data be stored in the rule file which also contains the
operators "AND", "OR"?


--
View this message in context: http://drools.46999.n3.nabble.com/How-to-create-a-drl-file-or-decision-table-dynamically-tp3772708p3772708.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] How to create a drl file or decision table dynamically?

shawn
Thanks for your reply.
Sorry, I am not quite clear about your first option.
What's the meaning of 'Construct a DRL String'?
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] How to create a drl file or decision table dynamically?

leo_gomes
In reply to this post by manstis
Hi Michael,

Do you have a link to the Fluent API documentation? I wanted to answer to this question and couldn't find the link anywhere.

Thanks,
Leo.

2012/2/24 Michael Anstis <[hidden email]>
Yes.

If the data "defines" the rules then there are numerous options:-
  • Construct a DRL String yourself and pass this to a KnowledgeBuilder
  • Use the fluent API to build rules programmatically
  • Construct an XLS decision table using your favourite XLS (Java) API and look at drools-decisiontables
  • Construct a Guvnor decision table using classes in droolsjbpm-ide-common (bundled with Guvnor)
If the data is to be plugged into place-holders in statically defined rules:-
  • Look at the use of Drools Expert Templates
Decision tables do not lend themselves well to "OR" as there is an implicit "AND" between columns.

There might be other solutions, these are those that came readily to mind.

With kind regards,

Mike


On 24 February 2012 14:31, shawn <[hidden email]> wrote:
If it is possible to create a drl file or decision table dynamically in drool
or java?
Like the drool received data then create drl or decision table based on the
data?
Data: Condition 1 AND Condition 2 OR Condition 3 .....
Can the above data be stored in the rule file which also contains the
operators "AND", "OR"?


--
View this message in context: http://drools.46999.n3.nabble.com/How-to-create-a-drl-file-or-decision-table-dynamically-tp3772708p3772708.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users



_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] How to create a drl file or decision table dynamically?

shawn
Is it from JBPM or ?
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] How to create a drl file or decision table dynamically?

manstis
In reply to this post by shawn
Quite simply, use a StringBuilder and create the DRL you need from the data you receive.

@Leonardo, erm, erm... no. TBH I thought I'd be able to Google for it.. but no luck. Edson? Is there anything - or am I promoting something I shouldn't ;)

On 24 February 2012 16:43, shawn <[hidden email]> wrote:
Thanks for your reply.
Sorry, I am not quite clear about your first option.
What's the meaning of 'Construct a DRL String'?


--
View this message in context: http://drools.46999.n3.nabble.com/How-to-create-a-drl-file-or-decision-table-dynamically-tp3772708p3773060.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] How to create a drl file or decision table dynamically?

shawn
Thank you~
Does it mean I have to write a file in java and saved it as .drl?
fluent API is in jbpm, right?
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] How to create a drl file or decision table dynamically?

manstis
1) No you don't have to save it; just use one of the overloaded methods on KnowledgeBuilder that takes a StringReader, or String or something else similar.

2) I understand there to be one for Drools Expert too, which I'd expect to be in one of the drools-xxx JARs however am having trouble finding it!

Re#2, I've asked Edson Tirelli (the author of the Drools Expert Fluent API) to advise further...

On 24 February 2012 17:35, shawn <[hidden email]> wrote:
Thank you~
Does it mean I have to write a file in java and saved it as .drl?
fluent API is in jbpm, right?

--
View this message in context: http://drools.46999.n3.nabble.com/How-to-create-a-drl-file-or-decision-table-dynamically-tp3772708p3773187.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] How to create a drl file or decision table dynamically?

shawn
Thanks a lot~
Looking forward to hearing from you.
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] How to create a drl file or decision table dynamically?

Edson Tirelli-4
In reply to this post by manstis
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] How to create a drl file or decision table dynamically?

laune
In reply to this post by leo_gomes
There is one (1) sentence and a dozen (12) lines of example in the
section about "What is New and Noteworhty in Drools 5.2.0" in the
Introduction manual. Given that this nano-documentation doesn't tell
you what to do with the resulting PackageDescr and that this "fluent
API" is part of the unstable API, I'd put my money on StringBuilder
and create rules as DRL text. YMMV.

-W


On 24/02/2012, Leonardo Gomes <[hidden email]> wrote:

> Hi Michael,
>
> Do you have a link to the Fluent API documentation? I wanted to answer to
> this question and couldn't find the link anywhere.
>
> Thanks,
> Leo.
>
> 2012/2/24 Michael Anstis <[hidden email]>
>
>> Yes.
>>
>> If the data "defines" the rules then there are numerous options:-
>>
>>    - Construct a DRL String yourself and pass this to a KnowledgeBuilder
>>    - Use the fluent API to build rules programmatically
>>    - Construct an XLS decision table using your favourite XLS (Java) API
>>    and look at drools-decisiontables
>>    - Construct a Guvnor decision table using classes in
>>    droolsjbpm-ide-common (bundled with Guvnor)
>>
>> If the data is to be plugged into place-holders in statically defined
>> rules:-
>>
>>    - Look at the use of Drools Expert Templates
>>
>> Decision tables do not lend themselves well to "OR" as there is an
>> implicit "AND" between columns.
>>
>> There might be other solutions, these are those that came readily to mind.
>>
>> With kind regards,
>>
>> Mike
>>
>>
>> On 24 February 2012 14:31, shawn <[hidden email]> wrote:
>>
>>> If it is possible to create a drl file or decision table dynamically in
>>> drool
>>> or java?
>>> Like the drool received data then create drl or decision table based on
>>> the
>>> data?
>>> Data: Condition 1 AND Condition 2 OR Condition 3 .....
>>> Can the above data be stored in the rule file which also contains the
>>> operators "AND", "OR"?
>>>
>>>
>>> --
>>> View this message in context:
>>> http://drools.46999.n3.nabble.com/How-to-create-a-drl-file-or-decision-table-dynamically-tp3772708p3772708.html
>>> Sent from the Drools: User forum mailing list archive at Nabble.com.
>>> _______________________________________________
>>> rules-users mailing list
>>> [hidden email]
>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>
>>
>>
>> _______________________________________________
>> rules-users mailing list
>> [hidden email]
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] How to create a drl file or decision table dynamically?

shawn
Hi~
Do you have any example about using stringBuilder?
Cheers
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] How to create a drl file or decision table dynamically?

shawn
In reply to this post by manstis
Hi Michael,
Thank you for your reply~
Now, I understand some mechanism of building dynamic class.
Back to my question,
if I understand correct, those methods you mentioned is to add a drl file(exist) to the knowledgeBase dynamically, right?
But how about the file?
I mean if I need to write "Condition 1 AND Condition 2 OR Condition 3...." into the file, does drool have API to do it.
Because the content that I write into the file is also dynamic. What I really want to do is how to make the drl file exist first? Does it mean I have to create the file myself, and after finished creation I can add it dynamically?
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] How to create a drl file or decision table dynamically?

manstis

You don't need a file, you need a String (not to say you couldn't use a File if you really, really wanted - just that you don't have to).

Other than the Fluent API already mentioned there is no Drools API to construct a DRL String. Read the manual, understand *your* data and build DRL applicable.

I get the feeling you don't know what DRL actually is nor how to use Drools to any extent. Please do read the excellent documentation I am sure things will become clearer to you.

sent on the move

On 26 Feb 2012 11:37, "shawn" <[hidden email]> wrote:

Hi Michael,
Thank you for your reply~
Now, I understand some mechanism of building dynamic class.
Back to my question,
if I understand correct, those methods you mentioned is to add a drl
file(exist) to the knowledgeBase dynamically, right?
But how about the file?
I mean if I need to write "Condition 1 AND Condition 2 OR Condition 3...."
into the file, does drool have API to do it.
Because the content that I write into the file is also dynamic. What I
really want to do is how to make the drl file exist first? Does it mean I
have to create the file myself, and after finished creation I can add it
dynamically?

--
View this message in context: http://drools.46999.n3.nabble.com/How-to-create-a-drl-file-or-decision-table-dynamically-tp3772708p3776811.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] How to create a drl file or decision table dynamically?

shawn
Thank you ~
I will learn the documentation more.
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] How to create a drl file or decision table dynamically?

shawn
In reply to this post by manstis
Sorry, I forget to mention one thing.
What's really difficult for me is to translate the "AND","OR"(Condition 1 AND Condition 2 OR Condition 3....) to the drool.
Because someone will send the request with the expression(Condition 1 AND Condition 2 OR Condition 3....) to me. For each request the expression is different. They hope I can translate the "AND","OR" to rule file automatically. They don't want drool to parse the expression(maybe string) to pick "AND", "OR".  This is why they want to have a rule file for each request. They want to trigger the function to make a rule file when they are making the expression, not only simply send me the expression and verify it..
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] How to create a drl file or decision table dynamically?

laune

A (dynamic) "request" with a "logical expression" that is to be evaluated as 
a rule is very much like a (dynamic) SQL query to be evaluated on a database.

Are you sure that Drools is the right platform?

If "someone" wants to send a logical expression in a formal language of their
own, you'll have to parse that expression and translate it into the Drools Rule
Language (aka DRL). Perhaps a Domain Specific Language might help, but
there's no telling from the very sparse information you've provided. (In any case
"someone" and Drools will have to agree on the  data model and the way to 
refer to the data, or else you'll have to do more work.)

-W


On 26 February 2012 16:00, shawn <[hidden email]> wrote:
Sorry, I forget to mention one thing.
What's really difficult for me is to translate the "AND","OR"(Condition 1
AND Condition 2 OR Condition 3....) to the drool.
Because someone will send the request with the expression(Condition 1 AND
Condition 2 OR Condition 3....) to me. For each request the expression is
different. They hope I can translate the "AND","OR" to rule file
automatically. They don't want drool to parse the expression(maybe string)
to pick "AND", "OR".  This is why they want to have a rule file for each
request. They want to trigger the function to make a rule file when they are
making the expression, not only simply send me the expression and verify
it..

--
View this message in context: http://drools.46999.n3.nabble.com/How-to-create-a-drl-file-or-decision-table-dynamically-tp3772708p3777057.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] How to create a drl file or decision table dynamically?

shawn
Thank your for your reply~
I am developing the Identity and Access management. I have finished the
basic requirement, but the pre-condition part is what I am doing. The
website sends the pre-condition(like what IP address or the time period can
user access) that user sets. The pre-conditions are what I mentioned
(expression). The difficulty is one expression may consist of several
pre-conditions and every condition may be related to different rules.

So here is the problem, how to verify users' authorization based on the
expression which contains many operators("AND", "OR"). The number of "AND",
"OR" in the expression are set by users. This is why I thought to create a
rule file for each expression when the expression is created. In this case,
I won't bother how many "AND", "OR" a  expression contains.
By the way, I also thought about parsing the expression in Java, then
inserting every single condition into working memory. But it seems Drool can
not be fully used in this way. Because it only looks like a if-else
block....

Do you have any other solution for this requirement?
Cheers


laune wrote
A (dynamic) "request" with a "logical expression" that is to be evaluated
as
a rule is very much like a (dynamic) SQL query to be evaluated on a
database.

Are you sure that Drools is the right platform?

If "someone" wants to send a logical expression in a formal language of
their
own, you'll have to parse that expression and translate it into the Drools
Rule
Language (aka DRL). Perhaps a Domain Specific Language might help, but
there's no telling from the very sparse information you've provided. (In
any case
"someone" and Drools will have to agree on the  data model and the way to
refer to the data, or else you'll have to do more work.)

-W


On 26 February 2012 16:00, shawn <[hidden email]> wrote:

> Sorry, I forget to mention one thing.
> What's really difficult for me is to translate the "AND","OR"(Condition 1
> AND Condition 2 OR Condition 3....) to the drool.
> Because someone will send the request with the expression(Condition 1 AND
> Condition 2 OR Condition 3....) to me. For each request the expression is
> different. They hope I can translate the "AND","OR" to rule file
> automatically. They don't want drool to parse the expression(maybe string)
> to pick "AND", "OR".  This is why they want to have a rule file for each
> request. They want to trigger the function to make a rule file when they
> are
> making the expression, not only simply send me the expression and verify
> it..
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/How-to-create-a-drl-file-or-decision-table-dynamically-tp3772708p3777057.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users