use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.
the class AbstractMergeCellMigrator method applySourceContexts.
/**
* Apply contexts/conditions from the original source to the source of the
* new mapping cell that replaces it.
*
* @param newCell the cell to adapt
* @param originalSource the original source
* @param log the cell log
*/
private void applySourceContexts(MutableCell newCell, Entity originalSource, SimpleLog log) {
if (originalSource != null) {
EntityDefinition original = originalSource.getDefinition();
boolean isDefault = AlignmentUtil.isDefaultEntity(original);
if (!isDefault) {
ListMultimap<String, ? extends Entity> newSource = newCell.getSource();
if (newSource == null || newSource.size() == 0) {
// new cell does not have a source -> drop contexts
log.warn("Any conditions/contexts on the original source have been dropped because the new mapping does not have a source: " + MergeUtil.getContextInfoString(original));
} else if (newSource.size() == 1) {
// try to transfer contexts
Entity singleSource = CellUtil.getFirstEntity(newSource);
if (singleSource != null) {
EntityDefinition transferedSource = AbstractMigration.translateContexts(original, singleSource.getDefinition(), log);
ListMultimap<String, Entity> s = ArrayListMultimap.create();
s.put(newSource.keySet().iterator().next(), AlignmentUtil.createEntity(transferedSource));
newCell.setSource(s);
}
} else {
// no idea where to add contexts -> report
log.warn("Any conditions/contexts on the original source have been dropped because the new mapping has multiple sources and it is not clear where they should be attached: " + MergeUtil.getContextInfoString(original));
}
}
}
}
use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.
the class OMLReaderTest method testMathematicalExpression.
/**
* Test for mathematical expression in alignment
*/
@Test
public void testMathematicalExpression() {
Collection<? extends Cell> cells = alignment.getCells();
Iterator<? extends Cell> it = cells.iterator();
Cell cell = null;
while (it.hasNext()) {
Cell temp = it.next();
if (temp.getTransformationIdentifier().equals("eu.esdihumboldt.cst.functions.numeric.mathexpression")) {
cell = temp;
break;
}
}
ListMultimap<String, ParameterValue> params = cell.getTransformationParameters();
List<ParameterValue> values = params.get("expression");
// test the amount and the correctness of the parameter
assertEquals(1, values.size());
String date = values.get(0).as(String.class);
assertEquals("income * age/10", date);
// test the amount and the correctness of source properties
ListMultimap<String, ? extends Entity> src = cell.getSource();
// all source properties should be named "var" so we test if both lists
// have the same size
List<? extends Entity> srcCells = src.get("var");
assertEquals(2, src.size());
assertEquals(2, srcCells.size());
// since we have now the right amount of source properties we can now
// test the correctness of their names
Entity srcCell1 = srcCells.get(0);
Entity srcCell2 = srcCells.get(1);
String name1 = srcCell1.getDefinition().getDefinition().getDisplayName();
String name2 = srcCell2.getDefinition().getDefinition().getDisplayName();
assertEquals("age", name1);
assertEquals("income", name2);
}
use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.
the class OMLReaderTest method testCentroid1.
/**
* Test for centroid function in alignment3
*/
@Test
public void testCentroid1() {
Collection<? extends Cell> cells = alignment5.getCells();
Iterator<? extends Cell> it = cells.iterator();
Cell cell = null;
while (it.hasNext()) {
Cell temp = it.next();
if (temp.getTransformationIdentifier().equals("eu.esdihumboldt.cst.functions.geometric.centroid")) {
cell = temp;
break;
}
}
// test if there is only one source and one target
assertEquals(1, cell.getSource().size());
assertEquals(1, cell.getTarget().size());
List<? extends Entity> list = cell.getTarget().get(null);
assertEquals(1, list.size());
Entity ent = list.get(0);
String name = ent.getDefinition().getDefinition().getDisplayName();
assertEquals("referencePoint", name);
}
use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.
the class OMLReaderTest method testOrdinatesToPoint1.
/**
* Test for ordinates to point function in alignment5
*/
@Test
public void testOrdinatesToPoint1() {
Collection<? extends Cell> cells = alignment5.getCells();
Iterator<? extends Cell> it = cells.iterator();
Cell cell = null;
while (it.hasNext()) {
Cell temp = it.next();
if (temp.getTransformationIdentifier().equals("eu.esdihumboldt.cst.functions.geometric.ordinates_to_point")) {
cell = temp;
break;
}
}
ListMultimap<String, ? extends Entity> src = cell.getSource();
// the parameters were moved to the source entities with the appropriate
// names so get the source entities with name "X"/"Y"
Entity srcX = src.get("X").get(0);
Entity srcY = src.get("Y").get(0);
// check if the source entity has the correct value
assertEquals("HOCHWERT", srcX.getDefinition().getDefinition().getDisplayName());
assertEquals("RECHTSWERT", srcY.getDefinition().getDefinition().getDisplayName());
}
use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.
the class CellRelationshipContentProvider method getNodes.
/**
* Get all nodes for the given cells.
*
* @param cells an iterable of {@link Cell}s, other objects will be ignored
* @return the array of edges
*/
protected Object[] getNodes(Iterable<?> cells) {
Set<Object> nodes = new LinkedHashSet<Object>();
for (Object object : cells) {
if (object instanceof Cell) {
Cell cell = (Cell) object;
// add source entities
for (Entity entity : cell.getSource().values()) {
nodes.add(entity);
}
// add cell
nodes.add(cell);
// add target entities
for (Entity entity : cell.getTarget().values()) {
nodes.add(entity);
}
}
}
return nodes.toArray();
}
Aggregations