Search in sources :

Example 1 with Numeric2BitVectorThresholdCellFactory

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 };
}
Also used : ArrayList(java.util.ArrayList) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) Numeric2BitVectorThresholdCellFactory(org.knime.base.data.bitvector.Numeric2BitVectorThresholdCellFactory) DataColumnSpec(org.knime.core.data.DataColumnSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) Numeric2BitVectorMeanCellFactory(org.knime.base.data.bitvector.Numeric2BitVectorMeanCellFactory) BufferedDataTable(org.knime.core.node.BufferedDataTable)

Example 2 with Numeric2BitVectorThresholdCellFactory

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;
}
Also used : MultiString2BitVectorCellFactory(org.knime.base.data.bitvector.MultiString2BitVectorCellFactory) DataColumnSpec(org.knime.core.data.DataColumnSpec) BitVectorCellFactory(org.knime.base.data.bitvector.BitVectorCellFactory) Collection2BitVectorCellFactory(org.knime.base.data.bitvector.Collection2BitVectorCellFactory) Hex2BitVectorCellFactory(org.knime.base.data.bitvector.Hex2BitVectorCellFactory) IdString2BitVectorCellFactory(org.knime.base.data.bitvector.IdString2BitVectorCellFactory) BitString2BitVectorCellFactory(org.knime.base.data.bitvector.BitString2BitVectorCellFactory) MultiString2BitVectorCellFactory(org.knime.base.data.bitvector.MultiString2BitVectorCellFactory) Numeric2BitVectorMeanCellFactory(org.knime.base.data.bitvector.Numeric2BitVectorMeanCellFactory) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) Numeric2BitVectorThresholdCellFactory(org.knime.base.data.bitvector.Numeric2BitVectorThresholdCellFactory)

Aggregations

Numeric2BitVectorMeanCellFactory (org.knime.base.data.bitvector.Numeric2BitVectorMeanCellFactory)2 Numeric2BitVectorThresholdCellFactory (org.knime.base.data.bitvector.Numeric2BitVectorThresholdCellFactory)2 DataColumnSpec (org.knime.core.data.DataColumnSpec)2 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)2 ArrayList (java.util.ArrayList)1 BitString2BitVectorCellFactory (org.knime.base.data.bitvector.BitString2BitVectorCellFactory)1 BitVectorCellFactory (org.knime.base.data.bitvector.BitVectorCellFactory)1 Collection2BitVectorCellFactory (org.knime.base.data.bitvector.Collection2BitVectorCellFactory)1 Hex2BitVectorCellFactory (org.knime.base.data.bitvector.Hex2BitVectorCellFactory)1 IdString2BitVectorCellFactory (org.knime.base.data.bitvector.IdString2BitVectorCellFactory)1 MultiString2BitVectorCellFactory (org.knime.base.data.bitvector.MultiString2BitVectorCellFactory)1 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)1 BufferedDataTable (org.knime.core.node.BufferedDataTable)1 SettingsModelFilterString (org.knime.core.node.defaultnodesettings.SettingsModelFilterString)1