Search in sources :

Example 46 with IntCell

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

the class LinearInterpolationStatisticMB method consumeRow.

/**
 * {@inheritDoc}
 */
@Override
protected void consumeRow(final DataRow dataRow) {
    DataCell cell = dataRow.getCell(m_colIdx);
    if (cell.isMissing()) {
        m_numMissing++;
    } else {
        for (int i = 0; i < m_numMissing; i++) {
            DataCell res;
            if (m_previous.isMissing()) {
                res = cell;
            } else {
                if (m_isDateColumn) {
                    DateAndTimeValue val = (DateAndTimeValue) cell;
                    DateAndTimeValue prevVal = (DateAndTimeValue) m_previous;
                    boolean hasDate = val.hasDate() | prevVal.hasDate();
                    boolean hasTime = val.hasTime() | prevVal.hasTime();
                    boolean hasMilis = val.hasMillis() | prevVal.hasMillis();
                    long prev = prevVal.getUTCTimeInMillis();
                    long next = val.getUTCTimeInMillis();
                    long lin = Math.round(prev + 1.0 * (i + 1) / (1.0 * (m_numMissing + 1)) * (next - prev));
                    res = new DateAndTimeCell(lin, hasDate, hasTime, hasMilis);
                } else {
                    DoubleValue val = (DoubleValue) cell;
                    double prev = ((DoubleValue) m_previous).getDoubleValue();
                    double next = val.getDoubleValue();
                    double lin = prev + 1.0 * (i + 1) / (1.0 * (m_numMissing + 1)) * (next - prev);
                    if (m_previous instanceof IntValue) {
                        // get an int, create an int
                        res = new IntCell((int) Math.round(lin));
                    } else if (m_previous instanceof LongValue) {
                        // get an long, create an long
                        res = new LongCell(Math.round(lin));
                    } else {
                        res = new DoubleCell(lin);
                    }
                }
            }
            m_values.add(res);
        }
        m_numMissing = 0;
        m_previous = cell;
    }
}
Also used : DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) DoubleCell(org.knime.core.data.def.DoubleCell) IntCell(org.knime.core.data.def.IntCell) LongCell(org.knime.core.data.def.LongCell) DoubleValue(org.knime.core.data.DoubleValue) LongValue(org.knime.core.data.LongValue) DataCell(org.knime.core.data.DataCell) DateAndTimeCell(org.knime.core.data.date.DateAndTimeCell) IntValue(org.knime.core.data.IntValue)

Example 47 with IntCell

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

the class RankCellFactory method getCell.

/**
 * {@inheritDoc}
 */
@Override
public DataCell getCell(final DataRow row) {
    // create group identification
    DataCellTuple rowVals = new DataCellTuple(row, m_groupColIndices);
    // get RankAssigner for corresponding group
    RankAssigner rankAssigner = m_groupHashTable.get(rowVals);
    DataCell rankCell = null;
    // check if RankAssigner is registered for group
    if (rankAssigner == null) {
        // create new RankAssigner and register it for this new group
        rankAssigner = createRankAssigner(m_rankMode, m_rankColIndices);
        m_groupHashTable.put(rowVals, rankAssigner);
        // create RankCell
        if (m_rankAsLong) {
            rankCell = new LongCell(rankAssigner.getRank(row));
        } else {
            rankCell = new IntCell((int) rankAssigner.getRank(row));
        }
    } else {
        // create RankCell
        if (m_rankAsLong) {
            rankCell = new LongCell(rankAssigner.getRank(row));
        } else {
            rankCell = new IntCell((int) rankAssigner.getRank(row));
        }
    }
    return rankCell;
}
Also used : LongCell(org.knime.core.data.def.LongCell) DataCell(org.knime.core.data.DataCell) IntCell(org.knime.core.data.def.IntCell)

Example 48 with IntCell

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

the class DomainDialog method takeOverSettings.

/**
 * @return an object with domain values set by the user. Or <code>null</code> if settings are invalid. Then, a error
 *         message box is displayed.
 */
