Search in sources :

Example 1 with TransformationTree

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

the class TransformationTreeContentProvider method getElements.

/**
 * @see ArrayContentProvider#getElements(Object)
 */
@SuppressWarnings("unchecked")
@Override
public Object[] getElements(Object inputElement) {
    if (inputElement instanceof TransformationTree)
        return collectNodes((TransformationTree) inputElement).toArray();
    Collection<Instance> instances = null;
    if (inputElement instanceof Pair<?, ?>) {
        Pair<?, ?> pair = (Pair<?, ?>) inputElement;
        inputElement = pair.getFirst();
        if (pair.getSecond() instanceof Collection<?>) {
            instances = (Collection<Instance>) pair.getSecond();
        }
    }
    if (inputElement instanceof Alignment) {
        Alignment alignment = (Alignment) inputElement;
        // input contained specific instances
        if (instances != null && !instances.isEmpty()) {
            Collection<Object> result = new ArrayList<Object>();
            // create transformation trees for each instance
            for (Instance instance : instances) {
                // find type cells matching the instance
                Collection<? extends Cell> typeCells = alignment.getActiveTypeCells();
                Collection<Cell> associatedTypeCells = new LinkedList<Cell>();
                for (Cell typeCell : typeCells) for (Entity entity : typeCell.getSource().values()) {
                    TypeEntityDefinition type = (TypeEntityDefinition) entity.getDefinition();
                    if (type.getDefinition().equals(instance.getDefinition()) && (type.getFilter() == null || type.getFilter().match(instance))) {
                        associatedTypeCells.add(typeCell);
                        break;
                    }
                }
                // for each type cell one tree
                for (Cell cell : associatedTypeCells) {
                    TransformationTree tree = createInstanceTree(instance, cell, alignment);
                    if (tree != null)
                        result.addAll(collectNodes(tree));
                }
            }
            return result.toArray();
        }
        // input was alignment only, show trees for all type cells
        Collection<? extends Cell> typeCells = alignment.getActiveTypeCells();
        Collection<Object> result = new ArrayList<Object>(typeCells.size());
        for (Cell typeCell : typeCells) {
            // create tree and add nodes for each cell
            result.addAll(collectNodes(new TransformationTreeImpl(alignment, typeCell)));
        }
        return result.toArray();
    }
    return super.getElements(inputElement);
}
Also used : TransformationTreeImpl(eu.esdihumboldt.hale.common.align.model.transformation.tree.impl.TransformationTreeImpl) Entity(eu.esdihumboldt.hale.common.align.model.Entity) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) ArrayList(java.util.ArrayList) TransformationTree(eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationTree) LinkedList(java.util.LinkedList) Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) Collection(java.util.Collection) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Pair(eu.esdihumboldt.util.Pair)

Example 2 with TransformationTree

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

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

the class TransformationTreeLabelProvider method getFigure.

/**
 * @see GraphLabelProvider#getFigure(Object)
 */
