Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » QVT-OML » About Family2Person Transformation
About Family2Person Transformation [message #1792153] Thu, 12 July 2018 08:24 Go to next message
ashrafur rahman is currently offline ashrafur rahmanFriend
Messages: 21
Registered: May 2018
Junior Member
Dear All,

I was trying to transform Family2Person in QVTo. But as I am new, I am facing multiple problems. Someone, please help me.

Here is my input model:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI 
	xmi:version="2.0" 
	xmlns:xmi="http://www.omg.org/XMI" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:Families="http://ashraf.families" 
	xsi:schemaLocation="http://ashraf.families Families.ecore">
  <Families:Family lastName="March">
    <father firstName="Jim"/>
    <mother firstName="Cindy"/>
    <sons firstName="Brandon"/>
    <daughters firstName="Brenda"/>
    <daughters firstName="Jen"/>
  </Families:Family>
  <Families:Family lastName="Sailor">
    <father firstName="Peter"/>
    <mother firstName="Jackie"/>
    <sons firstName="David"/>
    <sons firstName="Dylan"/>
    <daughters firstName="Kelly"/>
  </Families:Family>
</xmi:XMI>


Output Model:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:ashraf.persons="http://ashraf.persons">
  <ashraf.persons:Female fullName="Cindy March"/>
  <ashraf.persons:Female fullName="Brenda March"/>
  <ashraf.persons:Female fullName="Jen March"/>
  <ashraf.persons:Female fullName="Jackie Sailor"/>
  <ashraf.persons:Female fullName="Kelly Sailor"/>
  <ashraf.persons:Male fullName="Jim March"/>
  <ashraf.persons:Male fullName="Brandon March"/>
  <ashraf.persons:Male fullName="Peter Sailor"/>
  <ashraf.persons:Male fullName="David Sailor"/>
  <ashraf.persons:Male fullName="Dylan Sailor"/>
</xmi:XMI>


My problem is, I cannot iterate to father, mother, daughters, and sons, to get the full name. It overwrites one another.
I tried several ways but nothing works.

Someone, please help me to get the solution. Thank you.

I attached my project here.
  • Attachment: F2PQvto.zip
    (Size: 3.96KB, Downloaded 11 times)
Re: About Family2Person Transformation [message #1792163 is a reply to message #1792153] Thu, 12 July 2018 09:30 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6112
Registered: July 2009
Senior Member
Hi

You don't show me exactly what you are unhappy with, but I can draw two hazards to your attention that may be relevant.

The standard Family metamodel from the ATL zoo is very simple and so used by many introductory texts and examples. Unfortunately the metamodel is seriously broken. A Family contains its Persons, consequently the father in one Family cannot be the son in another; Ecore and UML support only single containment. A Family should reference its Persons which should be contained elsewhere, possibly at the root.

A mapping is performed exactly once for each distinct tuple of arguments; repeated executions re-use the old results. If you really want multiple executions you need to add an extra disambiguation argument to ensure that each invocation is distinct.

Regards

Ed Willink
Re: About Family2Person Transformation [message #1792183 is a reply to message #1792163] Thu, 12 July 2018 11:03 Go to previous messageGo to next message
ashrafur rahman is currently offline ashrafur rahmanFriend
Messages: 21
Registered: May 2018
Junior Member
Thanks a lot for your reply. As I am new in QVTo, I don't have enough knowledge about this transformation. I am trying to learn from the different source.

I want to achieve something like this:


mapping Families::Family::Family2Member(): Persons::Person
{

	fullName := self.father.firstName + ' ' + self.lastName;
	fullName := self.mother.firstName + ' ' + self.lastName;
	fullName := self.sons.firstName + ' ' + self.lastName;
	fullName := self.daughters.firstName + ' ' + self.lastName;
}
	


Here, I can get only one full name and the other problem is, sons and daughters can be multiple item, So how can I get all the items?

Thanks again for your kind help.
Re: About Family2Person Transformation [message #1792185 is a reply to message #1792183] Thu, 12 July 2018 11:49 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6112
Registered: July 2009
Senior Member
Hi

I'm a bit puzzled since surely your last snippet is not what you are trying to achieve, but what you have to achieve something with?

Your Family2Member mapping should be invoked once for each Family, and return exactly one Person, whose fullName you have defined four times. Just as if in Java you assign to the same variable 4 times, the first three are list.

If your intention is to return four Persons, then you should return a list so that a distinct object is created for each.

Of course there may be multiple sons so you should create a distinct Person for each.

You probably want each Family2Persons invocation to aggregate the result of multiple Member2Person invocations.

You might find that it helps to draw an instance diagram of typical LHS and RHS so that you can see how your each invocation of each mapping contributes to the overall transformation.

Regards

Ed Willink
Re: About Family2Person Transformation [message #1792220 is a reply to message #1792185] Thu, 12 July 2018 18:09 Go to previous messageGo to next message
ashrafur rahman is currently offline ashrafur rahmanFriend
Messages: 21
Registered: May 2018
Junior Member
Yes, as you mentioned, I want to return a list for each distinct person. I tried several methods, but as my knowledge about QVTo is limited, I was unable to get any meaningful result.
Can you please give me some hint or code snippet to achieve this in the mentioned example? Thank you.
Re: About Family2Person Transformation [message #1792224 is a reply to message #1792220] Thu, 12 July 2018 19:12 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6112
Registered: July 2009
Senior Member
Hi

I think you mistyped. Why do you want a list per Person.

Have you studied the Simpleuml_To_Rdb which most people use as guidance? Section 8.1 of the specification now has some more useful and more accurate tutorial material.

Regards

Ed Willink
Re: About Family2Person Transformation [message #1792225 is a reply to message #1792224] Thu, 12 July 2018 19:43 Go to previous messageGo to next message
ashrafur rahman is currently offline ashrafur rahmanFriend
Messages: 21
Registered: May 2018
Junior Member
Sorry for my ignorance, otherwise how can I aggregate multiple daughters and sons.

I checked Simpleuml_To_Rdb and I am still trying to get the full understanding of this example.

Thank you.
Re: About Family2Person Transformation [message #1792245 is a reply to message #1792225] Fri, 13 July 2018 07:55 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6112
Registered: July 2009
Senior Member
Hi

You may find that http://git.eclipse.org/c/mmt/org.eclipse.qvtd.git/tree/tests/org.eclipse.qvtd.doc.bigmde2016.tests/src/org/eclipse/qvtd/doc/bigmde2016/tests/qvto/Families2Persons.qvto
provides some ideas.

However for a more modular approach I might recommend (untested):

main() {
family.objectsOfKind(fMM::Family)->map Family2Persons()->flatten();
}

mapping fMM::Family::Family2Persons() : List(pMM::Person)
{
result += self.father.map Member2Person();
result += self.mother.map Member2Person();
result += self.sons->map Member2Person();
result += self.daughters->map Member2Person();
}

List is an imperative extension to OCL. You can improve efficieny by passing lastName as a parameter rather than invoking familyName(). repeatedly.

Regards

Ed Willink
Re: About Family2Person Transformation [message #1792246 is a reply to message #1792245] Fri, 13 July 2018 08:03 Go to previous message
ashrafur rahman is currently offline ashrafur rahmanFriend
Messages: 21
Registered: May 2018
Junior Member
Many many thanks. I got some useful idea. This is just what I wanted to do.
Previous Topic:Using QVTo with Xtext
Next Topic:QVTo transformation from command line
Goto Forum:
  


Current Time: Mon Nov 19 05:06:22 GMT 2018

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

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

Back to the top