Search in sources :

Example 1 with TransformationNode

use of eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationNode 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;
}
Also used : TransformationNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationNode) Vertex(com.tinkerpop.blueprints.Vertex) CellNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.CellNode) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) TreeToGraphVisitor(eu.esdihumboldt.hale.common.align.model.transformation.tree.visitor.TreeToGraphVisitor) GroupNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.GroupNode) SourceNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) Edge(com.tinkerpop.blueprints.Edge)

Example 2 with TransformationNode

use of eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationNode in project hale by halestudio.

the class TreeGraphMLProvider method generateGraph.

/**
 * @see eu.esdihumboldt.hale.ui.cst.debug.metadata.internal.TreeGraphProvider#generateGraph()
 */
@Override
public Graph generateGraph() {
    tree.accept(graphVisitor);
    SetMultimap<String, String> connections = graphVisitor.getAllConnections();
    Set<String> ids = graphVisitor.getAllIds();
    TinkerGraph graph = new TinkerGraph();
    // add nodes to the graph
    for (String key : ids) {
        TransformationNode node = graphVisitor.getNode(key);
        Vertex vertex = graph.addVertex(key);
        setVertexProperty(node, vertex);
    }
    for (String key : connections.keySet()) {
        for (String value : connections.get(key)) {
            graph.addEdge(null, graph.getVertex(key), graph.getVertex(value), " ");
        }
    }
    return graph;
}
Also used : TransformationNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationNode) Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph)

Aggregations

Vertex (com.tinkerpop.blueprints.Vertex)2 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)2 TransformationNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationNode)2 Edge (com.tinkerpop.blueprints.Edge)1 Graph (com.tinkerpop.blueprints.Graph)1 CellNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.CellNode)1 GroupNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.GroupNode)1 SourceNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode)1 TreeToGraphVisitor (eu.esdihumboldt.hale.common.align.model.transformation.tree.visitor.TreeToGraphVisitor)1