Skip to main content



      Home
Home » Archived » M2M (model-to-model transformation) » [ATL] Many-to-one mapping using ATL
[ATL] Many-to-one mapping using ATL [message #92069] Fri, 10 October 2008 12:33 Go to next message
Eclipse UserFriend
Originally posted by: jmcq.cs.nuim.ie

Hi,

Is it possible to create a many-to-one transformation using ATL. If so,
pointers to some examples would be greatly appreciated. I've gone
through the basic examples on the ATL site but don't see anything that
does this.

By many-to-one, I mean I have a source model with multiple instances of
SourceElementA and some of these instances have the same value for the
attribute name, for example name="String" but name could be anything.
I'd like to transform all these elements of SourceElementA with the same
name to a single instance of TargetElementA with its attribute name set
to "String". Is it possible to do this with a single ATL rule or is
something more complicated required?

Thanks,

Jacqui
Re: [ATL] Many-to-one mapping using ATL [message #92205 is a reply to message #92069] Mon, 13 October 2008 03:53 Go to previous messageGo to next message
Eclipse UserFriend
Hello,

You can try unique lazy rules. It would look like that:

unique lazy rule SourceA2TargetA {
-- s is name of a SourceElementA
from s:String
to t:TARGET!TargetElementA(
name<-s
)
}


The rule will only create one TargetElementA for each distinct name, but
you have to call this rule explicitly. So for example you have
SourceElementX, that references SourceElementA (via attribute "a") and you
want to create TargetElementX that references TargetElementA, you need the
following rule:

rule SourceX2TargetX {
from s:SOURCE!SourceElementX
to t:TARGET!TargetElementX(
a <- thisModule.SourceA2TargetA(s.name)
)
}

If you want additional information to move from from SourceElementA to
TargetElementA, you could add a using-block declare a variable, holding
all instances of SourceElementA with the same name.

unique lazy rule SourceA2TrgetA {
-- s is name of a SourceElementA
from s:String
using {
-- all SourceElementA objects with name s
allSourceA : SOURCE!SourceElementA =
SOURCE!SourceElementA->allInstances()->select(a|a.name=s);
}
to t:TARGET!TargetElementA(
name<-s
-- access information from allSourceA here
)
}

If you don't like the solution, you can try to write a rule like this:

rule SourceA2TargetA {
from s:SOURCE!SourceElementA( not TARGET!TargetElementA->allInstances()
->exists(t|t.name=s.name) )
to t:TARGET!TargetElementA(
name <- s.name
)
}

But I'm not sure if this works (or is a generally a good idea), because of
the declarative nature of the language. There are no guaranties about the
execution order. The rules even may be executed concurrently, which could
result in multiple output TargetElementA elements with the same name.

Greetings,
Max

Jacqui wrote:

> By many-to-one, I mean I have a source model with multiple instances of
> SourceElementA and some of these instances have the same value for the
> attribute name, for example name="String" but name could be anything.
> I'd like to transform all these elements of SourceElementA with the same
> name to a single instance of TargetElementA with its attribute name set
> to "String". Is it possible to do this with a single ATL rule or is
> something more complicated required?
Re: [ATL] Many-to-one mapping using ATL [message #92219 is a reply to message #92069] Mon, 13 October 2008 03:55 Go to previous message
Eclipse UserFriend
Originally posted by: mddfabro.ilog.fr

Hi,

Check the post below. We have used a couple of helper to transform
multiple primitive types into a single one (in a use case of model merging).

http://dev.eclipse.org/newslists/news.eclipse.modeling.m2m/m sg00390.html

Regards,

Marcos.

Jacqui wrote:
> Hi,
>
> Is it possible to create a many-to-one transformation using ATL. If so,
> pointers to some examples would be greatly appreciated. I've gone
> through the basic examples on the ATL site but don't see anything that
> does this.
>
> By many-to-one, I mean I have a source model with multiple instances of
> SourceElementA and some of these instances have the same value for the
> attribute name, for example name="String" but name could be anything.
> I'd like to transform all these elements of SourceElementA with the same
> name to a single instance of TargetElementA with its attribute name set
> to "String". Is it possible to do this with a single ATL rule or is
> something more complicated required?
>
> Thanks,
>
> Jacqui
Previous Topic:[ATL] Turning off warnings in the ATL console
Next Topic:[QVTO] Intermediate data
Goto Forum:
  


Current Time: Sun Jul 27 15:34:09 EDT 2025

Powered by FUDForum. Page generated in 0.03489 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top