Search in sources :

Example 1 with AlignmentFunctionService

use of eu.esdihumboldt.hale.common.align.service.impl.AlignmentFunctionService 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 AlignmentFunctionService

use of eu.esdihumboldt.hale.common.align.service.impl.AlignmentFunctionService 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 AlignmentFunctionService

use of eu.esdihumboldt.hale.common.align.service.impl.AlignmentFunctionService 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)

Aggregations

AlignmentFunctionService (eu.esdihumboldt.hale.common.align.service.impl.AlignmentFunctionService)3 ConceptualSchemaTransformer (eu.esdihumboldt.cst.ConceptualSchemaTransformer)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 ServiceProvider (eu.esdihumboldt.hale.common.core.service.ServiceProvider)2 HashMap (java.util.HashMap)2 TransformationTree (eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationTree)1 TransformationTreeImpl (eu.esdihumboldt.hale.common.align.model.transformation.tree.impl.TransformationTreeImpl)1 FunctionService (eu.esdihumboldt.hale.common.align.service.FunctionService)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 ThreadSafeInstanceSink (eu.esdihumboldt.hale.common.align.transformation.service.impl.ThreadSafeInstanceSink)1 InstanceIndexServiceImpl (eu.esdihumboldt.hale.common.instance.index.InstanceIndexServiceImpl)1 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)1 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)1 AbstractTransformationTraverser (eu.esdihumboldt.hale.io.xslt.transformations.base.AbstractTransformationTraverser)1 StringWriter (java.io.StringWriter)1