Search in sources :

Example 1 with FunctionService

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

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

the class FunctionUtil method getFunction.

/**
 * Get the function w/ the given identifier. Falls back to static function
 * declarations if no service is available.
 *
 * @param id the function ID
 * @param serviceProvider the service provider to retrieve the function
 *            service for resolving the function identifier
 * @return the function or <code>null</code> if no function with the given
 *         identifier was found
 */
public static FunctionDefinition<?> getFunction(String id, @Nullable ServiceProvider serviceProvider) {
    if (serviceProvider != null) {
        FunctionService fs = serviceProvider.getService(FunctionService.class);
        if (fs != null) {
            return fs.getFunction(id);
        }
    }
    AbstractFunction<?> result = null;
    result = TypeFunctionExtension.getInstance().get(id);
    if (result == null) {
        result = PropertyFunctionExtension.getInstance().get(id);
    }
    return result;
}
Also used : FunctionService(eu.esdihumboldt.hale.common.align.service.FunctionService)

Example 3 with FunctionService

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

the class CellUtil method getCellDescription.

/**
 * Get a short description of a cell.
 *
 * @param cell the cell
 * @param serviceProvider the service provider for retrieving the function
 *            service, may be <code>null</code>
 * @return the cell description
 */
public static String getCellDescription(Cell cell, @Nullable ServiceProvider serviceProvider) {
    StringBuffer result = new StringBuffer();
    // include function name if possible
    String functionId = cell.getTransformationIdentifier();
    eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition<?> function = null;
    if (serviceProvider != null) {
        FunctionService fs = serviceProvider.getService(FunctionService.class);
        if (fs != null) {
            function = fs.getFunction(functionId);
        }
    }
    if (function != null) {
        result.append(function.getDisplayName());
        result.append(": ");
    }
    if (cell.getSource() != null) {
        result.append(entitiesText(cell.getSource().values()));
        result.append(" to ");
    }
    result.append(entitiesText(cell.getTarget().values()));
    return result.toString();
}
Also used : FunctionService(eu.esdihumboldt.hale.common.align.service.FunctionService)

Aggregations

FunctionService (eu.esdihumboldt.hale.common.align.service.FunctionService)3 TransformationTree (eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationTree)1 TransformationTreeImpl (eu.esdihumboldt.hale.common.align.model.transformation.tree.impl.TransformationTreeImpl)1 AlignmentFunctionService (eu.esdihumboldt.hale.common.align.service.impl.AlignmentFunctionService)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 AbstractTransformationTraverser (eu.esdihumboldt.hale.io.xslt.transformations.base.AbstractTransformationTraverser)1 StringWriter (java.io.StringWriter)1