Search in sources :

Example 1 with CellNode

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

the class TransformationTreeContentProvider method getChilddren.

/**
 * Get the children of a node
 *
 * @param node the node
 * @return the node's children
 */
private Collection<? extends Object> getChilddren(Object node) {
    if (node instanceof IdentityWrapper<?>) {
        node = ((IdentityWrapper<?>) node).getValue();
    }
    if (node instanceof TransformationTree) {
        return wrapNodes(((TransformationTree) node).getChildren(true));
    }
    if (node instanceof TargetNode) {
        List<Object> children = new ArrayList<Object>();
        children.addAll(((TargetNode) node).getChildren(true));
        children.addAll(((TargetNode) node).getAssignments());
        return wrapNodes(children);
    }
    if (node instanceof CellNode) {
        return wrapNodes(((CellNode) node).getSources());
    }
    if (node instanceof SourceNode) {
        SourceNode parent = ((SourceNode) node).getParent();
        if (parent != null) {
            return Collections.singleton(new IdentityWrapper<Object>(parent));
        }
    }
    return Collections.emptyList();
}
Also used : CellNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.CellNode) SourceNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode) TargetNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.TargetNode) IdentityWrapper(eu.esdihumboldt.util.IdentityWrapper) ArrayList(java.util.ArrayList) TransformationTree(eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationTree)

Example 2 with CellNode

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

the class TargetContext method duplicateTree.

/**
 * Duplicates the transformation tree for the given source node to the given
 * duplicate source node.
 *
 * @param source the original source node
 * @param duplicate the duplication target
 * @param info the duplication info object
 * @param log the transformation log
 * @param serviceProvider service provider for resolving functions
 */
private static void duplicateTree(SourceNode source, SourceNode duplicate, DuplicationInformation info, TransformationLog log, ServiceProvider serviceProvider) {
    // Duplicate relations.
    for (CellNode cell : source.getRelations(false)) {
        // check whether the cell is eager for the source node
        if (TransformationTreeUtil.isEager(cell, source, log, serviceProvider))
            continue;
        // Check whether the cell is ignored.
        if (info.isIgnoreCell(cell.getCell()))
            continue;
        // XXX prioritize already created cell nodes (in this run) over old
        // nodes?
        // First check whether an old cell node with a missing source
        // exists.
        // If so, add this source to the first so found cell.
        boolean usedOld = false;
        for (IdentityWrapper<CellNode> wrapper : info.getOldCellNodes(cell.getCell())) {
            CellNode oldCellNode = wrapper.getValue();
            // Skip the cell if it's full.
            if (oldCellNode.getSources().size() == cell.getSources().size())
                continue;
            // Check whether out duplicate source node is missing...
            if (!oldCellNode.getSources().contains(duplicate)) {
                usedOld = true;
                // Has to be a cell created with the cell constructor.
                ((CellNodeImpl) oldCellNode).addSource(cell.getSourceNames(source), duplicate);
                duplicate.addRelation(oldCellNode);
                break;
            }
        }
        // If no old cell was used, use a newly created one / create one.
        if (!usedOld) {
            CellNodeImpl duplicatedCell = info.getNewCellNode(cell.getCell());
            if (duplicatedCell == null) {
                // Create a new cell, augment it with existing sources, add
                // it to info and duplicate targets.
                duplicatedCell = new CellNodeImpl(cell.getCell());
                augmentCell(cell, duplicatedCell, info);
                info.addNewCellNode(cell.getCell(), duplicatedCell);
                duplicateTree(cell, duplicatedCell, info, log);
            }
            // Add as relation/source.
            duplicate.addRelation(duplicatedCell);
            duplicatedCell.addSource(cell.getSourceNames(source), duplicate);
        }
    }
    // Duplicate children.
    for (SourceNode child : source.getChildren(false)) {
        SourceNode duplicatedChild = new SourceNodeImpl(child.getEntityDefinition(), duplicate, true);
        duplicatedChild.setContext(child.getContext());
        duplicateTree(child, duplicatedChild, info, log, serviceProvider);
    }
}
Also used : SourceNodeImpl(eu.esdihumboldt.hale.common.align.model.transformation.tree.impl.SourceNodeImpl) CellNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.CellNode) SourceNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode) CellNodeImpl(eu.esdihumboldt.hale.common.align.model.transformation.tree.impl.CellNodeImpl)

Example 3 with CellNode

use of eu.esdihumboldt.hale.common.align.model.transformation.tree.CellNode 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 4 with CellNode

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

the class TransformationTreeLabelProvider method getText.

/**
 * @see GraphLabelProvider#getText(Object)
 */
