use of org.knime.base.data.bitvector.Numeric2BitVectorThresholdCellFactory in project knime-core by knime.
the class BitVectorGeneratorNodeModel method createBitVectorsFromNumericData.
private BufferedDataTable[] createBitVectorsFromNumericData(final BufferedDataTable data, final ExecutionContext exec) throws CanceledExecutionException {
DataColumnSpec colSpec = createNumericOutputSpec(data.getDataTableSpec());
// get the indices for included columns
List<Integer> colIndices = new ArrayList<Integer>();
for (String colName : m_includedColumns.getIncludeList()) {
int index = data.getDataTableSpec().findColumnIndex(colName);
if (index < 0) {
throw new IllegalArgumentException("Column " + colName + " is not available in " + "current data. Please re-configure the node.");
}
colIndices.add(index);
}
// calculate bits from numeric data
if (m_useMean) {
// either from a percentage of the mean
double[] meanValues = new double[0];
double meanFactor = m_meanPercentage / 100.0;
meanValues = calculateMeanValues(data);
m_factory = new Numeric2BitVectorMeanCellFactory(colSpec, meanValues, meanFactor, colIndices);
} else {
// or dependend on fixed threshold
m_factory = new Numeric2BitVectorThresholdCellFactory(colSpec, m_threshold, colIndices);
}
ColumnRearranger c = new ColumnRearranger(data.getDataTableSpec());
c.append(m_factory);
if (m_replace) {
List<String> includeList = m_includedColumns.getIncludeList();
c.remove(includeList.toArray(new String[includeList.size()]));
}
BufferedDataTable out = exec.createColumnRearrangeTable(data, c, exec);
return new BufferedDataTable[] { out };
}
use of org.knime.base.data.bitvector.Numeric2BitVectorThresholdCellFactory in project knime-core by knime.
the class CreateBitVectorNodeModel method createMultiColumnCellFactory.
private BitVectorCellFactory createMultiColumnCellFactory(final BufferedDataTable data, final ExecutionContext exec, final ColumnType columnType, final BitVectorType vectorType, final String[] multiCols) throws CanceledExecutionException, InvalidSettingsException {
final DataColumnSpec colSpec = createMultiColumnOutputSpec(data.getDataTableSpec(), multiCols, vectorType);
// get the indices for included columns
final int[] colIndices = new int[multiCols.length];
int idx = 0;
for (String colName : multiCols) {
int index = data.getDataTableSpec().findColumnIndex(colName);
if (index < 0) {
throw new IllegalArgumentException("Column " + colName + " is not available in input table. Please re-configure the node.");
}
colIndices[idx++] = index;
}
final BitVectorCellFactory factory;
if (ColumnType.MULTI_NUMERICAL.equals(columnType)) {
// calculate bits from numeric data
if (m_useMean.getBooleanValue()) {
// either from a percentage of the mean
final double meanFactor = m_meanPercentage.getIntValue() / 100.0;
final double[] meanValues = calculateMeanValues(exec.createSubProgress(0.5), data, colIndices);
factory = new Numeric2BitVectorMeanCellFactory(vectorType, colSpec, meanFactor, meanValues, colIndices);
} else {
// or dependent on fixed threshold
factory = new Numeric2BitVectorThresholdCellFactory(vectorType, colSpec, m_threshold.getDoubleValue(), colIndices);
}
} else if (ColumnType.MULTI_STRING.equals(columnType)) {
final boolean setMatching = SetMatching.MATCHING.equals(SetMatching.get(m_mscSetMatching.getStringValue()));
factory = new MultiString2BitVectorCellFactory(vectorType, colSpec, m_mscCaseSensitiv.getBooleanValue(), m_mscHasWildcards.getBooleanValue(), m_mscRegex.getBooleanValue(), setMatching, m_mscPattern.getStringValue(), colIndices);
} else {
throw new IllegalStateException("Not implemeted column type " + columnType.getText());
}
return factory;
}
Aggregations