Search in sources :

Example 1 with InstanceVisitor

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

Example 2 with InstanceVisitor

use of eu.esdihumboldt.hale.common.align.model.transformation.tree.visitor.InstanceVisitor 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)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 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 TransformationTreeImpl (eu.esdihumboldt.hale.common.align.model.transformation.tree.impl.TransformationTreeImpl)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 FamilyInstance (eu.esdihumboldt.hale.common.instance.model.FamilyInstance)1 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)1 MutableInstance (eu.esdihumboldt.hale.common.instance.model.MutableInstance)1 HashSet (java.util.HashSet)1