@Override
public IFigure getFigure(Object element) {
    if (element instanceof IdentityWrapper<?>) {
        element = ((IdentityWrapper<?>) element).getValue();
    }
    ShapePainter shape = null;
    String contextText = null;
    String cardText = null;
    if (element instanceof TransformationTree) {
        shape = new TransformationNodeShape(10, SWT.NONE);
    } else if (element instanceof TargetNode) {
        TargetNode node = (TargetNode) element;
        contextText = AlignmentUtil.getContextText(node.getEntityDefinition());
        if (!hasTransformationAnnotations(element)) {
            cardText = getCardinalityText(node.getEntityDefinition().getDefinition());
        }
        if (node.getAssignments().isEmpty()) {
            shape = new TransformationNodeShape(10, SWT.NONE);
        } else {
            // shape = new TransformationNodeShape(10, SWT.LEFT);
            shape = new FingerPost(10, SWT.LEFT);
        }
    } else if (element instanceof SourceNode) {
        SourceNode node = (SourceNode) element;
        contextText = AlignmentUtil.getContextText(node.getEntityDefinition());
        if (!hasTransformationAnnotations(element)) {
            cardText = getCardinalityText(node.getEntityDefinition().getDefinition());
        }
        if (node.getParent() == null) {
            shape = new TransformationNodeShape(10, SWT.NONE);
        } else {
            shape = new FingerPost(10, SWT.RIGHT);
        }
    }
    if (shape != null) {
        CustomShapeFigure figure;
        if (contextText != null || cardText != null) {
            figure = new EntityFigure(shape, contextText, cardText, getCustomFigureFont());
        } else {
            figure = new CustomShapeLabel(shape, getCustomFigureFont());
        }
        figure.setMaximumWidth(MAX_FIGURE_WIDTH);
        return figure;
    }
    element = TransformationTreeUtil.extractObject(element);
    return super.getFigure(element);
}
Also used : SourceNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode) TargetNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.TargetNode) EntityFigure(eu.esdihumboldt.hale.ui.common.graph.figures.EntityFigure) CustomShapeFigure(eu.esdihumboldt.hale.ui.util.graph.CustomShapeFigure) FingerPost(eu.esdihumboldt.hale.ui.util.graph.shapes.FingerPost) IdentityWrapper(eu.esdihumboldt.util.IdentityWrapper) TransformationTree(eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationTree) ShapePainter(eu.esdihumboldt.hale.ui.util.graph.CustomShapeFigure.ShapePainter) CustomShapeLabel(eu.esdihumboldt.hale.ui.util.graph.CustomShapeLabel) TransformationNodeShape(eu.esdihumboldt.hale.ui.common.graph.figures.TransformationNodeShape)

Example 4 with TransformationTree

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

the class XslRetype method createPropertiesFragment.

/**
 * Create a XSL fragment for populating the properties of a target instance.
 *
 * @param typeCell the associated type cell
 * @return the XSL fragment
 * @throws TransformationException if creating the fragment failed
 */
protected String createPropertiesFragment(final Cell typeCell) throws TransformationException {
    final TransformationTree tree = new TransformationTreeImpl(context().getAlignment(), typeCell);
    FunctionService functionService = new AlignmentFunctionService(context().getAlignment());
    /*
		 * Create the transformation graph derived from the transformation tree
		 * and perform context matching.
		 */
    /*
		 * XXX proxying multi-result nodes omitted for now, see
		 * proxyMultiResultNodes imlementation
		 */
    // final TGraph graph = new TGraphImpl(tree).proxyMultiResultNodes().performContextMatching();
    final TGraph graph = new TGraphImpl(tree, functionService).performContextMatching();
    // TODO tree as GraphML as informative annotation into XSLT?
    try {
        StringWriter propsOut = new StringWriter();
        try {
            AbstractTransformationTraverser trav = new RetypeTraverser(context(), propsOut, typeCell);
            trav.traverse(graph);
        } finally {
            propsOut.close();
        }
        return propsOut.toString();
    } catch (Exception e) {
        throw new TransformationException("Failed to create property transformations", e);
    }
}
Also used : TransformationTreeImpl(eu.esdihumboldt.hale.common.align.model.transformation.tree.impl.TransformationTreeImpl) TransformationException(eu.esdihumboldt.hale.common.align.transformation.function.TransformationException) StringWriter(java.io.StringWriter) AbstractTransformationTraverser(eu.esdihumboldt.hale.io.xslt.transformations.base.AbstractTransformationTraverser) TransformationTree(eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationTree) FunctionService(eu.esdihumboldt.hale.common.align.service.FunctionService) AlignmentFunctionService(eu.esdihumboldt.hale.common.align.service.impl.AlignmentFunctionService) TGraphImpl(eu.esdihumboldt.hale.common.align.tgraph.impl.TGraphImpl) AlignmentFunctionService(eu.esdihumboldt.hale.common.align.service.impl.AlignmentFunctionService) TGraph(eu.esdihumboldt.hale.common.align.tgraph.TGraph) TransformationException(eu.esdihumboldt.hale.common.align.transformation.function.TransformationException)

