Search in sources :

Example 6 with TransformationTree

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

the class TargetContext method duplicateTree.

/**
 * Duplicates the transformation tree for the given target node to the given
 * duplicate target node.
 *
 * @param target the original target node
 * @param info the duplication info object
 * @param log the transformation log
 * @return a collection of newly created target nodes
 */
private static TargetNodeImpl duplicateTree(TargetNode target, DuplicationInformation info, TransformationLog log) {
    GroupNode parent = null;
    // Check if the parent node exists in the given context already.
    if (target.getParent() instanceof TargetNode) {
        Iterator<TargetNode> possibleParents = info.getAllTargetNodes(((TargetNode) target.getParent()).getEntityDefinition()).iterator();
        while (possibleParents.hasNext()) {
            TargetNode possibleParent = possibleParents.next();
            if (info.getContextTargets().contains(target) || !possibleParent.getChildren(false).contains(target)) {
                parent = possibleParent;
                break;
            }
        }
    } else if (target.getParent() instanceof TransformationTree && info.getContextTargets().contains(target)) {
        // Reached root, but this is a possible target.
        parent = target.getParent();
    } else {
        // Reached root, but this is no possible target or the parent is
        // null!
        // XXX instead log and return null or not connected TargetNode? See
        // T O D O below
        log.warn(log.createMessage("DuplicationContext present, but no matching target found.", null));
        return null;
    // throw new IllegalStateException(
    // "DuplicationContext present, but no matching target found.");
    }
    if (parent == null) {
        // Does not exist: recursion.
        TargetNodeImpl duplicatedTarget = duplicateTree((TargetNode) target.getParent(), info, log);
        if (duplicatedTarget == null) {
            return null;
        }
        TargetNodeImpl newTarget = new TargetNodeImpl(target.getEntityDefinition(), duplicatedTarget);
        info.addNewTargetNode(newTarget.getEntityDefinition(), newTarget);
        duplicatedTarget.addChild(newTarget);
        return newTarget;
    } else {
        // Exists: add as child.
        TargetNodeImpl newTarget = new TargetNodeImpl(target.getEntityDefinition(), parent);
        info.addNewTargetNode(newTarget.getEntityDefinition(), newTarget);
        // as annotated child.
        if (parent instanceof TargetNodeImpl && !parent.getChildren(false).contains(newTarget))
            ((TargetNodeImpl) parent).addChild(newTarget);
        else
            parent.addAnnotatedChild(newTarget);
        return newTarget;
    }
}
Also used : TargetNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.TargetNode) TransformationTree(eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationTree) GroupNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.GroupNode) TargetNodeImpl(eu.esdihumboldt.hale.common.align.model.transformation.tree.impl.TargetNodeImpl)

Example 7 with TransformationTree

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

the class TransformationTreeContentProvider method createInstanceTree.

/**
 * Create a transformation tree based on a source instance.
 *
 * @param instance the source instance
 * @param typeCell the type cell
 * @param alignment the alignment
 * @return the transformation tree or <code>null</code>
 */
private TransformationTree createInstanceTree(Instance instance, Cell typeCell, Alignment alignment) {
    TransformationTree tree = new TransformationTreeImpl(alignment, typeCell);
    ReportLog<TransformationMessage> reporter = new DefaultTransformationReporter("Transformation tree", true);
    TransformationLog log = new CellLog(reporter, typeCell);
    // context matching
    // XXX instead through service/extension point?
    ContextMatcher matcher = new AsDeepAsPossible(null);
    matcher.findMatches(tree);
    // process and annotate the tree
    InstanceVisitor visitor = new InstanceVisitor(new FamilyInstanceImpl(instance), tree, log);
    tree.accept(visitor);
    // duplicate subtree as necessary
    DuplicationVisitor duplicationVisitor = new DuplicationVisitor(tree, log);
    tree.accept(duplicationVisitor);
    duplicationVisitor.doAugmentationTrackback();
    return tree;
}
Also used : TransformationTreeImpl(eu.esdihumboldt.hale.common.align.model.transformation.tree.impl.TransformationTreeImpl) TransformationMessage(eu.esdihumboldt.hale.common.align.transformation.report.TransformationMessage) FamilyInstanceImpl(eu.esdihumboldt.hale.common.align.transformation.function.impl.FamilyInstanceImpl) AsDeepAsPossible(eu.esdihumboldt.hale.common.align.model.transformation.tree.context.impl.matcher.AsDeepAsPossible) DefaultTransformationReporter(eu.esdihumboldt.hale.common.align.transformation.report.impl.DefaultTransformationReporter) TransformationTree(eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationTree) TransformationLog(eu.esdihumboldt.hale.common.align.transformation.report.TransformationLog) CellLog(eu.esdihumboldt.hale.common.align.transformation.report.impl.CellLog) ContextMatcher(eu.esdihumboldt.hale.common.align.model.transformation.tree.context.ContextMatcher) InstanceVisitor(eu.esdihumboldt.hale.common.align.model.transformation.tree.visitor.InstanceVisitor) DuplicationVisitor(eu.esdihumboldt.hale.common.align.model.transformation.tree.visitor.DuplicationVisitor)

Example 8 with TransformationTree

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

TransformationTree (eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationTree)8 TargetNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.TargetNode)4 SourceNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode)3 TransformationTreeImpl (eu.esdihumboldt.hale.common.align.model.transformation.tree.impl.TransformationTreeImpl)3 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)3 CellNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.CellNode)2 DuplicationVisitor (eu.esdihumboldt.hale.common.align.model.transformation.tree.visitor.DuplicationVisitor)2 InstanceVisitor (eu.esdihumboldt.hale.common.align.model.transformation.tree.visitor.InstanceVisitor)2 IdentityWrapper (eu.esdihumboldt.util.IdentityWrapper)2 ArrayList (java.util.ArrayList)2 Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)1 Cell (eu.esdihumboldt.hale.common.align.model.Cell)1 Entity (eu.esdihumboldt.hale.common.align.model.Entity)1 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)1 GroupNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.GroupNode)1 ContextMatcher (eu.esdihumboldt.hale.common.align.model.transformation.tree.context.ContextMatcher)1 AsDeepAsPossible (eu.esdihumboldt.hale.common.align.model.transformation.tree.context.impl.matcher.AsDeepAsPossible)1 TargetNodeImpl (eu.esdihumboldt.hale.common.align.model.transformation.tree.impl.TargetNodeImpl)1 FunctionService (eu.esdihumboldt.hale.common.align.service.FunctionService)1 AlignmentFunctionService (eu.esdihumboldt.hale.common.align.service.impl.AlignmentFunctionService)1