Search in sources :

Example 91 with IntCell

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

the class Statistics3Table method createNominalValueTable.

/**
 * Create nominal value table containing all possible values together with their occurrences.
 *
 * @param nominal value output table
 * @return data table with nominal values for each column
 */
public DataTable createNominalValueTable(final List<String> nominal) {
    DataTableSpec outSpec = createOutSpecNominal(m_spec, nominal);
    @SuppressWarnings("unchecked") Iterator<Entry<DataCell, Integer>>[] it = new Iterator[(outSpec.getNumColumns() / 3)];
    long[] totals = new long[it.length];
    for (int i = 0, index = 0; i < m_nominalValues.size(); i++) {
        Map<DataCell, Integer> currentMap = m_nominalValues.get(i);
        if (currentMap != null) {
            it[index] = currentMap.entrySet().iterator();
            totals[index] = currentMap.values().stream().collect(Collectors.summingLong(Integer::valueOf));
            index += 1;
        }
    }
    DataContainer cont = new DataContainer(outSpec, true);
    int rowIndex = 0;
    do {
        boolean addEnd = true;
        DataCell[] cells = new DataCell[3 * it.length];
        for (int i = 0; i < it.length; i++) {
            if (it[i].hasNext()) {
                Map.Entry<DataCell, Integer> e = it[i].next();
                cells[3 * i] = e.getKey();
                int count = e.getValue().intValue();
                cells[3 * i + 1] = new IntCell(count);
                cells[3 * i + 2] = new DoubleCell((double) count / totals[i]);
                addEnd = false;
            } else {
                cells[3 * i] = DataType.getMissingCell();
                cells[3 * i + 1] = DataType.getMissingCell();
                cells[3 * i + 2] = DataType.getMissingCell();
            }
        }
        if (addEnd) {
            break;
        }
        cont.addRowToTable(new DefaultRow(RowKey.createRowKey(rowIndex++), cells));
    } while (true);
    cont.close();
    return cont.getTable();
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DoubleCell(org.knime.core.data.def.DoubleCell) IntCell(org.knime.core.data.def.IntCell) MutableInteger(org.knime.core.util.MutableInteger) DataContainer(org.knime.core.data.container.DataContainer) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) Iterator(java.util.Iterator) RowIterator(org.knime.core.data.RowIterator) DataCell(org.knime.core.data.DataCell) BlobWrapperDataCell(org.knime.core.data.container.BlobWrapperDataCell) DefaultRow(org.knime.core.data.def.DefaultRow) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 92 with IntCell

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

the class AppendVariableToTable2NodeModel method createColumnRearranger.