Example 5 with TransformationTree

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

the class TreePropertyTransformer method publish.

/**
 * @see PropertyTransformer#publish(FamilyInstance, MutableInstance,
 *      TransformationLog, Cell)
 */
@Override
public void publish(final FamilyInstance source, final MutableInstance target, final TransformationLog typeLog, final Cell typeCell) {
    instanceCounter.adjustOrPutValue(typeCell, 1, 1);
    // increase output type counter
    reporter.stats().at("createdPerType").at(target.getDefinition().getName().toString()).next();
    Runnable job = new Runnable() {

        @Override
        public void run() {
            try {
                SimpleLogContext.withLog(typeLog, () -> {
                    // Add the meta data ID of the source as SourceID to the
                    // target
                    Collection<Instance> sources = InstanceUtil.getInstanceOutOfFamily(source);
                    Set<Object> ids = new HashSet<Object>();
                    for (Instance inst : sources) {
                        // Merge instances may have multiple IDs
                        List<Object> sourceIDs = inst.getMetaData(InstanceMetadata.METADATA_ID);
                        if (sourceIDs != null) {
                            ids.addAll(sourceIDs);
                        }
                    }
                    InstanceMetadata.setSourceID(target, ids.toArray());
                    // identify transformations to be executed on given
                    // instances
                    // create/get a transformation tree
                    TransformationTree tree = treePool.getTree(typeCell);
                    // State: base tree
                    HooksUtil.executeTreeHooks(treeHooks, TreeState.MINIMAL, tree, target);
                    // apply instance value to transformation tree
                    InstanceVisitor instanceVisitor = new InstanceVisitor(source, tree, typeLog);
                    tree.accept(instanceVisitor);
                    // State: basic source populated tree
                    // duplicate subtree as necessary
                    DuplicationVisitor duplicationVisitor = new DuplicationVisitor(tree, typeLog);
                    tree.accept(duplicationVisitor);
                    duplicationVisitor.doAugmentationTrackback();
                    // State: source populated tree (duplication complete)
                    HooksUtil.executeTreeHooks(treeHooks, TreeState.SOURCE_POPULATED, tree, target);
                    // apply functions
                    for (FunctionExecutor functionExecutor : executors) {
                        functionExecutor.setTypeCell(typeCell);
                        tree.accept(functionExecutor);
                    }
                    // State: full tree (target populated)
                    HooksUtil.executeTreeHooks(treeHooks, TreeState.FULL, tree, target);
                    // fill instance
                    builder.populate(target, tree, typeLog);
                    // generate the rest of the metadatas
                    metaworkerthread.get().generate(target);
                    // XXX ok to add to sink in any thread?!
                    // XXX addInstance and close were made synchronized in
                    // OrientInstanceSink
                    // XXX instead collect instances and write them in only
                    // one
                    // thread?
                    // after property transformations, publish target
                    // instance
                    sink.addInstance(target);
                    // and release the tree for further use
                    treePool.releaseTree(tree);
                });
            } catch (Throwable e) {
                /*
					 * Catch any error, as exceptions in the executor service
					 * will only result in a message on the console.
					 */
                typeLog.error(typeLog.createMessage("Error performing property transformations", e));
            }
        }
    };
    if (executorService != null) {
        executorService.execute(job);
    } else {
        job.run();
    }
}
Also used : FamilyInstance(eu.esdihumboldt.hale.common.instance.model.FamilyInstance) MutableInstance(eu.esdihumboldt.hale.common.instance.model.MutableInstance) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) TransformationTree(eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationTree) InstanceVisitor(eu.esdihumboldt.hale.common.align.model.transformation.tree.visitor.InstanceVisitor) HashSet(java.util.HashSet) DuplicationVisitor(eu.esdihumboldt.hale.common.align.model.transformation.tree.visitor.DuplicationVisitor)

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