Search in sources :

Example 76 with DataColumnSpecCreator

use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.

the class DefaultDataArray method setMaxValue.

/**
 * Sets a new max value for the specified column.
 *
 * @param colIdx the index of the column to set the new max value for
 * @param newMaxValue the new max value for the specified column. Must not
 *            be <code>null</code> and must fit the type of the column.
 */
public void setMaxValue(final int colIdx, final DataCell newMaxValue) {
    if (newMaxValue == null) {
        throw new IllegalArgumentException("The new maximum value must not be null");
    }
    if (!m_tSpec.getColumnSpec(colIdx).getType().isASuperTypeOf(newMaxValue.getType())) {
        throw new IllegalArgumentException("new maximum value is of wrong type");
    }
    DataColumnSpec[] colSpecs = new DataColumnSpec[m_tSpec.getNumColumns()];
    for (int i = 0; i < colSpecs.length; i++) {
        colSpecs[i] = m_tSpec.getColumnSpec(i);
    }
    DataColumnSpecCreator sCrea = new DataColumnSpecCreator(colSpecs[colIdx]);
    DataColumnDomainCreator dCrea = new DataColumnDomainCreator(colSpecs[colIdx].getDomain());
    dCrea.setUpperBound(newMaxValue);
    sCrea.setDomain(dCrea.createDomain());
    colSpecs[colIdx] = sCrea.createSpec();
    m_tSpec = new DataTableSpec(m_tSpec.getName(), colSpecs);
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator)

Example 77 with DataColumnSpecCreator

use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.

the class DefaultDataArray method setMinValue.

/**
 * Sets a new min value for the specified column.
 *
 * @param colIdx the index of the column to set the new min value for. Must
 *            be between zero and the size of this container.
 * @param newMinValue the new min value for the specified column. Must not
 *            be <code>null</code> and must fit the type of the column.
 */
public void setMinValue(final int colIdx, final DataCell newMinValue) {
    if (newMinValue == null) {
        throw new IllegalArgumentException("The new minimum value must not be null");
    }
    if (!m_tSpec.getColumnSpec(colIdx).getType().isASuperTypeOf(newMinValue.getType())) {
        throw new IllegalArgumentException("new minimum value is of wrong type");
    }
    DataColumnSpec[] colSpecs = new DataColumnSpec[m_tSpec.getNumColumns()];
    for (int i = 0; i < colSpecs.length; i++) {
        colSpecs[i] = m_tSpec.getColumnSpec(i);
    }
    DataColumnSpecCreator sCrea = new DataColumnSpecCreator(colSpecs[colIdx]);
    DataColumnDomainCreator dCrea = new DataColumnDomainCreator(colSpecs[colIdx].getDomain());
    dCrea.setLowerBound(newMinValue);
    sCrea.setDomain(dCrea.createDomain());
    colSpecs[colIdx] = sCrea.createSpec();
    m_tSpec = new DataTableSpec(m_tSpec.getName(), colSpecs);
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator)

Example 78 with DataColumnSpecCreator

use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.

the class ExpandVectorNodeModel method createRearranger.

/**
 * Creates the {@link ColumnRearranger} to perform the computation.
 *
 * @param table The input table.
 * @param exec An {@link ExecutionMonitor}.
 * @return The {@link ColumnRearranger}.
 * @throws CanceledExecutionException Execution cancelled.
 */
private ColumnRearranger createRearranger(final BufferedDataTable table, final ExecutionMonitor exec) throws CanceledExecutionException {
    DataTableSpec spec = table.getSpec();
    final ColumnRearranger ret = new ColumnRearranger(spec);
    ExecutionMonitor subRead = exec.createSubProgress(.25);
    int maxOutput = 0;
    String inputColumnName = findInputColumnName(spec);
    final int colIndex = spec.findColumnIndex(inputColumnName);
    for (DataRow dataRow : table) {
        subRead.checkCanceled();
        DataCell cell = dataRow.getCell(colIndex);
        long length = getCellLength(cell);
        if (length > m_maxNewColumns.getIntValue()) {
            length = m_maxNewColumns.getIntValue();
        }
        maxOutput = Math.max(maxOutput, (int) length);
    }
    final String[] colNames = new String[maxOutput];
    final DataColumnSpec inputSpec = spec.getColumnSpec(inputColumnName);
    final int namedColumns;
    if (useNames()) {
        String[] origNames = inputSpec.getElementNames().toArray(new String[0]);
        System.arraycopy(origNames, 0, colNames, 0, Math.min(maxOutput, origNames.length));
        namedColumns = origNames.length;
    } else {
        namedColumns = 0;
    }
    for (int i = namedColumns; i < maxOutput; ++i) {
        colNames[i] = m_outputPrefix.getStringValue() + (i - namedColumns + m_startIndex.getIntValue());
    }
    DataColumnSpec[] outputColumns = new DataColumnSpec[maxOutput];
    DataColumnSpecCreator dataColumnSpecCreator = new DataColumnSpecCreator("Dummy", IntCell.TYPE);
    for (int idx = 0; idx < colNames.length; ++idx) {
        dataColumnSpecCreator.setName(DataTableSpec.getUniqueColumnName(spec, colNames[idx]));
        outputColumns[idx] = dataColumnSpecCreator.createSpec();
    }
    ret.append(createCellFactory(colNames, outputColumns, colIndex));
    if (m_removeOriginal.getBooleanValue()) {
        ret.remove(inputColumnName);
    }
    return ret;
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataCell(org.knime.core.data.DataCell) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) DataRow(org.knime.core.data.DataRow)

