Search in sources :

Example 26 with FilterResult

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

the class ColumnAggregatorNodeModel method createStreamableOperator.

/* ================= STREAMING ================= */
/**
 * {@inheritDoc}
 */
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    return new StreamableOperator() {

        @Override
        public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
            final DataTableSpec origSpec = (DataTableSpec) inSpecs[0];
            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(-1).setAggregationContext(AggregationContext.COLUMN_AGGREGATION).build();
            final AggregationCellFactory cellFactory = new AggregationCellFactory(origSpec, selectedCols, globalSettings, m_methods);
            final ColumnRearranger cr = createRearranger(origSpec, cellFactory);
            cr.createStreamableFunction().runFinal(inputs, outputs, exec);
        }
    };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ExecutionContext(org.knime.core.node.ExecutionContext) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) GlobalSettings(org.knime.base.data.aggregation.GlobalSettings) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 27 with FilterResult

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

the class ColumnToGrid2NodeModel method createOutputSpec.

private DataTableSpec createOutputSpec(final DataTableSpec spec) throws InvalidSettingsException {
    FilterResult filter = null;
    if (m_configuration == null) {
        m_configuration = new ColumnToGrid2Configuration(spec);
        filter = m_configuration.getFilterConfiguration().applyTo(spec);
        m_included = filter.getIncludes();
        setWarningMessage("Guessed \"" + Arrays.toString(m_included) + "\" as target column");
    }
    if (filter == null) {
        filter = m_configuration.getFilterConfiguration().applyTo(spec);
        m_included = filter.getIncludes();
    }
    String[] rmFromIncl = filter.getRemovedFromIncludes();
    if (m_configuration.getFilterConfiguration().isEnforceInclusion() && rmFromIncl.length != 0) {
        throw new InvalidSettingsException("Input table does not contain the following selected column(s): " + ConvenienceMethods.getShortStringFrom(new HashSet<String>(Arrays.asList(rmFromIncl)), 3));
    }
    DataColumnSpec groupColumn = null;
    String groupColumnName = m_configuration.getGroupColumn();
    if (groupColumnName != null) {
        groupColumn = spec.getColumnSpec(groupColumnName);
        if (groupColumn == null) {
            throw new InvalidSettingsException("Group colunmn \"" + groupColumnName + "\" not present in input table");
        }
    }
    int gridCount = m_configuration.getColCount();
    Set<String> cols = new HashSet<String>();
    List<DataColumnSpec> colSpecs = new ArrayList<DataColumnSpec>();
    for (int grid = 0; grid < gridCount; grid++) {
        for (int i = 0; i < m_included.length; i++) {
            DataColumnSpec in = spec.getColumnSpec(m_included[i]);
            String name = in.getName() + " (" + grid + ")";
            String colName = getUniqueColumn(name, cols);
            DataColumnSpecCreator newSpecC = new DataColumnSpecCreator(in);
            newSpecC.setName(colName);
            newSpecC.removeAllHandlers();
            colSpecs.add(newSpecC.createSpec());
        }
    }
    if (groupColumn != null) {
        colSpecs.add(groupColumn);
    }
    DataColumnSpec[] columnArray = colSpecs.toArray(new DataColumnSpec[colSpecs.size()]);
    return new DataTableSpec(spec.getName(), columnArray);
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) ArrayList(java.util.ArrayList) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) 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 28 with FilterResult

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

the class FeatureSelectionLoopStartNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
    for (int i = 1; i < inSpecs.length; i++) {
        if (!inSpecs[0].equalStructure(inSpecs[i])) {
            throw new InvalidSettingsException("All input tables must have the same structure");
        }
    }
    final DataColumnSpecFilterConfiguration filterConfig = m_settings.getStaticColumnsFilterConfiguration();
    final FilterResult filterResult = filterConfig.applyTo(inSpecs[0]);
    final String[] constantColumns;
    // check if no feature columns are selected (e.g. before the dialog is opened the first time)
    if (filterResult.getIncludes().length == 0) {
        throw new InvalidSettingsException("No feature columns selected. Please specify the feature columns in the dialog.");
    }
    if (filterResult.getExcludes().length == 0) {
        setWarningMessage("No constant columns selected. Are you sure you don't need a target column?");
    }
    constantColumns = filterResult.getExcludes();
    for (String colName : constantColumns) {
        if (!inSpecs[0].containsName(colName)) {
            throw new InvalidSettingsException("The specified constant column \"" + colName + "\" is not contained in the input tables.");
        }
    }
    if (m_iteration == 0) {
        // get feature selector
        try {
            final AbstractColumnHandler columnHandler = new DefaultColumnHandler(Arrays.asList(constantColumns), inSpecs[0]);
            final FeatureSelectionStrategy strategy = FeatureSelectionStrategies.createFeatureSelectionStrategy(m_settings.getSelectionStrategy(), m_settings.getNrFeaturesThreshold(), columnHandler.getAvailableFeatures());
            m_featureSelector = new FeatureSelector(strategy, columnHandler);
            // push max iterations flowvariable
            m_maxIterations = m_featureSelector.getNumberOfIterations();
            pushFlowVariableInt("maxIterations", m_maxIterations);
        } catch (Throwable t) {
            throw new InvalidSettingsException("Exception during feature selector setup", t);
        }
    }
    // push flowvariables
    pushFlowVariableInt("currentIteration", m_iteration);
    pushFlowVariableString("currentFeature", m_featureSelector.getCurrentFeatureName());
    final DataTableSpec outSpec = m_featureSelector.getOutSpec(inSpecs[0]);
    final DataTableSpec[] outSpecs = new DataTableSpec[inSpecs.length];
    Arrays.fill(outSpecs, outSpec);
    return outSpecs;
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpecFilterConfiguration(org.knime.core.node.util.filter.column.DataColumnSpecFilterConfiguration) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult)

