Search in sources :

Example 21 with FilterResult

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

the class EditNumericDomainNodeModel method processDomainSettings.

private DataTableSpec processDomainSettings(final DataTableSpec dataTableSpec) throws InvalidSettingsException {
    if (m_configuration == null) {
        throw new InvalidSettingsException("Missing Configuration.");
    }
    EditNumericDomainConfiguration config = m_configuration;
    FilterResult filterResult = config.getColumnspecFilterConfig().applyTo(dataTableSpec);
    List<DataColumnSpec> newColumnSpecs = new ArrayList<DataColumnSpec>(dataTableSpec.getNumColumns());
    String[] columnNames = dataTableSpec.getColumnNames();
    Set<String> includeSet = new HashSet<String>();
    Collections.addAll(includeSet, filterResult.getIncludes());
    for (int i = 0; i < dataTableSpec.getNumColumns(); i++) {
        DataColumnSpec columnSpec = dataTableSpec.getColumnSpec(i);
        String columnName = columnNames[i];
        if (includeSet.contains(columnName)) {
            DataColumnSpecCreator columnSpecCreator = new DataColumnSpecCreator(columnSpec);
            DataColumnDomainCreator domainCreator = new // 
            DataColumnDomainCreator(// 
            createCell(columnName, columnSpec.getType(), config.getLowerBound()), createCell(columnName, columnSpec.getType(), config.getUpperBound()));
            domainCreator.setValues(columnSpec.getDomain().getValues());
            columnSpecCreator.setDomain(domainCreator.createDomain());
            newColumnSpecs.add(columnSpecCreator.createSpec());
        } else {
            newColumnSpecs.add(columnSpec);
        }
    }
    StringBuilder warnings = new StringBuilder();
    if (includeSet.isEmpty()) {
        warnings.append("No columns are included.");
    }
    if (filterResult.getRemovedFromIncludes().length > 0) {
        warnings.append("\nFollowing columns are configured but no longer exist: " + ConvenienceMethods.getShortStringFrom(Arrays.asList(filterResult.getRemovedFromIncludes()), 5));
    }
    if (warnings.length() > 0) {
        setWarningMessage(warnings.toString());
    }
    return new DataTableSpecCreator(dataTableSpec).dropAllColumns().addColumns(newColumnSpecs.toArray(new DataColumnSpec[newColumnSpecs.size()])).createSpec();
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataTableSpecCreator(org.knime.core.data.DataTableSpecCreator) ArrayList(java.util.ArrayList) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator) DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult) HashSet(java.util.HashSet)

Example 22 with FilterResult

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

the class DataColumnSpecFilterNodeModel method createColumnRearranger.

/**
 * Creates the output data table spec according to the current settings.
 * Throws an InvalidSettingsException if columns are specified that don't
 * exist in the input table spec.
 *
 * @since 3.1
 */
protected ColumnRearranger createColumnRearranger(final DataTableSpec spec) {
    if (m_conf == null) {
        m_conf = createDCSFilterConfiguration();
        // auto-configure
        m_conf.loadDefaults(spec, true);
    }
    final FilterResult filter = getFilterResult(spec);
    final String[] incls = filter.getIncludes();
    final ColumnRearranger c = new ColumnRearranger(spec);
    c.keepOnly(incls);
    return c;
}
Also used : ColumnRearranger(org.knime.core.data.container.ColumnRearranger) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult)

Example 23 with FilterResult

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

the class Many2OneCol2PMMLNodeModel method getCellFactory.

