Search in sources :

Example 1 with TypeTransformationFactory

use of eu.esdihumboldt.hale.common.align.extension.transformation.TypeTransformationFactory 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)

Example 2 with TypeTransformationFactory

use of eu.esdihumboldt.hale.common.align.extension.transformation.TypeTransformationFactory in project hale by halestudio.

the class InstanceIndexServiceImpl method addPropertyMappings.

@Override
public boolean addPropertyMappings(Iterable<? extends Cell> cells, ServiceProvider serviceProvider) {
    if (serviceProvider == null) {
        throw new NullPointerException("Service provider must not be null");
    }
    boolean result = false;
    for (Cell cell : cells) {
        List<TypeTransformationFactory> functions = TransformationFunctionUtil.getTypeTransformations(cell.getTransformationIdentifier(), serviceProvider);
        if (functions.isEmpty()) {
            // Not a type transformation cell
            continue;
        }
        TypeTransformation<?> transformation;
        try {
            transformation = functions.get(0).createExtensionObject();
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
        List<List<PropertyEntityDefinition>> indexedProperties = new ArrayList<>();
        if (transformation instanceof InstanceIndexContribution) {
            InstanceIndexContribution contribution = (InstanceIndexContribution) transformation;
            indexedProperties.addAll(contribution.getIndexContribution(cell));
        }
        if (!indexedProperties.isEmpty()) {
            result = true;
            for (List<PropertyEntityDefinition> properties : indexedProperties) {
                this.addPropertyMapping(properties);
            }
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) TypeTransformationFactory(eu.esdihumboldt.hale.common.align.extension.transformation.TypeTransformationFactory) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ArrayList(java.util.ArrayList) List(java.util.List) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Aggregations

TypeTransformationFactory (eu.esdihumboldt.hale.common.align.extension.transformation.TypeTransformationFactory)2 Cell (eu.esdihumboldt.hale.common.align.model.Cell)2 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 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)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 ArrayList (java.util.ArrayList)1 List (java.util.List)1