Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] How to get the elements and put them in a target element
[ATL] How to get the elements and put them in a target element [message #536471] Fri, 28 May 2010 12:15 Go to next message
ayoub is currently offline ayoubFriend
Messages: 25
Registered: March 2010
Junior Member
Hi all,
I have the following problem:
My source metamodel named MMS has 2 classes named ObjPere and ObjFils respectively without relationship like this:
MMS: <objPere name="1"> </objPere>
<objFils name="21" type="a"> </objFils>
<objFils name="22" type="b"> </objFils>

My target metamodel named MMT has 2 classes (father and child) with composition relationship like this:
MMT: <father name="..">
<children>
<child name="..." type="a"> </child>
<child name="..." type="b"> </child>
.....
.....
</children>
</father>

children is the name of relationship (composition) between father and child, note that father contain 0 or * child.

I want make the following transformation:

1- MMT!father.name = MMS!objPere.name
2- MMT!children = List of MMT!child where child.name = MMS!objFils.name and child.type = MMS!objFils.type

Note I want also regroup the child elements into element children in a result transformation conforming to MMT metamodel.

Thanks for your help,
forgive my poor english

[Updated on: Fri, 28 May 2010 19:22]

Report message to a moderator

Re: [ATL] How to get the elements and put them in a target element [message #536966 is a reply to message #536471] Mon, 31 May 2010 17:36 Go to previous messageGo to next message
wafaa is currently offline wafaaFriend
Messages: 163
Registered: January 2010
Location: Egypt
Senior Member
hi ayoub
actually i gave chance for others to share
u can attache the metamodel here and I can test it with u

good luck
Re: [ATL] How to get the elements and put them in a target element [message #536977 is a reply to message #536966] Mon, 31 May 2010 18:38 Go to previous messageGo to next message
ayoub is currently offline ayoubFriend
Messages: 25
Registered: March 2010
Junior Member
hi wafaa,
thank's for your interest!
I don't know how can I share the metamodel's file, but I try to copy the code.

1-the mms metamode is:
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="mms">
<eClassifiers xsi:type="ecore:EClass" name="objPere">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="objFils">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="type" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
</ecore:EPackage>


2- the mmt metamode is:
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="mmt">
<eClassifiers xsi:type="ecore:EClass" name="father">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="children" upperBound="-1"
eType="#//child" containment="true" eOpposite="#//child/father"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="child">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="type" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="father" eType="#//father"
eOpposite="#//father/children"/>
</eClassifiers>
</ecore:EPackage>

---- children is the name of relationship (composition) between father and child, note that father contain 0 or * child.



3-the input file that is conforming to the mms metamodel is:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns="mms">
<objPere name="root"> </objPere>
<objFils name="001" type="a"> </objFils>
<objFils name="001" type="a"> </objFils>
<objFils name="010" type="b"> </objFils>
<objFils name="011" type="a"> </objFils>
<objFils name="100" type="c"> </objFils>
<objFils name="101" type="a"> </objFils>
<objFils name="110" type="d"> </objFils>
</xmi:XMI>



I want make the following transformation:

a- MMT!father.name = MMS!objPere.name
b- MMT!children = List of MMT!child where child.name = MMS!objFils.name and child.type = MMS!objFils.type and MMS!objFils.type ='a'

And regroup the child elements into element children in a result transformation conforming to MMT metamodel.

For this I wrote the following transformation:

4- the ATL transformation:
module mms2mmt;
create OUT: mmt from IN: mms;

rule mms2mmt {
from s : mms!objPere
to t : mmt!father (
name <- s.name,
children <- mms!objFils.allInstances()->collect(e| thisModule.fils2child(e))
->select(c| c.type='a')
)
}

lazy rule fils2child{
from s : mms!objFils(s.isA())
to t : mmt!child(
name <- s.name,
type <- s.type
)
}

helper context mms!objFils def: isA() : Boolean =
if self.type = 'a' then
true
else
false
endif;

but the result is:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns="mmt">
<father name="root">
<children name="001" type="a"/>
<children name="001" type="a"/>
<children name="011" type="a"/>
<children name="101" type="a"/>
</father>
<child name="010" type="b"/>
<child name="100" type="c"/>
<child name="110" type="d"/>
</xmi:XMI>

And I want have a result like this:
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns="mmt">
<father name="root">
<children>
<child name="001" type="a"/>
<child name="001" type="a"/>
<child name="011" type="a"/>
<child name="101" type="a"/>
</children>
</father>
</xmi:XMI>

Thnak's

[Updated on: Mon, 31 May 2010 18:40]

Report message to a moderator

Re: [ATL] How to get the elements and put them in a target element [message #537108 is a reply to message #536977] Tue, 01 June 2010 11:14 Go to previous messageGo to next message
ayoub is currently offline ayoubFriend
Messages: 25
Registered: March 2010
Junior Member
Hi wafaa and all people who want to join us!
I wrote the following transformation but I still have the problem to regroup elements "child" within children's "element":

rule mms2mmt {
from s : mms!objPere
to t : mmt!father (
name <- s.name,
children<-mms!objFils.allInstances()->iterate(e; res: Set(mms!objFils) =Set{} |
if(res->collect(f| f.name)->includes(e.name)) then
res
else
res->including(e)
endif
)->select(c| c.type='a')->flatten()->asOrderedSet()
->collect(e| thisModule.fils2child(e))
)
}

lazy rule fils2child{
from s : mms!objFils
to t : mmt!child(
name <- s.name,
type <- s.type
)
}

the result of this transformation is:

<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns="mmt">
<father name="root">
<children name="001" type="a"/>
<children name="011" type="a"/>
<children name="101" type="a"/>
</father>
</xmi:XMI>

but I want a result like this:

<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns="mmt">
<father name="root">
<children>
<child name="001" type="a"/>
<child name="011" type="a"/>
<child name="101" type="a"/>
</children>
</father>
</xmi:XMI>

It's possible with this metamodel?

[Updated on: Tue, 01 June 2010 16:09]

Report message to a moderator

Re: [ATL] How to get the elements and put them in a target element [message #537426 is a reply to message #537108] Wed, 02 June 2010 12:24 Go to previous messageGo to next message
wafaa is currently offline wafaaFriend
Messages: 163
Registered: January 2010
Location: Egypt
Senior Member
Ayoub, hoe you are fine

I have recreatd your metamodel via ecore diag , and it generated different crom your mmt, almost there is no attribute called father in the child class Rolling Eyes

and when trying to create example , actually when trying to run your examples it generates error Shocked

could you kindly tell me how did you create your examples in xmi in details format,
sorry for making you waiting
Re: [ATL] How to get the elements and put them in a target element [message #537540 is a reply to message #537426] Wed, 02 June 2010 19:40 Go to previous messageGo to next message
ayoub is currently offline ayoubFriend
Messages: 25
Registered: March 2010
Junior Member
Hi waffaa I'm fine thank you, hope you are too.
for my metamodel mmt you can just create an ecore file (with .ecore extension) and that works.
in the child class I have the Ereference father that is opposite in the attribute child in father class, look the red line in "metamodel mmt".
for the example, I generate it manually just to test the transformation.
I hope that you understand my english Confused
a+

the mmt metamode :
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="mmt">
<eClassifiers xsi:type="ecore:EClass" name="father">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="children" upperBound="-1"
eType="#//child" containment="true" eOpposite="#//child/father"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="child">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="type" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="father" eType="#//father"eOpposite="#//father/children"/>
</eClassifiers>
</ecore:EPackage>

[Updated on: Wed, 02 June 2010 19:44]

Report message to a moderator

Re: [ATL] How to get the elements and put them in a target element [message #537554 is a reply to message #537540] Wed, 02 June 2010 21:10 Go to previous messageGo to next message
wafaa is currently offline wafaaFriend
Messages: 163
Registered: January 2010
Location: Egypt
Senior Member
hi ayoub

hope you are ok

first of all, your english is like mine(if not better) so stop describing your writting by poor, it is good

second of all you are good ATLer:)

third of all
mabrooooook the code run
I made the check before the call of the lazy rule

and some changes, have a look and mabrook again Very Happy

module mms2mmt; -- Module Template

create OUT: mmt from IN: mms;

helper def : allAchild : Sequence(mms!objFils) =
mms!objFils.allInstances() -> select(p|p.type = 'a');


rule createMMT {
from s : mms!objPere
to t : mmt!father (
name <- s.name,
children <- thisModule.allAchild -> collect(e| thisModule.fils2child(e))
)
}

lazy rule fils2child{
from s : mms!objFils
to t : mmt!child(
name <- s.name,
type <- s.type
)
}
Re: [ATL] How to get the elements and put them in a target element [message #537653 is a reply to message #537554] Thu, 03 June 2010 09:31 Go to previous message
ayoub is currently offline ayoubFriend
Messages: 25
Registered: March 2010
Junior Member
Hi wafaa and thank you for your interest.
your code run correctly but it give the same result like mine Sad :

<?xml version="1.0" encoding="ISO-8859-1"?>
<father xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns="mmt" name="root">
<children name="011" type="a"/>
<children name="011" type="a"/>
<children name="101" type="a"/>
<children name="001" type="a"/>
</father>

It does not regroup child elements within children one like this:

<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns="mmt">
<father name="root">
<children>
<child name="001" type="a"/>
<child name="011" type="a"/>
<child name="101" type="a"/>
</children>
</father>
</xmi:XMI>

the question now is, it's possible with those metamodels and transformation?

take care waffa:)
Previous Topic:how to check the type of a property if it is String
Next Topic:[SOLVED] [ATL] Source Model Problem
Goto Forum:
  


Current Time: Thu Dec 26 23:15:38 GMT 2024

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

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

Back to the top