Example 29 with FilterResult

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

the class VirtualSubNodeOutputNodeModel method getVisibleFlowVariables.

/**
 * @return
 */
private Collection<FlowVariable> getVisibleFlowVariables() {
    Map<String, FlowVariable> filter = new LinkedHashMap<>(Node.invokeGetAvailableFlowVariables(this, Type.values()));
    FilterResult result = m_configuration.getFilterConfiguration().applyTo(filter);
    filter.keySet().retainAll(Arrays.asList(result.getIncludes()));
    return filter.values().stream().filter(e -> !e.isGlobalConstant()).collect(Collectors.toList());
}
Also used : Arrays(java.util.Arrays) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) FlowVariable(org.knime.core.node.workflow.FlowVariable) PortObjectInput(org.knime.core.node.streamable.PortObjectInput) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) LinkedHashMap(java.util.LinkedHashMap) ExecutionContext(org.knime.core.node.ExecutionContext) ExecutionEnvironment(org.knime.core.node.workflow.ExecutionEnvironment) Node(org.knime.core.node.Node) CredentialsProvider(org.knime.core.node.workflow.CredentialsProvider) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Map(java.util.Map) InactiveBranchPortObject(org.knime.core.node.port.inactive.InactiveBranchPortObject) WorkflowLoadHelper(org.knime.core.node.workflow.WorkflowLoadHelper) PortType(org.knime.core.node.port.PortType) PortInput(org.knime.core.node.streamable.PortInput) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) PartitionInfo(org.knime.core.node.streamable.PartitionInfo) RowInput(org.knime.core.node.streamable.RowInput) NodeStateEvent(org.knime.core.node.workflow.NodeStateEvent) Collection(java.util.Collection) ExtendedScopeNodeModel(org.knime.core.node.ExtendedScopeNodeModel) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) IOException(java.io.IOException) InactiveBranchConsumer(org.knime.core.node.port.inactive.InactiveBranchConsumer) CredentialsNode(org.knime.core.node.workflow.CredentialsStore.CredentialsNode) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) Collectors(java.util.stream.Collectors) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult) File(java.io.File) DataRow(org.knime.core.data.DataRow) PortOutput(org.knime.core.node.streamable.PortOutput) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) BufferedDataTable(org.knime.core.node.BufferedDataTable) Type(org.knime.core.node.workflow.FlowVariable.Type) InputPortRole(org.knime.core.node.streamable.InputPortRole) CheckUtils(org.knime.core.node.util.CheckUtils) Collections(java.util.Collections) PortObject(org.knime.core.node.port.PortObject) PortObjectHolder(org.knime.core.node.port.PortObjectHolder) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult) FlowVariable(org.knime.core.node.workflow.FlowVariable) LinkedHashMap(java.util.LinkedHashMap)

Example 30 with FilterResult

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

the class TypeFilterConfigurationImpl method applyTo.

/**
 * Applies this configuration to the column.
 *
 * @param columns The columns whose types to check
 * @return The filter result
 */
FilterResult applyTo(final Iterable<DataColumnSpec> columns) {
    List<String> includes = new ArrayList<String>();
    List<String> excludes = new ArrayList<String>();
    for (DataColumnSpec column : columns) {
        if (m_filter == null || m_filter.include(column)) {
            final Class<? extends DataValue> preferredValueClass = column.getType().getPreferredValueClass();
            String key = preferredValueClass.getName();
            if (m_selections.containsKey(key) && m_selections.get(key)) {
                includes.add(column.getName());
            } else {
                excludes.add(column.getName());
            }
        } else {
            excludes.add(column.getName());
        }
    }
    return new FilterResult(includes, excludes, Collections.<String>emptyList(), Collections.<String>emptyList());
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) ArrayList(java.util.ArrayList) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult)

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