Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » Group by name (to created Element)(In context of a tree model, I'm asking to group nodes with same name)
Group by name (to created Element) [message #1802881] Mon, 18 February 2019 13:10 Go to next message
Tai Ly is currently offline Tai LyFriend
Messages: 3
Registered: February 2019
Junior Member
Hello dear community,

I'm working on a transformation from a Tree-Model A to another Tree-Model B, where in both cases Node-Elements are refering to itself bidirectional (parentNode, childNode).
Model A has multiple Nodes with the same name and B should create a parentNode to group them.

rule node2node{
    from
        --all Nodes which names occures more than 1 time
        s_node: A!Node ( A!Node.allInstances() -> collect(n|n.name = s_node.name).size() > 1 )
    to
        parent: B!Node (
            name <- s_node.name + ' Group',
            childNode <- thisModule.resolveTemp(s_node, 'child')
        ),
        child: B!Node(
            name <- s_node.name,
            additional_Information <- s_node.info --this distinguish them
        )
}


the code is creating a new Element properly, but it only adds one Child to it (the corresponding one). Instead i wish to add/refer all Childs with the same name to a Parentnode.

we can assume that the guard is working (i have another one and this is just to simplify. The problem is the Child.

thank you very much,
Tai
Re: Group by name (to created Element) [message #1803073 is a reply to message #1802881] Thu, 21 February 2019 20:23 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 589
Registered: September 2012
Location: Belgium
Senior Member

You can use a unique lazy rule in combination with the Canonic element design pattern:

-- @atlcompiler emftvm
-- @path TREE=/GroupByNameExample/metamodels/Tree.ecore
module GroupByName;
create OUT : TREE from IN : TREE;

--- Returns the Tuple value representation of the TREE!Node.
helper context TREE!Node def : toTuple : TupleType(name : String) =
	Tuple{name = self.name};

rule Node {
	from
		s : TREE!Node
	to
		t : TREE!Node (
			name <- s.name,
			parent <- thisModule.Parent(s.toTuple)
		)
}

unique lazy rule Parent {
	from
		s : TupleType(name : String)
	to
		t : TREE!Node (
			name <- 'Parent of ' + s.name
		)
}


I've attached an example eclipse project.


Cheers,
Dennis
Re: Group by name (to created Element) [message #1803793 is a reply to message #1803073] Sun, 10 March 2019 13:31 Go to previous message
Tai Ly is currently offline Tai LyFriend
Messages: 3
Registered: February 2019
Junior Member
Thank you very much, this helped a lot!

Best wishes,
Tai
Previous Topic:Move an element
Next Topic:Using custom Java Methods with emftvm
Goto Forum:
  


Current Time: Fri Apr 26 18:58:54 GMT 2024

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

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

Back to the top