use of eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode in project hale by halestudio.
the class TransformationTreeContentProvider method getChilddren.
/**
* Get the children of a node
*
* @param node the node
* @return the node's children
*/
private Collection<? extends Object> getChilddren(Object node) {
if (node instanceof IdentityWrapper<?>) {
node = ((IdentityWrapper<?>) node).getValue();
}
if (node instanceof TransformationTree) {
return wrapNodes(((TransformationTree) node).getChildren(true));
}
if (node instanceof TargetNode) {
List<Object> children = new ArrayList<Object>();
children.addAll(((TargetNode) node).getChildren(true));
children.addAll(((TargetNode) node).getAssignments());
return wrapNodes(children);
}
if (node instanceof CellNode) {
return wrapNodes(((CellNode) node).getSources());
}
if (node instanceof SourceNode) {
SourceNode parent = ((SourceNode) node).getParent();
if (parent != null) {
return Collections.singleton(new IdentityWrapper<Object>(parent));
}
}
return Collections.emptyList();
}
use of eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode in project hale by halestudio.
the class TransformationTreeLabelProvider method getFigure.
/**
* @see GraphLabelProvider#getFigure(Object)
*/
@Override
public IFigure getFigure(Object element) {
if (element instanceof IdentityWrapper<?>) {
element = ((IdentityWrapper<?>) element).getValue();
}
ShapePainter shape = null;
String contextText = null;
String cardText = null;
if (element instanceof TransformationTree) {
shape = new TransformationNodeShape(10, SWT.NONE);
} else if (element instanceof TargetNode) {
TargetNode node = (TargetNode) element;
contextText = AlignmentUtil.getContextText(node.getEntityDefinition());
if (!hasTransformationAnnotations(element)) {
cardText = getCardinalityText(node.getEntityDefinition().getDefinition());
}
if (node.getAssignments().isEmpty()) {
shape = new TransformationNodeShape(10, SWT.NONE);
} else {
// shape = new TransformationNodeShape(10, SWT.LEFT);
shape = new FingerPost(10, SWT.LEFT);
}
} else if (element instanceof SourceNode) {
SourceNode node = (SourceNode) element;
contextText = AlignmentUtil.getContextText(node.getEntityDefinition());
if (!hasTransformationAnnotations(element)) {
cardText = getCardinalityText(node.getEntityDefinition().getDefinition());
}
if (node.getParent() == null) {
shape = new TransformationNodeShape(10, SWT.NONE);
} else {
shape = new FingerPost(10, SWT.RIGHT);
}
}
if (shape != null) {
CustomShapeFigure figure;
if (contextText != null || cardText != null) {
figure = new EntityFigure(shape, contextText, cardText, getCustomFigureFont());
} else {
figure = new CustomShapeLabel(shape, getCustomFigureFont());
}
figure.setMaximumWidth(MAX_FIGURE_WIDTH);
return figure;
}
element = TransformationTreeUtil.extractObject(element);
return super.getFigure(element);
}
use of eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode in project hale by halestudio.
the class TargetContext method duplicateTree.
/**
* Duplicates the transformation tree for the given source node to the given
* duplicate source node.
*
* @param source the original source node
* @param duplicate the duplication target
* @param info the duplication info object
* @param log the transformation log
* @param serviceProvider service provider for resolving functions
*/
private static void duplicateTree(SourceNode source, SourceNode duplicate, DuplicationInformation info, TransformationLog log, ServiceProvider serviceProvider) {
// Duplicate relations.
for (CellNode cell : source.getRelations(false)) {
// check whether the cell is eager for the source node
if (TransformationTreeUtil.isEager(cell, source, log, serviceProvider))
continue;
// Check whether the cell is ignored.
if (info.isIgnoreCell(cell.getCell()))
continue;
// XXX prioritize already created cell nodes (in this run) over old
// nodes?
// First check whether an old cell node with a missing source
// exists.
// If so, add this source to the first so found cell.
boolean usedOld = false;
for (IdentityWrapper<CellNode> wrapper : info.getOldCellNodes(cell.getCell())) {
CellNode oldCellNode = wrapper.getValue();
// Skip the cell if it's full.
if (oldCellNode.getSources().size() == cell.getSources().size())
continue;
// Check whether out duplicate source node is missing...
if (!oldCellNode.getSources().contains(duplicate)) {
usedOld = true;
// Has to be a cell created with the cell constructor.
((CellNodeImpl) oldCellNode).addSource(cell.getSourceNames(source), duplicate);
duplicate.addRelation(oldCellNode);
break;
}
}
// If no old cell was used, use a newly created one / create one.
if (!usedOld) {
CellNodeImpl duplicatedCell = info.getNewCellNode(cell.getCell());
if (duplicatedCell == null) {
// Create a new cell, augment it with existing sources, add
// it to info and duplicate targets.
duplicatedCell = new CellNodeImpl(cell.getCell());
augmentCell(cell, duplicatedCell, info);
info.addNewCellNode(cell.getCell(), duplicatedCell);
duplicateTree(cell, duplicatedCell, info, log);
}
// Add as relation/source.
duplicate.addRelation(duplicatedCell);
duplicatedCell.addSource(cell.getSourceNames(source), duplicate);
}
}
// Duplicate children.
for (SourceNode child : source.getChildren(false)) {
SourceNode duplicatedChild = new SourceNodeImpl(child.getEntityDefinition(), duplicate, true);
duplicatedChild.setContext(child.getContext());
duplicateTree(child, duplicatedChild, info, log, serviceProvider);
}
}
use of eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode in project hale by halestudio.
the class TargetContext method duplicateSource.
// /**
// * Checks whether the given source node is part of the context for the duplication.
// *
// * @param source the source node to check
// * @param info the context information
// * @return true, if the given node is in the context for the duplication, false otherwise
// */
// private boolean isInContext(SourceNode source, DuplicationInformation info) {
// Collection<SourceNode> contextNodes = info.getOldSourceNodes(source.getEntityDefinition());
// for (SourceNode node : contextNodes)
// if (node == source)
// return true;
// return false;
// }
// OLD STUFF!
// /**
// * Track back target nodes and duplicate any augmentation cells.
// * @param originalTarget the original target node
// * @param duplicationContext the duplication context
// */
// private void augmentationTrackback(TargetNode originalTarget,
// DuplicationContext duplicationContext) {
// // track back child augmentations
// for (TargetNode child : originalTarget.getChildren(false)) { //XXX should annotated children be included?
// augmentationTrackback(child, duplicationContext);
// }
//
// // track back augmentations
// for (CellNode originalAssignment : originalTarget.getAssignments()) {
// /*
// * Duplicated target does not contain an assignment representing
// * the same cell as originalAssignment.
// */
// if (originalAssignment.getSources().isEmpty()) {
// // the cell is an augmentation, thus we duplicate it
// duplicateCell(originalAssignment, null, duplicationContext);
// /*
// * it is automatically added to the target nodes (which are
// * retrieved from the duplication context or created as
// * necessary)
// */
// }
// }
// }
//
// /**
// * Track the graph back to sources that are missing in a cell node compared
// * to the original cell node.
// * @param cellNode the cell node
// * @param originalCell the original cell node the node was duplicated from
// */
// private void cellTrackback(CellNodeImpl cellNode, CellNode originalCell) {
// for (SourceNode originalSource : originalCell.getSources()) {
// if (!cellNode.getSources().contains(originalSource)) {
// /*
// * Duplicated cell does not contain a source representing the
// * same entity as originalSource.
// */
// SourceNode newSource = null;
//
// // now there are several possible cases
// // a) the original source has leftovers and we grab one
// Leftovers leftovers = originalSource.getLeftovers();
// if (leftovers != null) {
// newSource = leftovers.consumeValue(originalCell.getCell());
//
// if (newSource != null) {
// // interconnect both
// newSource.addRelation(cellNode);
// cellNode.addSource(originalCell.getSourceNames(originalSource),
// newSource);
// //XXX hard connections are OK here, as a leftover source is a duplicate
// }
// else {
// //TODO add an undefined source node in this case?
// }
// }
//
// // b) the original source has a parent (ot it has a parent etc.)
// // that has leftovers
// if (newSource == null) {
// //TODO
// }
//
// // c) we use the original source node
// if (newSource == null) {
// newSource = originalSource;
//
// // interconnect both
// newSource.addAnnotatedRelation(cellNode); //FIXME should be an augmentated relation!!!!
// cellNode.addSource(originalCell.getSourceNames(originalSource),
// newSource);
// }
// }
// }
// }
/**
* Duplicate a source node.
*
* @param source the source node to duplicate
* @param parent the parent of the new source node
* @param addToParent if the new source node should be added as child to the
* parent
* @param duplicationContext the duplication context
* @return the new duplicated source node or <code>null</code> if
* duplication was prohibited
*/
private SourceNode duplicateSource(SourceNode source, SourceNode parent, boolean addToParent, DuplicationContext duplicationContext) {
// create duplicate
SourceNode duplicate = new SourceNodeImpl(source.getEntityDefinition(), parent, addToParent);
duplicate.setContext(source.getContext());
return configureSourceDuplicate(source, duplicate, parent, duplicationContext, addToParent);
}
use of eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode in project hale by halestudio.
the class DuplicationVisitor method visit.
/**
* @see AbstractTransformationNodeVisitor#visit(SourceNode)
*/
@Override
public boolean visit(SourceNode source) {
Leftovers leftovers = source.getLeftovers();
if (leftovers != null) {
// identify context match (if possible)
TransformationContext context = source.getContext();
if (context == null) {
// no transformation context match defined
log.warn(log.createMessage("Multiple values for source node w/o transformation context match", null));
} else {
Pair<SourceNode, Set<Cell>> leftover;
// completely consume leftovers
while ((leftover = leftovers.consumeValue()) != null) {
context.duplicateContext(source, leftover.getFirst(), leftover.getSecond(), log);
// XXX is this the place where this should be propagated to
// the duplicated source children?
// XXX trying it out
SourceNode node = leftover.getFirst();
Object value = node.getValue();
if (value instanceof Group) {
InstanceVisitor instanceVisitor = new InstanceVisitor(null, null, log);
for (SourceNode child : node.getChildren(instanceVisitor.includeAnnotatedNodes())) {
// annotate children with leftovers
child.accept(instanceVisitor);
// run the duplication on the children
child.accept(this);
}
}
}
}
}
return true;
}
Aggregations