use of eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode in project hale by halestudio.
the class TargetContext method configureSourceDuplicate.
/**
* Configure a duplicated source node.
*
* @param originalSource the original source node
* @param duplicate the duplicated source node
* @param parent the parent for the duplicated source node
* @param duplicationContext the duplication context
* @param addToParent if the duplicated source node should be added as child
* to its parent
* @return the duplicated source node or <code>null</code> if it has no
* further connections
*/
private SourceNode configureSourceDuplicate(SourceNode originalSource, SourceNode duplicate, SourceNode parent, DuplicationContext duplicationContext, boolean addToParent) {
// duplicate relations
List<CellNode> relations = new ArrayList<CellNode>(originalSource.getRelations(false).size());
// though each cell node is only duplicated once per duplication context
for (CellNode relation : originalSource.getRelations(false)) {
// XXX
// should
// the
// annotated
// relations
// be
// included?
CellNode duplicatedRelation = duplicateCell(relation, duplicate, duplicationContext);
if (duplicatedRelation != null) {
relations.add(duplicatedRelation);
}
}
// duplicate children
List<SourceNode> children = new ArrayList<SourceNode>(originalSource.getChildren(false).size());
for (SourceNode child : originalSource.getChildren(false)) {
// XXX
// should
// the
// annotated
// children
// be
// included?
SourceNode duplicatedChild = duplicateSource(child, duplicate, true, duplicationContext);
if (duplicatedChild != null) {
children.add(duplicatedChild);
}
}
if (children.isEmpty() && relations.isEmpty()) {
// abort
return null;
}
// add duplicated relations
for (CellNode relation : relations) {
duplicate.addRelation(relation);
}
// add duplicated children
for (SourceNode child : children) {
duplicate.addChild(child);
}
if (addToParent) {
parent.addChild(duplicate);
}
return duplicate;
}
use of eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode in project hale by halestudio.
the class TargetContext method duplicateContext.
// /**
// * @see TransformationContext#duplicateContext(SourceNode, Object)
// */
// @Override
// public void duplicateContext(SourceNode contextSource, Object value) {
// // create a new duplication context
// DuplicationContext duplicationContext = new DuplicationContext();
//
// // duplicate context source
// SourceNode source = duplicateSource(contextSource,
// contextSource.getParent(), false, duplicationContext);
//
// if (source != null) {
// // add duplicated source as annotation to context source parent
// contextSource.getParent().addAnnotatedChild(source);
//
// // apply value to source
// if (value instanceof Group) {
// // value is a group, duplication may again be necessary for its properties
// InstanceVisitor visitor = new InstanceVisitor((Group) value);
// source.accept(visitor);
// }
// else {
// // value is a simple value
// source.setValue(value);
// }
// }
// }
/**
* @see TransformationContext#duplicateContext(SourceNode, SourceNode, Set,
* TransformationLog)
*/
@Override
public void duplicateContext(SourceNode originalSource, final SourceNode duplicate, Set<Cell> ignoreCells, TransformationLog log) {
DuplicationInformation info = new DuplicationInformation(duplicate, ignoreCells, contextTargets);
SourceNode parent = duplicate.getParent();
if (parent == null)
parent = duplicate.getAnnotatedParent();
if (parent != null) {
// Find existing cell/target nodes over children of the parent node.
Map<EntityDefinition, SourceNode> contextPath = new HashMap<EntityDefinition, SourceNode>();
SourceNode pathNode = duplicate;
SourceNode root;
do {
contextPath.put(pathNode.getEntityDefinition(), pathNode);
root = pathNode;
if (pathNode.getParent() != null)
pathNode = pathNode.getParent();
else
pathNode = pathNode.getAnnotatedParent();
} while (pathNode != null);
collectExistingNodes(root, contextPath, info, false);
// add target nodes reachable through original source node
// XXX not all target nodes are needed, collection of some of them
// could even lead to wrong results
collectExistingNodes(originalSource, Collections.<EntityDefinition, SourceNode>emptyMap(), info, true);
duplicateTree(originalSource, duplicate, info, log, serviceProvider);
} else
throw new IllegalStateException("Duplicate node neither got a parent, nor an annotated parent.");
// Code matching the old stuff at bottom!
// // create a new duplication context
// DuplicationContext duplicationContext = new DuplicationContext(ignoreCells);
//
// // configure duplicate, but don't add to parent (as it is already added as annotated child)
// // at this point duplicate may have a parent, even if the original source hasn't
// configureSourceDuplicate(originalSource, duplicate,
// duplicate.getParent(), duplicationContext, false);
//
// // track back to sources from cells where sources are missing
// for (Pair<CellNodeImpl, CellNode> cellPair : duplicationContext.getIncompleteCellNodes()) {
// CellNodeImpl cellNode = cellPair.getFirst();
// CellNode originalCell = cellPair.getSecond();
//
// cellTrackback(cellNode, originalCell);
// }
//
// // track back from targets where augmentations are missing
// for (Pair<TargetNodeImpl, TargetNode> targetPair : duplicationContext.getIncompleteTargetNodes()) {
// // TargetNodeImpl targetNode = targetPair.getFirst();
// TargetNode originalTarget = targetPair.getSecond();
//
// augmentationTrackback(originalTarget, duplicationContext);
// }
}
use of eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode in project hale by halestudio.
the class LeftoversImpl method addLeftover.
/**
* Adds the given value to the leftovers.
*
* @param value the leftover value
* @param annotatedParent the value for the annotated parent field of the
* duplicate nodes
*/
public void addLeftover(Object value, SourceNode annotatedParent) {
SourceNode duplicate = new SourceNodeImpl(originalSource.getEntityDefinition(), originalSource.getParent(), false);
duplicate.setAnnotatedParent(annotatedParent);
// assign context
duplicate.setContext(originalSource.getContext());
// add as annotated child to original parent
if (originalSource.getParent() != null)
originalSource.getParent().addAnnotatedChild(duplicate);
// set the value
duplicate.setValue(value);
// XXX where should eventual children be created?
// store the leftover
values.add(new Pair<SourceNode, Set<Cell>>(duplicate, new HashSet<Cell>()));
}
use of eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode in project hale by halestudio.
the class SourceNodeFactory method getSourceNode.
/**
* Get or create source node for the given entity definition. Source nodes
* created from this factory are ensured to exist only once for the same
* entity definition.
*
* @param entityDefinition the entity definition the source node is
* associated to
* @return the source node
*/
public SourceNode getSourceNode(EntityDefinition entityDefinition) {
SourceNode node = nodes.get(entityDefinition);
if (node == null) {
node = new SourceNodeImpl(entityDefinition, this);
nodes.put(entityDefinition, node);
}
return node;
}
use of eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode in project hale by halestudio.
the class CellNodeValidator method visit.
/**
* @see AbstractTargetToSourceVisitor#visit(CellNode)
*/
@Override
public boolean visit(CellNode node) {
// evaluate if for the cell all needed inputs are set
Cell cell = node.getCell();
// collect source and target nodes per entity name
ListMultimap<String, Pair<SourceNode, Entity>> sources = ArrayListMultimap.create();
if (cell.getSource() != null) {
for (Entry<String, ? extends Entity> sourceEntry : cell.getSource().entries()) {
String name = sourceEntry.getKey();
Entity entity = sourceEntry.getValue();
SourceNode sourceNode = findSourceNode(node, entity);
if (sourceNode != null) {
if (sourceNode.isDefined()) {
sources.put(name, new Pair<SourceNode, Entity>(sourceNode, entity));
}
} else {
log.error("Source node for entity not found.");
}
}
}
ListMultimap<String, Pair<TargetNode, Entity>> targets = ArrayListMultimap.create();
for (Entry<String, ? extends Entity> targetEntry : cell.getTarget().entries()) {
String name = targetEntry.getKey();
Entity entity = targetEntry.getValue();
TargetNode targetNode = findTargetNode(node, entity);
if (targetNode != null) {
targets.put(name, new Pair<TargetNode, Entity>(targetNode, entity));
} else {
log.error("Target node for entity not found.");
}
}
boolean valid = validate(node, sources, targets);
if (valid) {
processValid(cell, sources, targets);
}
node.setValid(valid);
// don't visit source nodes
return false;
}
Aggregations