Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » Create Tree out of a List(I have )
Create Tree out of a List [message #1723741] Wed, 17 February 2016 14:25 Go to next message
Matthias Seidemann is currently offline Matthias SeidemannFriend
Messages: 1
Registered: February 2016
Junior Member
Hello Community,

I have a rather complex transformation task and I wonder how this can be solved with ATL. The source model is a flat list of elements. However, some of its attributes can be used to build a hierarchy. I provide a source and target model to make it more clear.

The source model looks like this:
<xmi>
  <row name="element1" level0="0" level1="0"/>
  <row name="element2" level0="0" level1="0"/>
  <row name="element3" level0="1" level1="0"/>
  <row name="element4" level0="1" level1="1"/>
  <row name="element5" level0="1" level1="1"/>
  <row name="element6" level0="1" level1="1"/>
</xmi>


The desired target model should look something like this:

<xmi>
  <document>
    <node id="0">
      <node id="0">
        <leaf name="element1">
        <leaf name="element2">
      </node>
    </node>
    <node id="1">
      <node id="0">
        <leaf name="element3">
      </node>
      <node id="1">
        <leaf name="element4">
        <leaf name="element5">
        <leaf name="element6">
      </node>
    </node>
  </document>
</xmi>


I think the complicated part is that nodes should only be created once and then be reused by the other leafs and I did not find any tutorials about such a task. Any suggestions how I can solve this? I would really appreciate the help.

br
Matthias
Re: Create Tree out of a List [message #1725109 is a reply to message #1723741] Mon, 29 February 2016 20:43 Go to previous message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 589
Registered: September 2012
Location: Belgium
Senior Member

You may use lazy unique rules to create the nodes and and endpoint rule to create the document:

module RowsToDocument;
create OUT : OUTMM from IN : INMM;

rule Leaf {
  from
    row : INMM!Row
  to
    node : OUTMM!Leaf (
      name <- row.name
    )
}

unique lazy rule Level0Node {
  from
    level0 : Integer
  to
    node : OUTMM!Node (
      id <- level0,
      children <- INMM!Row.allInstances()
        ->collect(r -> r.level1)->asSet()
        ->collect(level1 -> thisModule.Level1Node(level0, level1))
    )
}

unique lazy rule Level1Node {
  from
    level0 : Integer,
    level1 : Integer
  to
    node : OUTMM!Node (
      id <- level1,
      children <- INMM!Row.allInstances()
        ->select(r -> r.level0 = level0 and r.level1 = level1)
    )
}

endpoint rule Document() {
  to
    document : OUTMM!Document (
      children <- INMM!Row.allInstances()
        ->collect(r -> r.level0)->asSet()
        ->collect(level0 -> thisModule.Level0Node(level0))
    )
}


Cheers,
Dennis
Previous Topic:ATL transformation rules
Next Topic:Generate two targets from one source respectively
Goto Forum:
  


Current Time: Wed Apr 24 13:35:22 GMT 2024

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

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

Back to the top