Search in sources :

Example 36 with FilterResult

use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.

the class VirtualSubNodeInputNodeModel method pushFlowVariables.

/**
 * @throws Exception
 */
private void pushFlowVariables() throws InvalidSettingsException {
    String prefix = m_configuration.getFlowVariablePrefix() == null ? "" : m_configuration.getFlowVariablePrefix();
    FlowVariableFilterConfiguration filterConfiguration = m_configuration.getFilterConfiguration();
    Map<String, FlowVariable> availableVariables = getSubNodeContainerFlowObjectStack().getAvailableFlowVariables(Type.values());
    FilterResult filtered = filterConfiguration.applyTo(availableVariables);
    for (String include : filtered.getIncludes()) {
        FlowVariable f = availableVariables.get(include);
        switch(f.getScope()) {
            case Global:
                // ignore global flow vars
                continue;
            case Flow:
            case Local:
            default:
        }
        final String name = prefix + f.getName();
        Node.invokePushFlowVariable(this, f.withNewName(name));
    }
}
Also used : FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult) FlowVariableFilterConfiguration(org.knime.core.node.util.filter.variable.FlowVariableFilterConfiguration) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 37 with FilterResult

use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.

the class PatternFilterConfiguration method applyTo.

/**
 * Applies this configuration to the array of given names.
 *
 * @param names The names to check
 * @return FilterResult with the included and excluded names
 */
public FilterResult applyTo(final String[] names) {
    Pattern regex = compilePattern(m_pattern, m_type, m_caseSensitive);
    List<String> incls = new ArrayList<String>();
    List<String> excls = new ArrayList<String>();
    for (String name : names) {
        if (regex.matcher(name).matches()) {
            incls.add(name);
        } else {
            excls.add(name);
        }
    }
    return new FilterResult(incls, excls, new ArrayList<String>(), new ArrayList<String>());
}
Also used : Pattern(java.util.regex.Pattern) ArrayList(java.util.ArrayList) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult)

Example 38 with FilterResult

use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.

the class DataColumnSpecFilterPMMLNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] data, final ExecutionContext exec) throws Exception {
    final BufferedDataTable inTable = (BufferedDataTable) data[0];
    final BufferedDataTable outTable = super.execute(new BufferedDataTable[] { inTable }, exec)[0];
    final FilterResult res = getFilterResult(inTable.getSpec());
    final PMMLPortObject pmmlOut = createPMMLOut((PMMLPortObject) data[1], outTable.getSpec(), res);
    return new PortObject[] { outTable, pmmlOut };
}
Also used : PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) BufferedDataTable(org.knime.core.node.BufferedDataTable) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PortObject(org.knime.core.node.port.PortObject)

Example 39 with FilterResult

use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.

the class CreateBitVectorNodeModel method configure.

/**
 * Assume to get numeric data only. Output is one column of type BitVector.
 *
 * {@inheritDoc}
 */
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
    final DataTableSpec spec = inSpecs[0];
    // check the uniqueness of the output column
    if (spec.containsName(m_outputColumn.getStringValue())) {
        throw new InvalidSettingsException("Input table contains column with name " + m_outputColumn.getStringValue() + " please specifiy a new output column name.");
    }
    final ColumnType columnType = ColumnType.getType(m_columnType.getStringValue());
    final BitVectorType vectorType = BitVectorType.getType(m_vectorType.getStringValue());
    final DataTableSpec newSpec;
    if (columnType.isMultiColumn()) {
        final FilterResult multiColFilter = m_multiColumnsConfig.applyTo(spec);
        final String[] includes = multiColFilter.getIncludes();
        if (includes == null || includes.length < 1) {
            throw new InvalidSettingsException("No column selected in the multi column selection panel. Please (re-)configure the node.");
        }
        final String[] removedFromIncludes = multiColFilter.getRemovedFromIncludes();
        if (removedFromIncludes != null && removedFromIncludes.length > 0) {
            setWarningMessage("Columns " + convert2String(5, removedFromIncludes) + " not found in input table. ");
        }
        // create the output spec
        final DataColumnSpec newColSpec = createMultiColumnOutputSpec(spec, includes, vectorType);
        if (m_remove.getBooleanValue()) {
            final ColumnRearranger colR = new ColumnRearranger(spec);
            colR.remove(includes);
            newSpec = new DataTableSpec(colR.createSpec(), new DataTableSpec(newColSpec));
        } else {
            newSpec = new DataTableSpec(spec, new DataTableSpec(newColSpec));
        }
    } else {
        // parse from single column
        if (m_singleColumn.getStringValue() == null) {
            throw new InvalidSettingsException("No single column selected. Please (re-)configure the node.");
        }
        final int stringColIdx = spec.findColumnIndex(m_singleColumn.getStringValue());
        // -> check if selected column exists in the input table
        if (stringColIdx < 0) {
            throw new InvalidSettingsException("Selected column " + m_singleColumn.getStringValue() + " not in the input table");
        }
        // check that the data type is supported by the selected method
        final DataType selectedDataType = spec.getColumnSpec(m_singleColumn.getStringValue()).getType();
        if (!columnType.isCompatible(selectedDataType)) {
            throw new InvalidSettingsException("Data type of column " + m_singleColumn.getStringValue() + " is not compatible with selected method");
        }
        // create the output spec
        final ColumnRearranger c = createSingleColumnRearranger(inSpecs[0], stringColIdx, columnType, vectorType);
        newSpec = c.createSpec();
    }
    return new DataTableSpec[] { newSpec };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DataType(org.knime.core.data.DataType) BitVectorType(org.knime.core.data.vector.bitvector.BitVectorType) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 40 with FilterResult

