Search in sources :

Example 1 with ServiceProvider

use of eu.esdihumboldt.hale.common.core.service.ServiceProvider in project hale by halestudio.

the class NetworkExpansionExplanation method getExplanation.

@Override
protected String getExplanation(Cell cell, boolean html, ServiceProvider services, Locale locale) {
    Entity target = CellUtil.getFirstEntity(cell.getTarget());
    String expression = CellUtil.getFirstParameter(cell, PARAMETER_BUFFER_WIDTH).as(String.class);
    List<? extends Entity> variables = cell.getSource().get(ENTITY_VARIABLE);
    List<? extends Entity> geom = cell.getSource().get(null);
    if (target != null && expression != null) {
        if (html)
            expression = "<pre>" + expression + "</pre>";
        String explanation = MessageFormat.format(getMessage("main", locale), formatEntity(geom.get(0), html, true, locale), formatEntity(target, html, true, locale), expression);
        if (html)
            explanation = explanation.replaceAll("\n", "<br />");
        if (html) {
            Map<String, String> varToProperty = variables.stream().collect(Collectors.toMap(entity -> {
                return getEntityNameWithoutCondition(entity);
            }, entity -> {
                return formatEntity(entity, true, false, locale);
            }));
            explanation += buildReplacementTable(varToProperty, locale);
        }
        return explanation;
    }
    return null;
}
Also used : List(java.util.List) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Locale(java.util.Locale) Map(java.util.Map) ServiceProvider(eu.esdihumboldt.hale.common.core.service.ServiceProvider) Entity(eu.esdihumboldt.hale.common.align.model.Entity) AbstractCellExplanation(eu.esdihumboldt.hale.common.align.model.impl.AbstractCellExplanation) Collectors(java.util.stream.Collectors) CellUtil(eu.esdihumboldt.hale.common.align.model.CellUtil) MessageFormat(java.text.MessageFormat) Entity(eu.esdihumboldt.hale.common.align.model.Entity)

Example 2 with ServiceProvider

use of eu.esdihumboldt.hale.common.core.service.ServiceProvider in project hale by halestudio.

the class ReprojectGeometryTest method transformData.

@Override
protected List<Instance> transformData(TransformationExample example) throws Exception {
    ConceptualSchemaTransformer transformer = new ConceptualSchemaTransformer();
    DefaultInstanceSink sink = new DefaultInstanceSink();
    final Map<Class<?>, Object> customServices = new HashMap<>();
    customServices.put(FunctionService.class, new AlignmentFunctionService(example.getAlignment()));
    customServices.put(TransformationFunctionService.class, new AlignmentTransformationFunctionService(example.getAlignment()));
    final ServiceProvider serviceProvider = new ServiceProvider() {

        private final ServiceProvider projectScope = new ServiceManager(ServiceManager.SCOPE_PROJECT);

        @SuppressWarnings("unchecked")
        @Override
        public <T> T getService(Class<T> serviceInterface) {
            if (customServices.containsKey(serviceInterface)) {
                return (T) customServices.get(serviceInterface);
            }
            // FIXME global scope not supported yet
            return projectScope.getService(serviceInterface);
        }
    };
    transformer.transform(example.getAlignment(), example.getSourceInstances(), sink, serviceProvider, new NullProgressIndicator());
    return sink.getInstances();
}
Also used : AlignmentTransformationFunctionService(eu.esdihumboldt.hale.common.align.service.impl.AlignmentTransformationFunctionService) ConceptualSchemaTransformer(eu.esdihumboldt.cst.ConceptualSchemaTransformer) HashMap(java.util.HashMap) ServiceManager(eu.esdihumboldt.hale.common.core.service.ServiceManager) DefaultInstanceSink(eu.esdihumboldt.hale.common.align.transformation.service.impl.DefaultInstanceSink) ServiceProvider(eu.esdihumboldt.hale.common.core.service.ServiceProvider) NullProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.NullProgressIndicator) AlignmentFunctionService(eu.esdihumboldt.hale.common.align.service.impl.AlignmentFunctionService)

Example 3 with ServiceProvider

