Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » QVT-OML » Wrong output model structure
Wrong output model structure [message #1850551] Tue, 08 March 2022 11:48 Go to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi,

I have the following example, where the metamodel on the left is the source metamodel and the one on the right the target metamodel.
index.php/fa/41743/0/
If I have the following source model:
University Harvard
-> Room 1-01
->Room 1-02
->Room 2-01

In the target model it should look like this:

University Harvard:
->Floor 1
-->Room 01
-->Room 02
->Floor 2
--> Room 03

Up until now I have the following mapping:

mapping University :: University2University() : University {
  name:=self.name;
  var Floor := object Floor Ob{
    name := self. room.name.substringBefore("-");
    room := self.room -> map Room2Room();
  }
  floor := FloorOb;
}

mapping Room :: Room2Room() : Room {
name := self.name.substringAfter("-");
}



However, there are two issues:

The first is in this line:

Quote:
name := self. room.name.substringBefore("-");


Because I am trying to assign a sequence string to string. When I comment that out, and run the transformations, instead of the expected target model that I included at the beginning, I get:

University Harvard:
->Floor
-->Room 01
-->Room 02
-->Room 03

Could there be a solution for these two issues without changing the metamodels?

Thank you in advance!

[Updated on: Tue, 08 March 2022 11:48]

Report message to a moderator

Re: Wrong output model structure [message #1850555 is a reply to message #1850551] Tue, 08 March 2022 12:41 Go to previous messageGo to next message
Christopher Gerking is currently offline Christopher GerkingFriend
Messages: 115
Registered: April 2011
Senior Member
Hi

These problems seem to be more algorithmic/conceptual than QVTo problems. If you want to have multiple floors, you need to implement some logic to create multiple floors instead of just one. This is like in any other imperative programming language, nothing QVTo-specific.

Regards
Christopher
Re: Wrong output model structure [message #1850556 is a reply to message #1850555] Tue, 08 March 2022 13:04 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi Christopher,

Yes I understand, the issue is that I am not quite aware how to do that with the QVTo syntax, being that not only do I have to create multiple floors, but I also have to make sure to create as many floors, as there are different strings before "_". So in this case, it would have to be two floors, Floor 1 and Floor 2. Could you point me out to some similar examples, or something that can guide me?

Thank you in advance!
Re: Wrong output model structure [message #1850570 is a reply to message #1850556] Tue, 08 March 2022 15:53 Go to previous messageGo to next message
Christopher Gerking is currently offline Christopher GerkingFriend
Messages: 115
Registered: April 2011
Senior Member
The thing is that algorithmic problems (like finding out how many floors to create) have nothing to do with QVTo at all. Try to imagine how you would solve these problems with a general-purpose language of your choice, say Java. On this basis, you can re-implement the same solution with QVTo, since QVTo provides all the necessary language facilities such as for-loops, sets, dictionaries, etc. Once you succeed, we could discuss certain additional possibilities that QVTo offers to simplify your solution.
Re: Wrong output model structure [message #1850571 is a reply to message #1850570] Tue, 08 March 2022 16:46 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

... which usually means doing things in stages.

It would appear that Floor is a critical hidden concept that you need to reify.

So first identify the floors.
Then for each floor handle its rooms.

In Java you might use a Map. In QVTo you might use a Dict.

Regards

Ed Willoink
Previous Topic:Conditional mappings
Next Topic:Change value of ENum attribute depending on type of class
Goto Forum:
  


Current Time: Fri Apr 26 11:53:48 GMT 2024

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

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

Back to the top