use of eu.esdihumboldt.hale.common.align.model.transformation.tree.visitor.TreeToGraphVisitor in project hale by halestudio.
the class TGraphFactory method create.
/**
* Create a transformation graph from a transformation tree.
*
* @param ttree the transformation tree
* @param functionService the function service
* @return an in-memory graph created from the transformation tree
*/
public static Graph create(TransformationTree ttree, FunctionService functionService) {
TreeToGraphVisitor graphVisitor = new TreeToGraphVisitor(functionService);
ttree.accept(graphVisitor);
SetMultimap<String, String> connections = graphVisitor.getAllConnections();
Set<String> ids = graphVisitor.getAllIds();
Graph graph = new TinkerGraph();
// add nodes to the graph
for (String key : ids) {
// create a vertex for each transformation node
TransformationNode node = graphVisitor.getNode(key);
Vertex vertex = graph.addVertex(key);
setVertexProperties(vertex, node);
}
for (String key : connections.keySet()) {
for (String value : connections.get(key)) {
Vertex targetSide = graph.getVertex(key);
Vertex sourceSide = graph.getVertex(value);
TransformationNode targetSideNode = graphVisitor.getNode(key);
TransformationNode sourceSideNode = graphVisitor.getNode(value);
String edgeLabel;
if (sourceSideNode instanceof SourceNode && targetSideNode instanceof SourceNode) {
edgeLabel = EDGE_CHILD;
} else if (sourceSideNode instanceof SourceNode && targetSideNode instanceof CellNode) {
edgeLabel = EDGE_VARIABLE;
} else if (sourceSideNode instanceof CellNode && targetSideNode instanceof GroupNode) {
edgeLabel = EDGE_RESULT;
} else if (sourceSideNode instanceof GroupNode && targetSideNode instanceof GroupNode) {
edgeLabel = EDGE_PARENT;
} else {
throw new IllegalStateException("Invalid relation in transformation tree");
}
Edge edge = graph.addEdge(null, sourceSide, targetSide, edgeLabel);
setEdgeProperties(edge, sourceSideNode, targetSideNode);
}
}
return graph;
}
Aggregations