use of eu.esdihumboldt.hale.common.align.model.transformation.tree.impl.TransformationTreeImpl 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.model.transformation.tree.impl.TransformationTreeImpl in project hale by halestudio.
the class TransformationTreeContentProvider method getElements.
/**
* @see ArrayContentProvider#getElements(Object)
*/
@SuppressWarnings("unchecked")
@Override
public Object[] getElements(Object inputElement) {
if (inputElement instanceof TransformationTree)
return collectNodes((TransformationTree) inputElement).toArray();
Collection<Instance> instances = null;
if (inputElement instanceof Pair<?, ?>) {
Pair<?, ?> pair = (Pair<?, ?>) inputElement;
inputElement = pair.getFirst();
if (pair.getSecond() instanceof Collection<?>) {
instances = (Collection<Instance>) pair.getSecond();
}
}
if (inputElement instanceof Alignment) {
Alignment alignment = (Alignment) inputElement;
// input contained specific instances
if (instances != null && !instances.isEmpty()) {
Collection<Object> result = new ArrayList<Object>();
// create transformation trees for each instance
for (Instance instance : instances) {
// find type cells matching the instance
Collection<? extends Cell> typeCells = alignment.getActiveTypeCells();
Collection<Cell> associatedTypeCells = new LinkedList<Cell>();
for (Cell typeCell : typeCells) for (Entity entity : typeCell.getSource().values()) {
TypeEntityDefinition type = (TypeEntityDefinition) entity.getDefinition();
if (type.getDefinition().equals(instance.getDefinition()) && (type.getFilter() == null || type.getFilter().match(instance))) {
associatedTypeCells.add(typeCell);
break;
}
}
// for each type cell one tree
for (Cell cell : associatedTypeCells) {
TransformationTree tree = createInstanceTree(instance, cell, alignment);
if (tree != null)
result.addAll(collectNodes(tree));
}
}
return result.toArray();
}
// input was alignment only, show trees for all type cells
Collection<? extends Cell> typeCells = alignment.getActiveTypeCells();
Collection<Object> result = new ArrayList<Object>(typeCells.size());
for (Cell typeCell : typeCells) {
// create tree and add nodes for each cell
result.addAll(collectNodes(new TransformationTreeImpl(alignment, typeCell)));
}
return result.toArray();
}
return super.getElements(inputElement);
}
use of eu.esdihumboldt.hale.common.align.model.transformation.tree.impl.TransformationTreeImpl in project hale by halestudio.
the class TransformationTreeContentProvider method createInstanceTree.
/**
* Create a transformation tree based on a source instance.
*
* @param instance the source instance
* @param typeCell the type cell
* @param alignment the alignment
* @return the transformation tree or <code>null</code>
*/
private TransformationTree createInstanceTree(Instance instance, Cell typeCell, Alignment alignment) {
TransformationTree tree = new TransformationTreeImpl(alignment, typeCell);
ReportLog<TransformationMessage> reporter = new DefaultTransformationReporter("Transformation tree", true);
TransformationLog log = new CellLog(reporter, typeCell);
// context matching
// XXX instead through service/extension point?
ContextMatcher matcher = new AsDeepAsPossible(null);
matcher.findMatches(tree);
// process and annotate the tree
InstanceVisitor visitor = new InstanceVisitor(new FamilyInstanceImpl(instance), tree, log);
tree.accept(visitor);
// duplicate subtree as necessary
DuplicationVisitor duplicationVisitor = new DuplicationVisitor(tree, log);
tree.accept(duplicationVisitor);
duplicationVisitor.doAugmentationTrackback();
return tree;
}
Aggregations