コード例 #1
0
ファイル: DefaultAlignment.java プロジェクト: halestudio/hale
  /** @see Alignment#getTypeCells(Cell) */
  @Override
  public Collection<? extends Cell> getTypeCells(Cell queryCell) {
    Set<TypeEntityDefinition> sources = new HashSet<TypeEntityDefinition>();
    if (queryCell.getSource() != null) {
      Iterator<? extends Entity> it = queryCell.getSource().values().iterator();
      while (it.hasNext()) sources.add(AlignmentUtil.getTypeEntity(it.next().getDefinition()));
    }

    Entity targetEntity = CellUtil.getFirstEntity(queryCell.getTarget());
    TypeDefinition target = targetEntity == null ? null : targetEntity.getDefinition().getType();

    if (sources.isEmpty() && target == null) return getTypeCells();

    List<Cell> result = new ArrayList<Cell>();

    for (Cell typeCell : typeCells) {
      TypeDefinition typeCellTarget =
          CellUtil.getFirstEntity(typeCell.getTarget()).getDefinition().getType();
      if (target == null || DefinitionUtil.isSuperType(target, typeCellTarget)) {
        // target matches
        if (sources.isEmpty() || matchesSources(typeCell.getSource(), sources)) {
          // source matches, too
          result.add(typeCell);
        }
      }
    }

    return result;
  }
コード例 #2
0
ファイル: OMLReaderTest.java プロジェクト: nunotoriz/hale
  /** 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);
  }
コード例 #3
0
ファイル: OMLReaderTest.java プロジェクト: nunotoriz/hale
  /** 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());
  }
コード例 #4
0
ファイル: DefaultAlignment.java プロジェクト: halestudio/hale
  /** @see Alignment#getPropertyCells(Cell, boolean, boolean) */
  @Override
  public Collection<? extends Cell> getPropertyCells(
      Cell typeCell, boolean includeDisabled, boolean ignoreEmptySource) {
    if (CellUtil.getFirstEntity(typeCell.getTarget()) == null) {
      if (CellUtil.getFirstEntity(typeCell.getSource()) == null) return Collections.emptySet();
      else if (!(typeCell.getSource().values().iterator().next() instanceof Type))
        throw new IllegalArgumentException("Given cell is not a type cell.");

      // query with sources only
      Collection<TypeEntityDefinition> sourceTypes = new ArrayList<TypeEntityDefinition>();
      Iterator<? extends Entity> it = typeCell.getSource().values().iterator();
      while (it.hasNext()) sourceTypes.add((TypeEntityDefinition) it.next().getDefinition());

      List<Cell> result = new ArrayList<Cell>();
      for (Cell cell : cells)
        if (!AlignmentUtil.isTypeCell(cell) && matchesSources(cell.getSource(), sourceTypes))
          result.add(cell);
      return result;
    }

    if (!AlignmentUtil.isTypeCell(typeCell))
      throw new IllegalArgumentException("Given cell is not a type cell.");

    List<Cell> result = new ArrayList<Cell>();

    TypeDefinition typeCellType =
        typeCell.getTarget().values().iterator().next().getDefinition().getType();

    // collect source entity definitions
    Collection<TypeEntityDefinition> sourceTypes = new ArrayList<TypeEntityDefinition>();
    // null check in case only target type is in question
    if (typeCell.getSource() != null) {
      Iterator<? extends Entity> it = typeCell.getSource().values().iterator();
      while (it.hasNext()) sourceTypes.add((TypeEntityDefinition) it.next().getDefinition());
    }

    while (typeCellType != null) {
      // select all cells of the target type
      for (Cell cell : cellsPerTargetType.get(typeCellType)) {
        // check all cells associated to the target type
        if (!AlignmentUtil.isTypeCell(cell)
            && (includeDisabled || !cell.getDisabledFor().contains(typeCell.getId()))) {
          // cell is a property cell that isn't disabled
          // the target type matches, too
          if (AlignmentUtil.isAugmentation(cell)
              || (ignoreEmptySource && sourceTypes.isEmpty())
              || matchesSources(cell.getSource(), sourceTypes)) {
            // cell matches on the source side, too
            result.add(cell);
          }
        }
      }

      // continue with super type for inheritance
      typeCellType = typeCellType.getSuperType();
    }

    return result;
  }
コード例 #5
0
ファイル: DefaultAlignment.java プロジェクト: halestudio/hale
  /**
   * Add a cell to the various internal containers.
   *
   * @param cell the cell to add
   */
  private void internalAdd(Cell cell) {
    cells.add(cell);
    idToCell.put(cell.getId(), cell);

    // check if cell is a type cell
    if (AlignmentUtil.isTypeCell(cell)) {
      typeCells.add(cell);
    }

    // add to maps
    internalAddToMaps(cell.getSource(), cell);
    internalAddToMaps(cell.getTarget(), cell);
  }
コード例 #6
0
ファイル: DefaultAlignment.java プロジェクト: halestudio/hale
  /** @see MutableAlignment#removeCell(Cell) */
  @Override
  public boolean removeCell(Cell cell) {
    boolean removed = cells.remove(cell);
    if (removed) {
      typeCells.remove(cell);

      idToCell.remove(cell.getId());

      // remove from maps
      internalRemoveFromMaps(cell.getSource(), cell);
      internalRemoveFromMaps(cell.getTarget(), cell);
    }

    return removed;
  }
コード例 #7
0
ファイル: OMLReaderTest.java プロジェクト: nunotoriz/hale
  /** 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);
  }