use of eu.esdihumboldt.hale.common.core.service.ServiceProvider in project hale by halestudio.

the class MathematicalExpressionExplanation method getExplanation.

@Override
protected String getExplanation(Cell cell, boolean html, ServiceProvider services, Locale locale) {
    Entity target = CellUtil.getFirstEntity(cell.getTarget());
    String expression = CellUtil.getFirstParameter(cell, MathematicalExpression.PARAMETER_EXPRESSION).as(String.class);
    List<? extends Entity> sources = cell.getSource().get(MathematicalExpression.ENTITY_VARIABLE);
    if (target != null && expression != null) {
        if (html)
            expression = "<pre>" + expression + "</pre>";
        String explanation = MessageFormat.format(getMessage("main", locale), formatEntity(target, html, true, locale), expression);
        if (html)
            explanation = explanation.replaceAll("\n", "<br />");
        if (html) {
            Map<String, String> varToProperty = sources.stream().collect(Collectors.toMap(entity -> {
                return getEntityNameWithoutCondition(entity);
            }, entity -> {
                return formatEntity(entity, true, false, locale);
            }));
            explanation += buildReplacementTable(varToProperty, locale);
        }
        return explanation;
    }
    return null;
}
Also used : List(java.util.List) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Locale(java.util.Locale) Map(java.util.Map) ServiceProvider(eu.esdihumboldt.hale.common.core.service.ServiceProvider) Entity(eu.esdihumboldt.hale.common.align.model.Entity) AbstractCellExplanation(eu.esdihumboldt.hale.common.align.model.impl.AbstractCellExplanation) Collectors(java.util.stream.Collectors) CellUtil(eu.esdihumboldt.hale.common.align.model.CellUtil) MessageFormat(java.text.MessageFormat) Entity(eu.esdihumboldt.hale.common.align.model.Entity)

Example 4 with ServiceProvider

use of eu.esdihumboldt.hale.common.core.service.ServiceProvider in project hale by halestudio.

the class ConceptualSchemaTransformerTest method transformData.

@Override
protected List<Instance> transformData(TransformationExample example) throws Exception {
    ConceptualSchemaTransformer transformer = new ConceptualSchemaTransformer();
    ThreadSafeInstanceSink<DefaultInstanceSink> sink = new ThreadSafeInstanceSink<>(new DefaultInstanceSink());
    final Map<Class<?>, Object> customServices = new HashMap<>();
    customServices.put(FunctionService.class, new AlignmentFunctionService(example.getAlignment()));
    customServices.put(TransformationFunctionService.class, new AlignmentTransformationFunctionService(example.getAlignment()));
    InstanceIndexServiceImpl indexService = new InstanceIndexServiceImpl();
    customServices.put(InstanceIndexService.class, indexService);
    final ServiceProvider serviceProvider = new ServiceProvider() {

        private final ServiceProvider projectScope = new ServiceManager(ServiceManager.SCOPE_PROJECT);

        @SuppressWarnings("unchecked")
        @Override
        public <T> T getService(Class<T> serviceInterface) {
            if (customServices.containsKey(serviceInterface)) {
                return (T) customServices.get(serviceInterface);
            }
            // FIXME global scope not supported yet
            return projectScope.getService(serviceInterface);
        }
    };
    indexService.addPropertyMappings(example.getAlignment().getActiveTypeCells(), serviceProvider);
    InstanceCollection source = example.getSourceInstances();
    try (ResourceIterator<Instance> it = source.iterator()) {
        while (it.hasNext()) {
            indexService.add(it.next(), source);
        }
    }
    transformer.transform(example.getAlignment(), source, sink, serviceProvider, new NullProgressIndicator());
    return sink.getDecoratee().getInstances();
}
Also used : AlignmentTransformationFunctionService(eu.esdihumboldt.hale.common.align.service.impl.AlignmentTransformationFunctionService) HashMap(java.util.HashMap) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) DefaultInstanceSink(eu.esdihumboldt.hale.common.align.transformation.service.impl.DefaultInstanceSink) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) NullProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.NullProgressIndicator) AlignmentFunctionService(eu.esdihumboldt.hale.common.align.service.impl.AlignmentFunctionService) InstanceIndexServiceImpl(eu.esdihumboldt.hale.common.instance.index.InstanceIndexServiceImpl) ConceptualSchemaTransformer(eu.esdihumboldt.cst.ConceptualSchemaTransformer) ServiceManager(eu.esdihumboldt.hale.common.core.service.ServiceManager) ServiceProvider(eu.esdihumboldt.hale.common.core.service.ServiceProvider) ThreadSafeInstanceSink(eu.esdihumboldt.hale.common.align.transformation.service.impl.ThreadSafeInstanceSink)

