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);
}
}
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;
}
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();
}
Aggregations