Search in sources :

Example 1 with TransformationTreeImpl

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

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

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

Aggregations

TransformationTree (eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationTree)3 TransformationTreeImpl (eu.esdihumboldt.hale.common.align.model.transformation.tree.impl.TransformationTreeImpl)3 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 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 DuplicationVisitor (eu.esdihumboldt.hale.common.align.model.transformation.tree.visitor.DuplicationVisitor)1 InstanceVisitor (eu.esdihumboldt.hale.common.align.model.transformation.tree.visitor.InstanceVisitor)1 FunctionService (eu.esdihumboldt.hale.common.align.service.FunctionService)1 AlignmentFunctionService (eu.esdihumboldt.hale.common.align.service.impl.AlignmentFunctionService)1 TGraph (eu.esdihumboldt.hale.common.align.tgraph.TGraph)1 TGraphImpl (eu.esdihumboldt.hale.common.align.tgraph.impl.TGraphImpl)1 TransformationException (eu.esdihumboldt.hale.common.align.transformation.function.TransformationException)1 FamilyInstanceImpl (eu.esdihumboldt.hale.common.align.transformation.function.impl.FamilyInstanceImpl)1 TransformationLog (eu.esdihumboldt.hale.common.align.transformation.report.TransformationLog)1 TransformationMessage (eu.esdihumboldt.hale.common.align.transformation.report.TransformationMessage)1 CellLog (eu.esdihumboldt.hale.common.align.transformation.report.impl.CellLog)1 DefaultTransformationReporter (eu.esdihumboldt.hale.common.align.transformation.report.impl.DefaultTransformationReporter)1