Example 79 with DataColumnSpecCreator

use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.

the class UniqueNameGeneratorTest method testNewCreatorFromColumn.

@Test
public void testNewCreatorFromColumn() {
    UniqueNameGenerator ng = new UniqueNameGenerator(USED_NAMES);
    DataColumnSpecCreator c1 = ng.newCreator(new DataColumnSpecCreator("NewName", StringCell.TYPE).createSpec());
    assertEquals("NewName", c1.createSpec().getName());
    DataColumnSpecCreator c2 = ng.newCreator(new DataColumnSpecCreator("NewName", StringCell.TYPE).createSpec());
    assertEquals("NewName (#1)", c2.createSpec().getName());
    DataColumnSpecCreator c3 = ng.newCreator(new DataColumnSpecCreator("Parenthesis (#1)", StringCell.TYPE).createSpec());
    assertEquals("Parenthesis (#2)", c3.createSpec().getName());
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) Test(org.junit.Test)

Example 80 with DataColumnSpecCreator

use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.

the class SotaPredictorNodeModel method createOutColSpecs.

/**
 * @param sotaSpec
 * @return
 * @throws InvalidSettingsException
 */
private DataColumnSpec[] createOutColSpecs(final SotaPortObjectSpec sotaSpec) throws InvalidSettingsException {
    final PredictorHelper ph = PredictorHelper.getInstance();
    final DataColumnSpec classColumnSpec = sotaSpec.getClassColumnSpec();
    String trainingColumnName = classColumnSpec == null ? "No class" : classColumnSpec.getName();
    final String predColName = ph.checkedComputePredictionColumnName(m_customPrediction.getStringValue(), m_changePrediction.getBooleanValue(), trainingColumnName);
    final DataColumnSpec[] colSpecs;
    if (m_appendProbs.getBooleanValue() && sotaSpec.hasClassColumn()) {
        assert classColumnSpec != null;
        @SuppressWarnings("null") Set<DataCell> values = classColumnSpec.getDomain().getValues();
        if (values != null) {
            colSpecs = new DataColumnSpec[values.size() + 1];
            int idx = 0;
            for (DataCell dataCell : values) {
                colSpecs[idx++] = new DataColumnSpecCreator(ph.probabilityColumnName(trainingColumnName, dataCell.toString(), m_probSuffix.getStringValue()), DoubleCell.TYPE).createSpec();
            }
        } else {
            colSpecs = new DataColumnSpec[1];
        }
    } else {
        colSpecs = new DataColumnSpec[1];
    }
    colSpecs[colSpecs.length - 1] = new DataColumnSpecCreator(predColName, StringCell.TYPE).createSpec();
    return colSpecs;
}
Also used : PredictorHelper(org.knime.base.node.mine.util.PredictorHelper) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataCell(org.knime.core.data.DataCell) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Aggregations

DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)267 DataColumnSpec (org.knime.core.data.DataColumnSpec)210 DataTableSpec (org.knime.core.data.DataTableSpec)132 DataCell (org.knime.core.data.DataCell)92 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)77 DataType (org.knime.core.data.DataType)74 DataRow (org.knime.core.data.DataRow)73 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)57 DataColumnDomainCreator (org.knime.core.data.DataColumnDomainCreator)51 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)48 ArrayList (java.util.ArrayList)46 DoubleCell (org.knime.core.data.def.DoubleCell)45 SingleCellFactory (org.knime.core.data.container.SingleCellFactory)44 StringCell (org.knime.core.data.def.StringCell)29 BufferedDataTable (org.knime.core.node.BufferedDataTable)23 DoubleValue (org.knime.core.data.DoubleValue)22 HashSet (java.util.HashSet)19 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)17 DataColumnDomain (org.knime.core.data.DataColumnDomain)16 DefaultRow (org.knime.core.data.def.DefaultRow)16