Search in sources :

Example 86 with IntCell

use of org.knime.core.data.def.IntCell in project knime-core by knime.

the class DBUpdateNodeModel method createColumnRearranger.

private ColumnRearranger createColumnRearranger(final DataTableSpec inSpec, final int[] updateStatus) {
    final String updateColumn = DataTableSpec.getUniqueColumnName(inSpec, UPDATE_COLUMN);
    final DataColumnSpec cspec = new DataColumnSpecCreator(updateColumn, IntCell.TYPE).createSpec();
    final ColumnRearranger rearr = new ColumnRearranger(inSpec);
    rearr.append(new SingleCellFactory(cspec) {

        private int m_rowCount = 0;

        @Override
        public DataCell getCell(final DataRow row) {
            return new IntCell(updateStatus[m_rowCount++]);
        }
    });
    return rearr;
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataCell(org.knime.core.data.DataCell) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) DataRow(org.knime.core.data.DataRow) IntCell(org.knime.core.data.def.IntCell)

Example 87 with IntCell

use of org.knime.core.data.def.IntCell in project knime-core by knime.

the class MissingValueHandling2Panel method getSettings.

/**
 * Get the settings currently entered in the dialog.
 *
 * @return the current settings
 */
public MissingValueHandling2ColSetting getSettings() {
    int method;
    if (m_nothingButton.isSelected()) {
        method = MissingValueHandling2ColSetting.METHOD_NO_HANDLING;
    } else if (m_removeButton.isSelected()) {
        method = MissingValueHandling2ColSetting.METHOD_IGNORE_ROWS;
    } else if (m_fixButton != null && m_fixButton.isSelected()) {
        method = MissingValueHandling2ColSetting.METHOD_FIX_VAL;
        DataCell cell;
        switch(m_setting.getType()) {
            case MissingValueHandling2ColSetting.TYPE_INT:
                Object value = ((JFormattedTextField) m_fixText).getValue();
                cell = new IntCell(((Number) value).intValue());
                break;
            case MissingValueHandling2ColSetting.TYPE_DOUBLE:
                value = ((JFormattedTextField) m_fixText).getValue();
                cell = new DoubleCell(((Number) value).doubleValue());
                break;
            case MissingValueHandling2ColSetting.TYPE_STRING:
                value = ((JComboBox) m_fixText).getEditor().getItem();
                cell = new StringCell(value.toString());
                break;
            default:
                throw new RuntimeException("You shouldn't have come here.");
        }
        m_setting.setFixCell(cell);
    } else if (m_maxButton != null && m_maxButton.isSelected()) {
        method = MissingValueHandling2ColSetting.METHOD_MAX;
    } else if (m_minButton != null && m_minButton.isSelected()) {
        method = MissingValueHandling2ColSetting.METHOD_MIN;
    } else if (m_meanButton != null && m_meanButton.isSelected()) {
        method = MissingValueHandling2ColSetting.METHOD_MEAN;
    } else if (m_mostFrequentButton != null && m_mostFrequentButton.isSelected()) {
        method = MissingValueHandling2ColSetting.METHOD_MOST_FREQUENT;
    } else {
        assert false : "One button must be selected.";
        method = MissingValueHandling2ColSetting.METHOD_NO_HANDLING;
    }
    m_setting.setMethod(method);
    return m_setting;
}
Also used : JComboBox(javax.swing.JComboBox) StringCell(org.knime.core.data.def.StringCell) DoubleCell(org.knime.core.data.def.DoubleCell) JFormattedTextField(javax.swing.JFormattedTextField) DataCell(org.knime.core.data.DataCell) IntCell(org.knime.core.data.def.IntCell)

Example 88 with IntCell

use of org.knime.core.data.def.IntCell in project knime-core by knime.

the class MissingValueHandling2TableIterator method handleMissing.

/* Does the missing value handling on a row. */
private DataRow handleMissing(final DataRow row) {
    DataCell[] cells = new DataCell[row.getNumCells()];
    for (int i = 0; i < row.getNumCells(); i++) {
        MissingValueHandling2ColSetting colset = m_table.getColSetting(i);
        DataCell oldCell = row.getCell(i);
        DataCell newCell;
        if (oldCell.isMissing()) {
            switch(colset.getMethod()) {
                case MissingValueHandling2ColSetting.METHOD_NO_HANDLING:
                    newCell = oldCell;
                    break;
                case MissingValueHandling2ColSetting.METHOD_FIX_VAL:
                    newCell = m_table.getColSetting(i).getFixCell();
                    assert (newCell != null);
                    break;
                case MissingValueHandling2ColSetting.METHOD_MOST_FREQUENT:
                    newCell = m_table.getMostFrequent(i);
                    break;
                case MissingValueHandling2ColSetting.METHOD_MAX:
                    newCell = m_table.getMax(i);
                    break;
                case MissingValueHandling2ColSetting.METHOD_MIN:
                    newCell = m_table.getMin(i);
                    break;
                case MissingValueHandling2ColSetting.METHOD_MEAN:
                    // in contrast to the above, it will return
                    // a newly generate value, thus, only a double
                    double mean = m_table.getMean(i);
                    if (colset.getType() == MissingValueHandling2ColSetting.TYPE_DOUBLE) {
                        newCell = new DoubleCell(mean);
                    } else {
                        assert colset.getType() == MissingValueHandling2ColSetting.TYPE_INT;
                        newCell = new IntCell((int) Math.round(mean));
                    }
                    break;
                case MissingValueHandling2ColSetting.METHOD_IGNORE_ROWS:
                    assert false : "That should have been filtered.";
                    newCell = oldCell;
                default:
                    throw new RuntimeException("Invalid method!");
            }
        } else {
            newCell = oldCell;
        }
        cells[i] = newCell;
    }
    RowKey key = row.getKey();
    return new DefaultRow(key, cells);
}
Also used : RowKey(org.knime.core.data.RowKey) DoubleCell(org.knime.core.data.def.DoubleCell) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) IntCell(org.knime.core.data.def.IntCell)