use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.

the class CreateBitVectorNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    final BufferedDataTable data = inData[0];
    final DataTableSpec spec = data.getDataTableSpec();
    final ColumnType columnType = ColumnType.getType(m_columnType.getStringValue());
    final BitVectorType vectorType = BitVectorType.getType(m_vectorType.getStringValue());
    final String[] parsedColumnNames;
    final BitVectorCellFactory factory;
    if (columnType.isMultiColumn()) {
        final FilterResult multiColFilter = m_multiColumnsConfig.applyTo(spec);
        parsedColumnNames = multiColFilter.getIncludes();
        factory = createMultiColumnCellFactory(data, exec, columnType, vectorType, parsedColumnNames);
    } else {
        final int colIdx = spec.findColumnIndex(m_singleColumn.getStringValue());
        factory = getSingleColFactory(exec, colIdx, spec, data, columnType, vectorType);
        parsedColumnNames = new String[] { m_singleColumn.getStringValue() };
    }
    final ColumnRearranger c = new ColumnRearranger(spec);
    if (m_remove.getBooleanValue()) {
        if (columnType.isMultiColumn()) {
            c.remove(parsedColumnNames);
            c.append(factory);
        } else {
            c.replace(factory, m_singleColumn.getStringValue());
        }
    } else {
        c.append(factory);
    }
    factory.setFailOnError(m_failOnError.getBooleanValue());
    final ExecutionMonitor subExec;
    if (ColumnType.MULTI_NUMERICAL.equals(columnType) || (ColumnType.MULTI_NUMERICAL.equals(columnType) && StringType.ID.equals(StringType.getType(m_singleStringColumnType.getStringValue()))) || ColumnType.SINGLE_COLLECTION.equals(columnType)) {
        subExec = exec.createSubProgress(0.5);
    } else {
        subExec = exec;
    }
    final BufferedDataTable out = exec.createColumnRearrangeTable(data, c, subExec);
    if (!factory.wasSuccessful() && data.size() > 0) {
        final String errorMessage = factory.getNoOfPrintedErrors() + " errors found. Last message: " + factory.getLastErrorMessage() + ". See log file for details on all errors.";
        setWarningMessage(errorMessage);
    }
    m_nrOfProcessedRows = factory.getNrOfProcessedRows();
    m_totalNrOf0s = factory.getNumberOfNotSetBits();
    m_totalNrOf1s = factory.getNumberOfSetBits();
    return new BufferedDataTable[] { out };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) 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) BufferedDataTable(org.knime.core.node.BufferedDataTable) BitVectorType(org.knime.core.data.vector.bitvector.BitVectorType) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult) ExecutionMonitor(org.knime.core.node.ExecutionMonitor)

Aggregations

FilterResult (org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult)54 DataTableSpec (org.knime.core.data.DataTableSpec)29 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)29 DataColumnSpec (org.knime.core.data.DataColumnSpec)19 ArrayList (java.util.ArrayList)14 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)13 DataType (org.knime.core.data.DataType)10 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)10 BufferedDataTable (org.knime.core.node.BufferedDataTable)9 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)6 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)6 HashSet (java.util.HashSet)5 DataCell (org.knime.core.data.DataCell)5 DoubleValue (org.knime.core.data.DoubleValue)5 HashMap (java.util.HashMap)3 DataColumnProperties (org.knime.core.data.DataColumnProperties)3 DataRow (org.knime.core.data.DataRow)3 PMMLPortObjectSpecCreator (org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)3 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2