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);
}
};
}
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);
}
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;
}
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());
}
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());
}
Aggregations