Search in sources :

Example 31 with Entity

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));
            }
        }
    }
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Entity(eu.esdihumboldt.hale.common.align.model.Entity) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) ListMultimap(com.google.common.collect.ListMultimap)

Example 32 with Entity

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);
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Test(org.junit.Test)

Example 33 with Entity

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);
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Test(org.junit.Test)

Example 34 with Entity

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());
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Test(org.junit.Test)

Example 35 with Entity

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();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Entity(eu.esdihumboldt.hale.common.align.model.Entity) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Aggregations

Entity (eu.esdihumboldt.hale.common.align.model.Entity)64 Cell (eu.esdihumboldt.hale.common.align.model.Cell)25 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)21 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)14 ArrayList (java.util.ArrayList)12 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)9 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)9 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)9 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)9 List (java.util.List)9 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)8 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)7 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)6 HashSet (java.util.HashSet)6 Locale (java.util.Locale)6 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)5 FunctionDefinition (eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition)4 CellUtil (eu.esdihumboldt.hale.common.align.model.CellUtil)4 CellLog (eu.esdihumboldt.hale.common.align.model.annotations.messages.CellLog)4 AbstractCellExplanation (eu.esdihumboldt.hale.common.align.model.impl.AbstractCellExplanation)4