Search in sources :

Example 1 with TransformationFunctionService

use of eu.esdihumboldt.hale.common.align.service.TransformationFunctionService in project hale by halestudio.

the class ConceptualSchemaTransformer method transform.

/**
 * @see TransformationService#transform(Alignment, InstanceCollection,
 *      InstanceSink, ServiceProvider, ProgressIndicator)
 */
@Override
public TransformationReport transform(Alignment alignment, InstanceCollection source, InstanceSink target, ServiceProvider serviceProvider, ProgressIndicator progressIndicator) {
    TransformationReporter reporter = new DefaultTransformationReporter("Instance transformation", true);
    TransformationContext context = new TransformationContext(serviceProvider, alignment);
    TransformationFunctionService functions = serviceProvider.getService(TransformationFunctionService.class);
    final SubtaskProgressIndicator sub = new SubtaskProgressIndicator(progressIndicator) {

        @Override
        protected String getCombinedTaskName(String taskName, String subtaskName) {
            return taskName + " (" + subtaskName + ")";
        }
    };
    progressIndicator = sub;
    target = new CountingInstanceSink(target) {

        private long lastUpdate = 0;

        @Override
        protected void countChanged(int count) {
            long now = System.currentTimeMillis();
            if (now - lastUpdate > 100) {
                // only update every 100
                // milliseconds
                lastUpdate = now;
                sub.subTask(count + " transformed instances");
            }
        }
    };
    progressIndicator.begin("Transformation", ProgressIndicator.UNKNOWN);
    try {
        EngineManager engines = new EngineManager();
        PropertyTransformer transformer = new TreePropertyTransformer(alignment, reporter, target, engines, context);
        Collection<? extends Cell> typeCells = alignment.getActiveTypeCells();
        // sort type cell by priority
        typeCells = sortTypeCells(typeCells);
        for (Cell typeCell : typeCells) {
            if (progressIndicator.isCanceled()) {
                break;
            }
            List<TypeTransformationFactory> transformations = functions.getTypeTransformations(typeCell.getTransformationIdentifier());
            if (transformations == null || transformations.isEmpty()) {
                reporter.error(new TransformationMessageImpl(typeCell, MessageFormat.format("No transformation for function {0} found. Skipped type transformation.", typeCell.getTransformationIdentifier()), null));
            } else {
                // TODO select based on e.g. preferred transformation
                // engine?
                TypeTransformationFactory transformation = transformations.iterator().next();
                doTypeTransformation(transformation, typeCell, source, target, alignment, engines, transformer, context, reporter, progressIndicator);
            }
        }
        progressIndicator.setCurrentTask("Wait for property transformer to complete");
        // wait for the property transformer to complete
        // cancel property transformations if process was canceled - this
        // may leave transformed instances in inconsistent state
        transformer.join(progressIndicator.isCanceled());
        engines.dispose();
        reporter.setSuccess(true);
        return reporter;
    } finally {
        progressIndicator.end();
    }
}
Also used : EngineManager(eu.esdihumboldt.cst.internal.EngineManager) DefaultTransformationReporter(eu.esdihumboldt.hale.common.align.transformation.report.impl.DefaultTransformationReporter) TransformationFunctionService(eu.esdihumboldt.hale.common.align.service.TransformationFunctionService) CountingInstanceSink(eu.esdihumboldt.cst.internal.util.CountingInstanceSink) SubtaskProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.SubtaskProgressIndicator) TransformationContext(eu.esdihumboldt.cst.internal.TransformationContext) TypeTransformationFactory(eu.esdihumboldt.hale.common.align.extension.transformation.TypeTransformationFactory) TransformationMessageImpl(eu.esdihumboldt.hale.common.align.transformation.report.impl.TransformationMessageImpl) TransformationReporter(eu.esdihumboldt.hale.common.align.transformation.report.TransformationReporter) DefaultTransformationReporter(eu.esdihumboldt.hale.common.align.transformation.report.impl.DefaultTransformationReporter) PropertyTransformer(eu.esdihumboldt.hale.common.align.transformation.service.PropertyTransformer) TreePropertyTransformer(eu.esdihumboldt.cst.internal.TreePropertyTransformer) Cell(eu.esdihumboldt.hale.common.align.model.Cell) TreePropertyTransformer(eu.esdihumboldt.cst.internal.TreePropertyTransformer)

Aggregations

EngineManager (eu.esdihumboldt.cst.internal.EngineManager)1 TransformationContext (eu.esdihumboldt.cst.internal.TransformationContext)1 TreePropertyTransformer (eu.esdihumboldt.cst.internal.TreePropertyTransformer)1 CountingInstanceSink (eu.esdihumboldt.cst.internal.util.CountingInstanceSink)1 TypeTransformationFactory (eu.esdihumboldt.hale.common.align.extension.transformation.TypeTransformationFactory)1 Cell (eu.esdihumboldt.hale.common.align.model.Cell)1 TransformationFunctionService (eu.esdihumboldt.hale.common.align.service.TransformationFunctionService)1 TransformationReporter (eu.esdihumboldt.hale.common.align.transformation.report.TransformationReporter)1 DefaultTransformationReporter (eu.esdihumboldt.hale.common.align.transformation.report.impl.DefaultTransformationReporter)1 TransformationMessageImpl (eu.esdihumboldt.hale.common.align.transformation.report.impl.TransformationMessageImpl)1 PropertyTransformer (eu.esdihumboldt.hale.common.align.transformation.service.PropertyTransformer)1 SubtaskProgressIndicator (eu.esdihumboldt.hale.common.core.io.impl.SubtaskProgressIndicator)1