Example 5 with ServiceProvider

use of eu.esdihumboldt.hale.common.core.service.ServiceProvider in project hale by halestudio.

the class FormattedStringExplanation method getExplanation.

@Override
protected String getExplanation(Cell cell, boolean html, ServiceProvider services, Locale locale) {
    Entity target = CellUtil.getFirstEntity(cell.getTarget());
    String pattern = CellUtil.getFirstParameter(cell, PARAMETER_PATTERN).as(String.class);
    List<? extends Entity> sources = null;
    if (cell.getSource() != null) {
        sources = cell.getSource().get(ENTITY_VARIABLE);
    }
    if (target != null && pattern != null) {
        if (html)
            pattern = "<pre>" + pattern + "</pre>";
        String explanation = MessageFormat.format(getMessage("main", locale), formatEntity(target, html, true, locale), pattern);
        if (html)
            explanation = explanation.replaceAll("\n", "<br />");
        if (sources != null && html) {
            Map<String, String> varToProperty = sources.stream().collect(Collectors.toMap(entity -> {
                return '{' + getEntityNameWithoutCondition(entity) + '}';
            }, entity -> {
                return formatEntity(entity, true, false, locale);
            }));
            explanation += buildReplacementTable(varToProperty, locale);
        }
        return explanation;
    }
    return null;
}
Also used : List(java.util.List) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Locale(java.util.Locale) Map(java.util.Map) ServiceProvider(eu.esdihumboldt.hale.common.core.service.ServiceProvider) Entity(eu.esdihumboldt.hale.common.align.model.Entity) FormattedStringFunction(eu.esdihumboldt.hale.common.align.model.functions.FormattedStringFunction) AbstractCellExplanation(eu.esdihumboldt.hale.common.align.model.impl.AbstractCellExplanation) Collectors(java.util.stream.Collectors) CellUtil(eu.esdihumboldt.hale.common.align.model.CellUtil) MessageFormat(java.text.MessageFormat) Entity(eu.esdihumboldt.hale.common.align.model.Entity)

Aggregations

ServiceProvider (eu.esdihumboldt.hale.common.core.service.ServiceProvider)8 Entity (eu.esdihumboldt.hale.common.align.model.Entity)5 List (java.util.List)5 Cell (eu.esdihumboldt.hale.common.align.model.Cell)4 CellUtil (eu.esdihumboldt.hale.common.align.model.CellUtil)4 AbstractCellExplanation (eu.esdihumboldt.hale.common.align.model.impl.AbstractCellExplanation)4 MessageFormat (java.text.MessageFormat)4 Locale (java.util.Locale)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 HashMap (java.util.HashMap)3 ConceptualSchemaTransformer (eu.esdihumboldt.cst.ConceptualSchemaTransformer)2 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)2 AlignmentFunctionService (eu.esdihumboldt.hale.common.align.service.impl.AlignmentFunctionService)2 AlignmentTransformationFunctionService (eu.esdihumboldt.hale.common.align.service.impl.AlignmentTransformationFunctionService)2 DefaultInstanceSink (eu.esdihumboldt.hale.common.align.transformation.service.impl.DefaultInstanceSink)2 NullProgressIndicator (eu.esdihumboldt.hale.common.core.io.impl.NullProgressIndicator)2 ServiceManager (eu.esdihumboldt.hale.common.core.service.ServiceManager)2 Function (com.google.common.base.Function)1 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1