@Override
public String getText(Object element) {
    if (element instanceof IdentityWrapper<?>) {
        element = ((IdentityWrapper<?>) element).getValue();
    }
    if (element instanceof EntityConnectionData) {
        // text for connections
        EntityConnectionData connection = (EntityConnectionData) element;
        Set<String> names = null;
        Object source = connection.source;
        if (source instanceof IdentityWrapper<?>) {
            source = ((IdentityWrapper<?>) source).getValue();
        }
        Object dest = connection.dest;
        if (dest instanceof IdentityWrapper<?>) {
            dest = ((IdentityWrapper<?>) dest).getValue();
        }
        if (source instanceof TargetNode && dest instanceof CellNode) {
            names = ((TargetNode) source).getAssignmentNames((CellNode) dest);
        }
        if (source instanceof CellNode && dest instanceof SourceNode) {
            names = ((CellNode) source).getSourceNames((SourceNode) dest);
        }
        if (names != null && !names.isEmpty()) {
            if (names.contains(null)) {
                names = new HashSet<String>(names);
                names.remove(null);
                if (!names.isEmpty()) {
                    names.add("(unnamed)");
                }
            }
            // build name string
            Joiner joiner = Joiner.on(',');
            return joiner.join(names);
        }
        return "";
    }
    if (hasTransformationAnnotations(element)) {
        if (element instanceof SourceNode) {
            SourceNode node = (SourceNode) element;
            if (node.isDefined()) {
                Object value = node.getValue();
                if (value == null) {
                    // no value
                    return "(not set)";
                } else if (value instanceof Instance) {
                    // use the instance value if present
                    value = ((Instance) value).getValue();
                }
                if (value != null && !(value instanceof Group)) {
                    // TODO shorten if needed?
                    return value.toString();
                }
            // otherwise, just display the definition name
            }
        }
    }
    element = TransformationTreeUtil.extractObject(element);
    return super.getText(element);
}
Also used : Group(eu.esdihumboldt.hale.common.instance.model.Group) CellNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.CellNode) SourceNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode) TargetNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.TargetNode) Joiner(com.google.common.base.Joiner) EntityConnectionData(org.eclipse.zest.core.viewers.EntityConnectionData) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) IdentityWrapper(eu.esdihumboldt.util.IdentityWrapper)

Example 5 with CellNode

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

the class TreeGraphMLProvider method setVertexProperty.

/**
 * sets the property of a [@link]Vertex from a [@link]TransformationNode
 *
 * @param node the node-object to get the name from
 * @param vertex the vertex to set the property
 */
private void setVertexProperty(TransformationNode node, Vertex vertex) {
    if (node instanceof TransformationTree) {
        vertex.setProperty("name", ((TransformationTree) node).getType().getDisplayName());
        vertex.setProperty("type", "root");
    }
    if (node instanceof TargetNode) {
        vertex.setProperty("name", ((TargetNode) node).getDefinition().getDisplayName());
        vertex.setProperty("type", "target");
    }
    if (node instanceof SourceNode) {
        SourceNode snode = (SourceNode) node;
        Object value = snode.getValue();
        String name = ((SourceNode) node).getDefinition().getDisplayName();
        if (value instanceof Group) {
            vertex.setProperty("name", name);
            vertex.setProperty("group", getChildrencountString(value));
            vertex.setProperty("type", "source");
        }
        if (value instanceof Instance) {
            if (((Instance) value).getValue() != null) {
                vertex.setProperty("group", getChildrencountString(value));
                vertex.setProperty("value", ((Instance) value).getValue().toString());
                vertex.setProperty("type", "source");
            }
        } else {
            vertex.setProperty("name", name);
            vertex.setProperty("type", "source");
            if (value instanceof String) {
                vertex.setProperty("value", value);
            }
        }
    }
    if (node instanceof CellNode) {
        vertex.setProperty("name", FunctionUtil.getFunction(((CellNode) node).getCell().getTransformationIdentifier(), null).getDisplayName());
        vertex.setProperty("type", "cell");
    }
}
Also used : Group(eu.esdihumboldt.hale.common.instance.model.Group) SourceNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode) CellNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.CellNode) TargetNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.TargetNode) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) TransformationTree(eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationTree)

Aggregations

CellNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.CellNode)7 SourceNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode)6 TargetNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.TargetNode)4 TransformationTree (eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationTree)2 CellNodeImpl (eu.esdihumboldt.hale.common.align.model.transformation.tree.impl.CellNodeImpl)2 Group (eu.esdihumboldt.hale.common.instance.model.Group)2 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)2 IdentityWrapper (eu.esdihumboldt.util.IdentityWrapper)2 ArrayList (java.util.ArrayList)2 Joiner (com.google.common.base.Joiner)1 Edge (com.tinkerpop.blueprints.Edge)1 Graph (com.tinkerpop.blueprints.Graph)1 Vertex (com.tinkerpop.blueprints.Vertex)1 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)1 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)1 GroupNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.GroupNode)1 TransformationNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationNode)1 SourceNodeImpl (eu.esdihumboldt.hale.common.align.model.transformation.tree.impl.SourceNodeImpl)1 TargetNodeImpl (eu.esdihumboldt.hale.common.align.model.transformation.tree.impl.TargetNodeImpl)1 AbstractTargetToSourceVisitor (eu.esdihumboldt.hale.common.align.model.transformation.tree.visitor.AbstractTargetToSourceVisitor)1