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);
}
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);
}
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;
}
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());
}
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;
}
Aggregations