use of eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationTree in project hale by halestudio.
the class TargetContext method duplicateTree.
/**
* Duplicates the transformation tree for the given target node to the given
* duplicate target node.
*
* @param target the original target node
* @param info the duplication info object
* @param log the transformation log
* @return a collection of newly created target nodes
*/
private static TargetNodeImpl duplicateTree(TargetNode target, DuplicationInformation info, TransformationLog log) {
GroupNode parent = null;
// Check if the parent node exists in the given context already.
if (target.getParent() instanceof TargetNode) {
Iterator<TargetNode> possibleParents = info.getAllTargetNodes(((TargetNode) target.getParent()).getEntityDefinition()).iterator();
while (possibleParents.hasNext()) {
TargetNode possibleParent = possibleParents.next();
if (info.getContextTargets().contains(target) || !possibleParent.getChildren(false).contains(target)) {
parent = possibleParent;
break;
}
}
} else if (target.getParent() instanceof TransformationTree && info.getContextTargets().contains(target)) {
// Reached root, but this is a possible target.
parent = target.getParent();
} else {
// Reached root, but this is no possible target or the parent is
// null!
// XXX instead log and return null or not connected TargetNode? See
// T O D O below
log.warn(log.createMessage("DuplicationContext present, but no matching target found.", null));
return null;
// throw new IllegalStateException(
// "DuplicationContext present, but no matching target found.");
}
if (parent == null) {
// Does not exist: recursion.
TargetNodeImpl duplicatedTarget = duplicateTree((TargetNode) target.getParent(), info, log);
if (duplicatedTarget == null) {
return null;
}
TargetNodeImpl newTarget = new TargetNodeImpl(target.getEntityDefinition(), duplicatedTarget);
info.addNewTargetNode(newTarget.getEntityDefinition(), newTarget);
duplicatedTarget.addChild(newTarget);
return newTarget;
} else {
// Exists: add as child.
TargetNodeImpl newTarget = new TargetNodeImpl(target.getEntityDefinition(), parent);
info.addNewTargetNode(newTarget.getEntityDefinition(), newTarget);
// as annotated child.
if (parent instanceof TargetNodeImpl && !parent.getChildren(false).contains(newTarget))
((TargetNodeImpl) parent).addChild(newTarget);
else
parent.addAnnotatedChild(newTarget);
return newTarget;
}
}
use of eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationTree 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;
}
use of eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationTree in project hale by halestudio.
the class TreeGraphMLProvider method setVertexProperty.
/**
* sets the property of a [@link]Vertex from a [@link]TransformationNode
*
* @param node the node-object to get the name from
* @param vertex the vertex to set the property
*/
private void setVertexProperty(TransformationNode node, Vertex vertex) {
if (node instanceof TransformationTree) {
vertex.setProperty("name", ((TransformationTree) node).getType().getDisplayName());
vertex.setProperty("type", "root");
}
if (node instanceof TargetNode) {
vertex.setProperty("name", ((TargetNode) node).getDefinition().getDisplayName());
vertex.setProperty("type", "target");
}
if (node instanceof SourceNode) {
SourceNode snode = (SourceNode) node;
Object value = snode.getValue();
String name = ((SourceNode) node).getDefinition().getDisplayName();
if (value instanceof Group) {
vertex.setProperty("name", name);
vertex.setProperty("group", getChildrencountString(value));
vertex.setProperty("type", "source");
}
if (value instanceof Instance) {
if (((Instance) value).getValue() != null) {
vertex.setProperty("group", getChildrencountString(value));
vertex.setProperty("value", ((Instance) value).getValue().toString());
vertex.setProperty("type", "source");
}
} else {
vertex.setProperty("name", name);
vertex.setProperty("type", "source");
if (value instanceof String) {
vertex.setProperty("value", value);
}
}
}
if (node instanceof CellNode) {
vertex.setProperty("name", FunctionUtil.getFunction(((CellNode) node).getCell().getTransformationIdentifier(), null).getDisplayName());
vertex.setProperty("type", "cell");
}
}
Aggregations