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