It took a little while fiddling with it on my commute, but I knocked up an ultra-basic
natural language style DSL example project here:
I can guarantee that you will be unimpressed with the complexity of the DSL.
Best place to start is the test class:
That gives you the path to the DSL and DSLR, so you can easily check those out.
I hope it's useful...
Steve
On 19 Mar 2013, at 17:36, kurrent93 <kurrent93(a)gmail.com> wrote:
thanks Steve, that would be greatly appreciated!
I've just been reading up about Antlr and DSLs - all new territory.
Here is a sample rule that we would be likely to generator.
1. | rule "close old trades"
2. | dialect "mvel"
3. | when
4. | t : Tick( ) over window:length (1)
5. | closeMe : TradeOrder( orderOpenTime before [2m] t.tickTime )
6. | then
7. | closeMe.setStatus( OrderStatus.CLOSING );
8. | update( closeMe );
9. | modifiedOrderList.add(closeMe);
10. | end
On Tue, Mar 19, 2013 at 6:15 PM, Stephen Masters [via Drools] <[hidden email]>
wrote:
Obviously I don't know what your rules and model look like, but it's worth
considering. The DSL templates are designed to be parsed relatively easily, with a single
clause per line, so although they are not always that readable (if they're generating
a lot of DRL code), they do the job of providing a template reasonably well.
My number one tip working with them is to create a simple unit test class which creates a
knowledge base from the DSL and a simple example DSRL. That way the unit test works as a
compiler for your DSL/DSRL and lets you know when you mess up. You can of course build
more complex tests, but it's always good to have that minimal test there to confirm
that things are at least compiling.
If you're able to provide an example (perhaps slightly anonymised) DRL rule that your
application could be generating, then I'd be happy to have a go at knocking up a
simple straw man DSL which could generate it. It may not be quite what you need, but it
could be a useful starting point.
Steve
On 19 Mar 2013, at 16:34, kurrent93 <[hidden email]> wrote:
> Thanks Steve
>
> Yes that sounds like a way forward. I'll do some research on creating a dsl.
>
> Any pointers are appreciated.
>
> Cheers
>
>
> On Tue, Mar 19, 2013 at 5:20 PM, Stephen Masters [via Drools] <<a
href="x-msg://437/user/SendEmail.jtp?type=node&node=4022888&i=0"
target="_top" rel="nofollow" link="external">[hidden
email]> wrote:
> If you are going to generate DRL, you need to parse your model into a much more
general language and parse that language back into your model. The APIs don't save you
from doing this, they just mean that you interact with an API to generate the code, and
get some validation, rather than just outputting strings. Additionally, I suspect that you
would need to use APIs that are not really intended for public consumption and may change
any time you update Drools.
>
> A DSL defines a template for your own language, for which you define mappings to DRL.
You can write DSLR code using that DSL syntax, instead of DRL. Given that you write the
DSL yourself, it should be specific to your requirements and relatively simple to generate
in many cases (depends on your model of course). Additionally, given that you would be
using it as an intermediate language, you could write a DSL to be parsed easily, rather
than the usual natural language style.
>
> So your code just needs to generate and read your simplified language. Drools deals
with parsing your DSLR code into rules. And you have your own stable language. i.e. You
can update Drools with minimal impact to your application.
>
> It depends mostly on how flexible your rules generation needs to be. If the customers
will be defining values to be dropped into relatively fixed rule structures, then doing
this could be pretty simple.
>
> Steve
>
>
> On 19 Mar 2013, at 15:54, kurrent93 <[hidden email]> wrote:
>
>> thanks Stephen
>>
>> My knowledge of DSLs is very limited. But isnt the problem still parsing in the
DRL into the DSL? I dont really understand how a DSL helps - but that is probably due to
my lack of knowledge here.
>>
>>
>> On Tue, Mar 19, 2013 at 4:41 PM, Stephen Masters [via Drools] <<a
href="<a
href="x-msg://429/user/SendEmail.jtp?type=node&amp;node=4022886&amp;i=0">x-msg://429/user/SendEmail.jtp?type=node&node=4022886&i=0"
target="_top" rel="nofollow" link="external">[hidden
email]> wrote:
>> Depending on your model, it may be better to create a DSL as an intermediate
language. That way you have a simplified language, which you control, to parse in and out,
which could be tuned to your own domain model.
>>
>> Steve
>>
>>
>> On 19 Mar 2013, at 14:36, kurrent93 <[hidden email]> wrote:
>>
>>> HI David
>>>
>>> Yes we are also looking into rule templates.
>>>
>>> We have come up with - what we believe - is a very natural, intuitive and
visually appealing way to author rules. And it is tailored for our specific domain.
>>>
>>> One significant aspect of our work is that we are present drools authoring to
end users - customers - rather than business users. Hence the importance of crafting a
specialized UI, rather than the generic UI of Guvnor.
>>>
>>> And FYI - are also including in the design some UI elements, for a future
version, that will use Drools Chance features.
>>>
>>> Can you point me to documentation - and ideally - samples around using APIs
for the descriptor level?
>>>
>>> Thanks
>>>
>>>
>>>
>>>
>>> On Tue, Mar 19, 2013 at 3:11 PM, Davide Sottara [via Drools] <<a
href="<a href="<a
href="x-msg://398/user/SendEmail.jtp?type=node&amp;amp;node=4022881&amp;amp;i=0">x-msg://398/user/SendEmail.jtp?type=node&amp;node=4022881&amp;i=0"><a
href="x-msg://398/user/SendEmail.jtp?type=node&amp;node=4022881&amp;i=0">x-msg://398/user/SendEmail.jtp?type=node&node=4022881&i=0"
target="_top" rel="nofollow" link="external">[hidden
email]> wrote:
>>> As a RETE network is being created, DRL Rules are parsed into an internal
"descriptor" structure (a high level AST)
>>> and then compiled into a RETE.
>>>
>>> There are "APIs" to create rules at the descriptor level: this can
then be "dumped" back into DRL.
>>> To work at the DRL level directly, it's common to use parametric
"templates".
>>>
>>> If your internal (meta)model is object oriented, you could consider using DRL
rules to write the translators :)
>>>
>>> Davide
>>>
>>> p.s. could you provide some more information about your use case? I'm
doing some research on rule authoring
>>> environments right now. Thanks!
>>>
>>>
>>>
>>>
>>> On 03/19/2013 09:54 AM, Michael Anstis wrote:
>>>> Rules are DRL that is a String.
>>>>
>>>> Where and how you choose to store the String is up to you.
>>>>
>>>> Please try to explain what you want to achieve a little more.
>>>>
>>>> On 19 March 2013 12:49, kurrent93 <[hidden email]> wrote:
>>>> HI all
>>>>
>>>> Is there any samples or documentation for reading and writing of rules?
>>>>
>>>> The user case is we are trying to build a custom Rule Editor,
and thus would
>>>> like to write and read rules to/from our beans.
>>>>
>>>> Thanks
>>>>
>>>>
>>>>
>>>> --
>>>> View this message in context:
http://drools.46999.n3.nabble.com/API-for-reading-and-writing-rules-tp402...
>>>> 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
>>>
>>> If you reply to this email, your message will be added to the discussion
below:
>>>
http://drools.46999.n3.nabble.com/API-for-reading-and-writing-rules-tp402...
>>> To unsubscribe from API for reading and writing rules, <a href="<a
href="<a href="x-msg://398/">x-msg://398/"><a
href="x-msg://398/">x-msg://398/" target="_blank"
rel="nofollow" link="external">click here.
>>> NAML
>>>
>>>
>>> View this message in context: Re: [rules-users] API for reading and writing
rules
>>>
>>> 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
>>
>> If you reply to this email, your message will be added to the discussion below:
>>
http://drools.46999.n3.nabble.com/API-for-reading-and-writing-rules-tp402...
>> To unsubscribe from API for reading and writing rules, <a href="<a
href="x-msg://429/">x-msg://429/" target="_blank"
rel="nofollow" link="external">click here.
>> NAML
>>
>>
>> View this message in context: Re: [rules-users] API for reading and writing
rules
>> 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
>
> If you reply to this email, your message will be added to the discussion below:
>
http://drools.46999.n3.nabble.com/API-for-reading-and-writing-rules-tp402...
> To unsubscribe from API for reading and writing rules, <a
href="x-msg://437/" target="_blank" rel="nofollow"
link="external">click here.
> NAML
>
>
> View this message in context: Re: [rules-users] API for reading and writing rules
> 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
If you reply to this email, your message will be added to the discussion below:
http://drools.46999.n3.nabble.com/API-for-reading-and-writing-rules-tp402...
To unsubscribe from API for reading and writing rules, click here.
NAML
View this message in context: Re: [rules-users] API for reading and writing rules
Sent from the Drools: User forum mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users