private ColProperty takeOverSettings() {
    ColProperty result = new ColProperty();
    if (m_colProp.getColumnSpec().getType().isCompatible(StringValue.class)) {
        DataColumnSpecCreator dcsc = new DataColumnSpecCreator(m_colProp.getColumnSpec().getName(), m_colProp.getColumnSpec().getType());
        if (m_containsVals != null) {
            result.setReadPossibleValuesFromFile(m_containsVals.isSelected());
        }
        if ((m_containsVals == null) || m_containsVals.isSelected()) {
            // if it's null we have a string column
            Set<DataCell> pVals = null;
            // tranfser possible values
            int valCount = m_valueList.getModel().getSize();
            pVals = new LinkedHashSet<DataCell>();
            for (int i = 0; i < valCount; i++) {
                DataCell val = (DataCell) m_valueList.getModel().getElementAt(i);
                pVals.add(val);
            }
            if (pVals.size() > 0) {
                DataColumnDomainCreator domainCreator = new DataColumnDomainCreator(pVals);
                dcsc.setDomain(domainCreator.createDomain());
            }
        }
        result.setColumnSpec(dcsc.createSpec());
    } else {
        DataType type = m_colProp.getColumnSpec().getType();
        DataColumnSpecCreator dcsc = new DataColumnSpecCreator(m_colProp.getColumnSpec().getName(), type);
        DataColumnDomainCreator domainCreator = new DataColumnDomainCreator();
        if (type.equals(IntCell.TYPE)) {
            domainCreator.setLowerBound(new IntCell((int) m_lowerBoundField.getValue()));
            domainCreator.setUpperBound(new IntCell((int) m_upperBoundField.getValue()));
        } else if (type.equals(DoubleCell.TYPE)) {
            domainCreator.setLowerBound(new DoubleCell((double) m_lowerBoundField.getValue()));
            domainCreator.setUpperBound(new DoubleCell((double) m_upperBoundField.getValue()));
        }
        dcsc.setDomain(domainCreator.createDomain());
        result.setColumnSpec(dcsc.createSpec());
    }
    return result;
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DoubleCell(org.knime.core.data.def.DoubleCell) DataCell(org.knime.core.data.DataCell) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator) DataType(org.knime.core.data.DataType) IntCell(org.knime.core.data.def.IntCell)

Example 49 with IntCell

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

the class DomainDialog method addIntPosValue.

/**
 * Called when the user pressed the "Add" button to add an integer value to the list of possible values. Will add
 * the number entered, or set the error text, if user input is invalid. It will adjust the range settings (if any)
 * to include the new value.
 */
protected void addIntPosValue() {
    // clear the error.
    m_errorLabel.setText("");
    String newVal = m_editField.getText();
    if (newVal.length() < 1) {
        return;
    }
    int newInt;
    try {
        newInt = Integer.parseInt(newVal);
    } catch (NumberFormatException nfe) {
        m_errorLabel.setText("Invalid integer! Not added!");
        return;
    }
    IntCell newIntCell = new IntCell(newInt);
    addDataCellPossValue(newIntCell);
    m_editField.setText("");
}
Also used : IntCell(org.knime.core.data.def.IntCell)

Example 50 with IntCell

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

the class NumericalAttributeModel method createDataRows.

/**
 * {@inheritDoc}
 */
@Override
void createDataRows(final ExecutionMonitor exec, final BufferedDataContainer dc, final boolean ignoreMissing, final AtomicInteger rowId) throws CanceledExecutionException {
    final List<String> sortedClassVal = AttributeModel.sortCollection(m_classValues.keySet());
    if (sortedClassVal == null) {
        return;
    }
    final StringCell attributeCell = new StringCell(getAttributeName());
    for (final String classVal : sortedClassVal) {
        final List<DataCell> cells = new LinkedList<>();
        cells.add(attributeCell);
        cells.add(DataType.getMissingCell());
        cells.add(new StringCell(classVal));
        final NumericalClassValue classValue = m_classValues.get(classVal);
        cells.add(new IntCell(classValue.getNoOfNotMissingRows()));
        if (!ignoreMissing) {
            cells.add(new IntCell(classValue.getNoOfMissingValueRecs()));
        }
        cells.add(new DoubleCell(classValue.getMean()));
        cells.add(new DoubleCell(classValue.getStdDeviation()));
        dc.addRowToTable(new DefaultRow(RowKey.createRowKey(rowId.getAndIncrement()), cells.toArray(new DataCell[0])));
    }
}
Also used : StringCell(org.knime.core.data.def.StringCell) DoubleCell(org.knime.core.data.def.DoubleCell) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) LinkedList(java.util.LinkedList) 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