Example: Transform a Tree model to a Graph model with ETL


  • Tree2Graph.etl
  • Tree.emf
  • Graph.emf
  • Get it!
rule Tree2Node 
  transform t : Tree!Tree
  to n : Graph!Node {
  
  n.name := t.label;
  if (t.parent.isDefined()) {
    var e : new Graph!Edge;
    e.source ::= t.parent;
    e.target := n;
  }  
}
@namespace(uri="Tree", prefix="Tree")
package Tree;

class Tree {
   val Tree[*]#parent children;
   ref Tree#children parent;
   attr String label;
}
@namespace(uri="Graph", prefix="Graph")
package Graph;

class Graph {
   val Node[*] nodes;
}

class Node {
   attr String name;
   val Edge[*]#source outgoing;
   ref Edge[*]#target incoming;
}

class Edge {
   ref Node#outgoing source;
   ref Node#incoming target;
}

There are two ways to get the code of this example:

  1. download the following zip archive(s), extract them and import them as new Eclipse projects
  2. or check out the code from the SVN
    • go to the SVN repository
    • navigate to trunk/examples
    • check out the org.eclipse.epsilon.examples.metamodels project
    • check out the org.eclipse.epsilon.examples.tree2graph project

Once you have checked out/imported the code, to run the example you need to go through the following steps:

  1. register all .ecore metamodels in the org.eclipse.epsilon.examples.metamodels project (select all of them and then right click and select Register EPackages)
  2. right click the .launch file in the org.eclipse.epsilon.examples.tree2graph project
  3. select Run as... and click the first item in the menu that pops up