private AbstractMany2OneCellFactory getCellFactory(final DataTableSpec spec) {
    AbstractMany2OneCellFactory cellFactory;
    IncludeMethod method = IncludeMethod.valueOf(m_includeMethod.getStringValue());
    FilterResult filterResult = m_includedColumns.applyTo(spec);
    String[] includes = filterResult.getIncludes();
    int[] includedColIndices = new int[includes.length];
    int index = 0;
    for (String colName : includes) {
        includedColIndices[index++] = spec.findColumnIndex(colName);
    }
    String newColName = DataTableSpec.getUniqueColumnName(spec, m_appendedColumnName.getStringValue());
    m_appendedColumnName.setStringValue(newColName);
    if (method.equals(IncludeMethod.RegExpPattern)) {
        cellFactory = new RegExpCellFactory(spec, newColName, includedColIndices, m_pattern.getStringValue());
    } else if (method.equals(IncludeMethod.Minimum)) {
        cellFactory = new MinMaxCellFactory(spec, newColName, includedColIndices, false);
    } else if (method.equals(IncludeMethod.Binary)) {
        cellFactory = new BinaryCellFactory(spec, newColName, includedColIndices);
    } else {
        cellFactory = new MinMaxCellFactory(spec, newColName, includedColIndices, true);
    }
    return cellFactory;
}
Also used : RegExpCellFactory(org.knime.base.node.preproc.columntrans2.RegExpCellFactory) BinaryCellFactory(org.knime.base.node.preproc.columntrans2.BinaryCellFactory) AbstractMany2OneCellFactory(org.knime.base.node.preproc.columntrans2.AbstractMany2OneCellFactory) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) MinMaxCellFactory(org.knime.base.node.preproc.columntrans2.MinMaxCellFactory)

Example 24 with FilterResult

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

the class ColumnAggregatorNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
    if (m_methods.isEmpty()) {
        throw new InvalidSettingsException("Please select at least one aggregation method");
    }
    // check if at least one of the columns exists in the input table
    final DataTableSpec inSpec = inSpecs[0];
    final FilterResult filterResult = m_aggregationCols.applyTo(inSpec);
    final List<String> selectedCols = Arrays.asList(filterResult.getIncludes());
    if (selectedCols == null || selectedCols.isEmpty()) {
        throw new InvalidSettingsException("Please select at least one aggregation column");
    }
    int missing = 0;
    for (final String colName : selectedCols) {
        if (!inSpec.containsName(colName)) {
            missing++;
            setWarningMessage(colName + " not found in input table");
        }
    }
    if (missing > 0) {
        setWarningMessage(missing + " of the selected columns not found in input table. " + "See console for details.");
    }
    if (missing == selectedCols.size()) {
        throw new InvalidSettingsException("None of the selected columns found in input table.");
    }
    // configure also all aggregation operators to check if they can be
    // applied to the given input table
    NamedAggregationOperator.configure(inSpec, m_methods);
    final AggregationCellFactory cellFactory = new AggregationCellFactory(inSpec, selectedCols, GlobalSettings.DEFAULT, m_methods);
    return new DataTableSpec[] { createRearranger(inSpec, cellFactory).createSpec() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 25 with FilterResult

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

the class ColumnAggregatorNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    final BufferedDataTable table = inData[0];
    final DataTableSpec origSpec = table.getSpec();
    final FilterResult filterResult = m_aggregationCols.applyTo(origSpec);
    final List<String> selectedCols = Arrays.asList(filterResult.getIncludes());
    final GlobalSettings globalSettings = GlobalSettings.builder().setFileStoreFactory(FileStoreFactory.createWorkflowFileStoreFactory(exec)).setGroupColNames(selectedCols).setMaxUniqueValues(m_maxUniqueValues.getIntValue()).setValueDelimiter(getDefaultValueDelimiter()).setDataTableSpec(origSpec).setNoOfRows(table.size()).setAggregationContext(AggregationContext.COLUMN_AGGREGATION).build();
    final AggregationCellFactory cellFactory = new AggregationCellFactory(origSpec, selectedCols, globalSettings, m_methods);
    final ColumnRearranger cr = createRearranger(origSpec, cellFactory);
    final BufferedDataTable out = exec.createColumnRearrangeTable(table, cr, exec);
    return new BufferedDataTable[] { out };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) BufferedDataTable(org.knime.core.node.BufferedDataTable) GlobalSettings(org.knime.base.data.aggregation.GlobalSettings) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

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