Example 89 with IntCell

use of org.knime.core.data.def.IntCell in project knime-core by knime.

the class MissingValueHandling3TableIterator method handleMissing.

/* Does the missing value handling on a row. */
private DataRow handleMissing(final DataRow row) {
    DataCell[] cells = new DataCell[row.getNumCells()];
    for (int i = 0; i < row.getNumCells(); i++) {
        MissingValueHandling2ColSetting colset = m_table.getColSetting(i);
        DataCell oldCell = row.getCell(i);
        DataCell newCell;
        if (oldCell.isMissing()) {
            switch(colset.getMethod()) {
                case MissingValueHandling2ColSetting.METHOD_NO_HANDLING:
                    newCell = oldCell;
                    break;
                case MissingValueHandling2ColSetting.METHOD_FIX_VAL:
                    newCell = m_table.getColSetting(i).getFixCell();
                    assert (newCell != null);
                    break;
                case MissingValueHandling2ColSetting.METHOD_MOST_FREQUENT:
                    newCell = m_table.getMostFrequent(i);
                    break;
                case MissingValueHandling2ColSetting.METHOD_MAX:
                    newCell = m_table.getMax(i);
                    break;
                case MissingValueHandling2ColSetting.METHOD_MIN:
                    newCell = m_table.getMin(i);
                    break;
                case MissingValueHandling2ColSetting.METHOD_MEAN:
                    // in contrast to the above, it will return
                    // a newly generate value, thus, only a double
                    double mean = m_table.getMean(i);
                    if (colset.getType() == MissingValueHandling2ColSetting.TYPE_DOUBLE) {
                        if (Double.isNaN(mean) && m_table.getNumberNaNValues(i) == 0) {
                            newCell = new MissingCell("Calculated mean is not a number");
                        } else {
                            newCell = new DoubleCell(mean);
                        }
                    } else {
                        assert colset.getType() == MissingValueHandling2ColSetting.TYPE_INT;
                        if (Double.isNaN(mean)) {
                            newCell = new MissingCell("Calculated mean is not a number");
                        } else {
                            newCell = new IntCell((int) Math.round(mean));
                        }
                    }
                    break;
                case MissingValueHandling2ColSetting.METHOD_IGNORE_ROWS:
                    assert false : "That should have been filtered.";
                    newCell = oldCell;
                    break;
                default:
                    throw new RuntimeException("Invalid method!");
            }
        } else {
            newCell = oldCell;
        }
        cells[i] = newCell;
    }
    RowKey key = row.getKey();
    return new DefaultRow(key, cells);
}
Also used : MissingCell(org.knime.core.data.MissingCell) RowKey(org.knime.core.data.RowKey) DoubleCell(org.knime.core.data.def.DoubleCell) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) IntCell(org.knime.core.data.def.IntCell)

Example 90 with IntCell

use of org.knime.core.data.def.IntCell in project knime-core by knime.

the class CategoryToNumberCellFactory method getCells.

/**
 * {@inheritDoc}
 */
@Override
public DataCell[] getCells(final DataRow row) {
    DataCell key = row.getCell(m_index);
    if (key.isMissing()) {
        return m_mapMissingTo;
    }
    DataCell[] value = m_categories.get(key);
    if (value == null) {
        if (m_categories.size() >= m_settings.getMaxCategories()) {
            // maximum reached give error
            throw new IllegalStateException("Maximum number of categories reached for column: " + m_columnSpecs[0].getName());
        }
        int number = m_settings.getStartIndex() + m_categories.size() * m_settings.getIncrement();
        IntCell cell = new IntCell(number);
        // Keep information in two maps for performance reasons
        // This avoids creating an array every time when the category
        // already exists.
        value = new DataCell[] { cell };
        m_categories.put(key, value);
        m_map.put(key, cell);
    }
    return value;
}
Also used : DataCell(org.knime.core.data.DataCell) IntCell(org.knime.core.data.def.IntCell)

Aggregations

IntCell (org.knime.core.data.def.IntCell)109 DataCell (org.knime.core.data.DataCell)79 DoubleCell (org.knime.core.data.def.DoubleCell)67 StringCell (org.knime.core.data.def.StringCell)55 DefaultRow (org.knime.core.data.def.DefaultRow)46 DataRow (org.knime.core.data.DataRow)33 DataTableSpec (org.knime.core.data.DataTableSpec)21 RowKey (org.knime.core.data.RowKey)21 ArrayList (java.util.ArrayList)20 DataType (org.knime.core.data.DataType)20 LongCell (org.knime.core.data.def.LongCell)14 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)14 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)12 BufferedDataTable (org.knime.core.node.BufferedDataTable)12 Test (org.junit.Test)11 DataColumnSpec (org.knime.core.data.DataColumnSpec)11 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)9 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)9 DataContainer (org.knime.core.data.container.DataContainer)8 DateAndTimeValue (org.knime.core.data.date.DateAndTimeValue)8