Home » Archived » M2M (model-to-model transformation) » avoiding : trying to register several rules...
|
Re: avoiding : trying to register several rules... [message #60239 is a reply to message #60215] |
Mon, 03 September 2007 07:46 |
Eclipse User |
|
|
|
Originally posted by: r.c.ladan.tue.nl
Alexandre Torres wrote:
> Hi.
> I created a couple of rules that generates two target elements from the
> same source element, what causes the "trying to register several
> rules..." error message.
> The problem is that each rule has distinct conditions, so that the
> source element may generate zero, one or both elements.
> I don't know the best way to do that, and most examples seem to be very
> simple.
>
> This is what I'm trying to do:
>
> rule r1 {
> from c : IN!Class (
> c.isR1()
> )
> to
> c_create : resultModel!ClassInRule1 (
> Name <- c.name
> )
> }
> rule r2 {
> from c : IN!Class (
> c.isR2()
> )
> to
> c_create : resultModel!ClassInRule2 (
> Name <- c.name
> )
> }
>
> do I have to use imperative rules?
How would you want to do that? AFAIK you'll still have to decide when to
generate which element using declarative rules.
You could experiment with the not-yet-documented keyword "nodefault", like:
rule r1 { ... }
nodefault rule r2 { ... }
and see what happens (maybe prefix both rules).
If the conditions are logically distinct, there shouldn't be a problem
at all I guess. Note that (r > 3) and (r > 5) are _not_ distinct and
therefore _not_ usable in the above manner.
Another possibility is to use rule inheritance if R1 is a stronger
version of R2 (or vice versa, e.g. (r > 5) and (r > 3) ).
> Thanks
>
regards,
Rene
|
|
|
Re: avoiding : trying to register several rules... [message #60288 is a reply to message #60239] |
Mon, 03 September 2007 11:20 |
Alexandre Torres Messages: 139 Registered: July 2009 |
Senior Member |
|
|
> How would you want to do that? AFAIK you'll still have to decide when to
> generate which element using declarative rules.
> You could experiment with the not-yet-documented keyword "nodefault", like:
> rule r1 { ... }
> nodefault rule r2 { ... }
> and see what happens (maybe prefix both rules).
> If the conditions are logically distinct, there shouldn't be a problem
> at all I guess. Note that (r > 3) and (r > 5) are _not_ distinct and
> therefore _not_ usable in the above manner.
> Another possibility is to use rule inheritance if R1 is a stronger
> version of R2 (or vice versa, e.g. (r > 5) and (r > 3) ).
>> Thanks
>>
> regards,
> Rene
Well I do consider a big limitation to a model transformation language
when you can't map one element to one or two elements depending on the
first component properties. This is what I'm trying to do. This is a
common issue.
I experimented a little bit with lazy rules, but it seems that any
condition in the from clause of lazy rules is ignored (and I can't find
documentation on that either).
Imagine a case when your source model has two properties that, if not
null, are mapped do two distinct components in the target model, but when
one of them is null, only one element is generated.
I *think* I can still simulate each combination of disjoint selective
solution. This will lead to several rules that are just the same thing.
well, going to try this option...
Thanks
|
|
|
Re: avoiding : trying to register several rules... [message #60312 is a reply to message #60215] |
Mon, 03 September 2007 11:37 |
Ivano Messages: 35 Registered: July 2009 |
Member |
|
|
I, this may help you:
The error message appears only when the two conditions evaluate to true,
in the other cases all works. So I think you have to separate all the
cases and create rules like these:
rule r1 {
from
c : IN!Class (c.isR1() and not c.isR2())
to
c_create : resultModel!ClassInRule1 (
Name <- c.name
)
}
rule r2 {
from
c : IN!Class (c.isR2() and not c.isR1())
to
c_create : resultModel!ClassInRule2 (
Name <- c.name
)
}
rule r3 {
from
c : IN!Class (c.isR2() and c.isR1())
to
c_create : resultModel!ClassInRule2 (
Name <- c.name
),
c_create2 : resultModel!ClassInRule1 (
Name <- c.name
)
}
I don't if it works, but it my be an initial idea....
Regards, Ivano
Alexandre Torres wrote:
> Hi.
> I created a couple of rules that generates two target elements from the
> same source element, what causes the "trying to register several rules..."
> error message.
> The problem is that each rule has distinct conditions, so that the source
> element may generate zero, one or both elements.
> I don't know the best way to do that, and most examples seem to be very
> simple.
> This is what I'm trying to do:
> rule r1 {
> from
> c : IN!Class (
> c.isR1()
> )
> to
> c_create : resultModel!ClassInRule1 (
> Name <- c.name
> )
> }
> rule r2 {
> from
> c : IN!Class (
> c.isR2()
> )
> to
> c_create : resultModel!ClassInRule2 (
> Name <- c.name
> )
> }
> do I have to use imperative rules?
> ThanksHi,
|
|
| |
Re: [ATL] avoiding : trying to register several rules... [message #61027 is a reply to message #60450] |
Wed, 05 September 2007 13:31 |
Frédéric Jouault Messages: 572 Registered: July 2009 |
Senior Member |
|
|
Hi,
Could you please remember to prefix the subject of your ATL-related
posts with [ATL], as I did in this answer (see )? Thanks.
Alexandre,
Your solution seems quite interesting.
Could you please contribute it to the wiki?
Note that if your target elements are referenced by other rules (and you
can sometimes force this by setting a reference using its opposite),
then it may be possible to avoid using a rule on a container.
Regards,
Frédéric Jouault
Alexandre Torres wrote:
>
> I found a suitable solution for me. Instead of selecting the element
> itself, I changed the rule to select a container of the element, and
> them used a couple of lazy rules to do the job. The main problem of
> creating a rule for every combination is that it looks fine for 2 rules,
> but it's not my case: I explode one class to several possible classes.
> Combination of 7x7 is a too big number of rules for my taste. This way I
> found will not require much extra coding,but do require to create a
> destination model with a grouping type (PackageHelper in my example).
> Something like this:
>
> lazy rule r1 {
> from c : IN!Class -- filter here DOES NOT WORK!?
> to
> c_create : resultModel!ClassInRule1 (
> Name <- c.name
> )
> }
> lazy rule r2 {
> from c : IN!Class to
> c_create : resultModel!ClassInRule2 (
> Name <- c.name
> )
> }
> rule r3 {
> from p : IN!Package to
> p_helper : resultModel!PackageHelper (
> members<-p.getMembers()->select(c|c.isOclType(IN!Class) and
> c.isR1())->collect(c|thisModule.r1(c))->union(
> p.getMembers()->select(c|c.isOclType(IN!Class) and
> c.isR2())->collect(c|thisModule.r2(c))
> )
> )
> }
>
> The secret is the union operator. I intend to organize it a little
> better with helpers. ;)
> This wiki helped a bit on my idea:
> http://wiki.eclipse.org/index.php/ATL_Language_Troubleshoote r
>
> Thanks for the feedback
>
|
|
|
Re: [ATL] avoiding : trying to register several rules... [message #61051 is a reply to message #61027] |
Wed, 05 September 2007 13:32 |
Frédéric Jouault Messages: 572 Registered: July 2009 |
Senior Member |
|
|
Hi,
Sorry, I meant to add http://wiki.eclipse.org/M2M after "see" ;-).
Regards,
Frédéric
M2M Project Lead
Frédéric Jouault wrote:
> Hi,
>
> Could you please remember to prefix the subject of your ATL-related
> posts with [ATL], as I did in this answer (see )? Thanks.
>
>
> Alexandre,
>
> Your solution seems quite interesting.
> Could you please contribute it to the wiki?
>
>
> Note that if your target elements are referenced by other rules (and you
> can sometimes force this by setting a reference using its opposite),
> then it may be possible to avoid using a rule on a container.
>
>
> Regards,
>
> Frédéric Jouault
>
>
> Alexandre Torres wrote:
>>
>> I found a suitable solution for me. Instead of selecting the element
>> itself, I changed the rule to select a container of the element, and
>> them used a couple of lazy rules to do the job. The main problem of
>> creating a rule for every combination is that it looks fine for 2
>> rules, but it's not my case: I explode one class to several possible
>> classes. Combination of 7x7 is a too big number of rules for my taste.
>> This way I found will not require much extra coding,but do require to
>> create a destination model with a grouping type (PackageHelper in my
>> example).
>> Something like this:
>>
>> lazy rule r1 {
>> from c : IN!Class -- filter here DOES NOT WORK!?
>> to
>> c_create : resultModel!ClassInRule1 (
>> Name <- c.name
>> )
>> }
>> lazy rule r2 {
>> from c : IN!Class to
>> c_create : resultModel!ClassInRule2 (
>> Name <- c.name
>> )
>> }
>> rule r3 {
>> from p : IN!Package to
>> p_helper : resultModel!PackageHelper (
>> members<-p.getMembers()->select(c|c.isOclType(IN!Class) and
>> c.isR1())->collect(c|thisModule.r1(c))->union(
>> p.getMembers()->select(c|c.isOclType(IN!Class) and
>> c.isR2())->collect(c|thisModule.r2(c))
>> )
>> )
>> }
>>
>> The secret is the union operator. I intend to organize it a little
>> better with helpers. ;)
>> This wiki helped a bit on my idea:
>> http://wiki.eclipse.org/index.php/ATL_Language_Troubleshoote r
>>
>> Thanks for the feedback
>>
|
|
|
Goto Forum:
Current Time: Fri Apr 19 13:58:37 GMT 2024
Powered by FUDForum. Page generated in 0.02254 seconds
|