@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec spec) throws InvalidSettingsException {
    ColumnRearranger arranger = new ColumnRearranger(spec);
    Set<String> nameHash = new HashSet<String>();
    for (DataColumnSpec c : spec) {
        nameHash.add(c.getName());
    }
    List<Pair<String, FlowVariable.Type>> vars = getVariablesOfInterest();
    if (vars.isEmpty()) {
        throw new InvalidSettingsException("No variables selected");
    }
    DataColumnSpec[] specs = new DataColumnSpec[vars.size()];
    final DataCell[] values = new DataCell[vars.size()];
    for (int i = 0; i < vars.size(); i++) {
        Pair<String, FlowVariable.Type> c = vars.get(i);
        String name = c.getFirst();
        final DataType type;
        switch(c.getSecond()) {
            case DOUBLE:
                type = DoubleCell.TYPE;
                try {
                    double dValue = peekFlowVariableDouble(name);
                    values[i] = new DoubleCell(dValue);
                } catch (NoSuchElementException e) {
                    throw new InvalidSettingsException("No such flow variable (of type double): " + name);
                }
                break;
            case INTEGER:
                type = IntCell.TYPE;
                try {
                    int iValue = peekFlowVariableInt(name);
                    values[i] = new IntCell(iValue);
                } catch (NoSuchElementException e) {
                    throw new InvalidSettingsException("No such flow variable (of type int): " + name);
                }
                break;
            case STRING:
                type = StringCell.TYPE;
                try {
                    String sValue = peekFlowVariableString(name);
                    sValue = sValue == null ? "" : sValue;
                    values[i] = new StringCell(sValue);
                } catch (NoSuchElementException e) {
                    throw new InvalidSettingsException("No such flow variable (of type String): " + name);
                }
                break;
            default:
                throw new InvalidSettingsException("Unsupported variable type: " + c.getSecond());
        }
        if (nameHash.contains(name) && !name.toLowerCase().endsWith("(variable)")) {
            name = name.concat(" (variable)");
        }
        String newName = name;
        int uniquifier = 1;
        while (!nameHash.add(newName)) {
            newName = name + " (#" + (uniquifier++) + ")";
        }
        specs[i] = new DataColumnSpecCreator(newName, type).createSpec();
    }
    arranger.append(new AbstractCellFactory(specs) {

        /**
         * {@inheritDoc}
         */
        @Override
        public DataCell[] getCells(final DataRow row) {
            return values;
        }
    });
    return arranger;
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DoubleCell(org.knime.core.data.def.DoubleCell) DataRow(org.knime.core.data.DataRow) IntCell(org.knime.core.data.def.IntCell) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataType(org.knime.core.data.DataType) HashSet(java.util.HashSet) Pair(org.knime.core.util.Pair) AbstractCellFactory(org.knime.core.data.container.AbstractCellFactory) PortType(org.knime.core.node.port.PortType) DataType(org.knime.core.data.DataType) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell) NoSuchElementException(java.util.NoSuchElementException) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 93 with IntCell

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

the class PercentOperator method getResultInternal.

/**
 * {@inheritDoc}
 */
@Override
protected DataCell getResultInternal() {
    final long itemCount = getGlobalSettings().getNoOfItems();
    if (itemCount == 0) {
        return ZERO_PERCENTAGE;
    }
    final IntCell resultInternal = (IntCell) super.getResultInternal();
    final double percentage = resultInternal.getDoubleValue() / itemCount * 100;
    return new DoubleCell(percentage);
}
Also used : DoubleCell(org.knime.core.data.def.DoubleCell) IntCell(org.knime.core.data.def.IntCell)

Example 94 with IntCell

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

the class SumOperator method getResultInternal.

/**
 * {@inheritDoc}
 */
@Override
protected DataCell getResultInternal() {
    if (!m_valid) {
        return DataType.getMissingCell();
    }
    if (IntCell.TYPE.equals(m_type)) {
        // check if the double value is to big for an integer
        if (m_sum > Integer.MAX_VALUE) {
            setSkipped(true);
            setSkipMessage("Sum > maximum int value. " + "Convert column to long.");
            return DataType.getMissingCell();
        }
        return new IntCell((int) m_sum);
    } else if (LongCell.TYPE.equals(m_type)) {
        // check if the double value is to big for a long
        if (m_sum > Long.MAX_VALUE) {
            setSkipped(true);
            setSkipMessage("Sum > maximum long value. " + "Convert column to double.");
            return DataType.getMissingCell();
        }
        return new LongCell((long) m_sum);
    }
    return new DoubleCell(m_sum);
}
Also used : LongCell(org.knime.core.data.def.LongCell) DoubleCell(org.knime.core.data.def.DoubleCell) IntCell(org.knime.core.data.def.IntCell)

Example 95 with IntCell

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

the class LogisticRegressionContent method createModelStatisticsTable.

BufferedDataTable createModelStatisticsTable(final ExecutionContext exec) {
    BufferedDataContainer container = exec.createDataContainer(createModelStatisticsTableSpec());
    DataCell[] cells = new DataCell[] { new IntCell(getIterationCount()), new DoubleCell(getEstimatedLikelihood()) };
    DataRow row = new DefaultRow(RowKey.createRowKey(0L), cells);
    container.addRowToTable(row);
    container.close();
    return container.getTable();
}
Also used : BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DoubleCell(org.knime.core.data.def.DoubleCell) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) DataRow(org.knime.core.data.DataRow) 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