use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.
the class LowVarFilter2NodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws CanceledExecutionException {
if (m_conf == null) {
// auto-guess
m_conf = createColFilterConf();
}
final FilterResult filter = m_conf.applyTo(inData[0].getDataTableSpec());
String[] includedColumns = filter.getIncludes();
Statistics3Table statTable = new Statistics3Table(inData[0], false, 0, Collections.<String>emptyList(), exec);
ArrayList<String> includes = new ArrayList<String>();
DataTableSpec s = inData[0].getDataTableSpec();
int colCount = s.getNumColumns();
double threshold = m_varianceThreshold;
HashSet<String> includesHash = new HashSet<String>(Arrays.asList(includedColumns));
for (int i = 0; i < colCount; i++) {
DataColumnSpec cs = s.getColumnSpec(i);
if (!includesHash.contains(cs.getName()) || !cs.getType().isCompatible(DoubleValue.class) || statTable.getVariance(i) > threshold) {
includes.add(cs.getName());
}
}
int filteredOutCount = s.getNumColumns() - includes.size();
LOGGER.info("Filtered out " + filteredOutCount + " column(s)");
if (filteredOutCount == 0) {
setWarningMessage("No columns were filtered out.");
}
ColumnRearranger rearranger = new ColumnRearranger(s);
rearranger.keepOnly(includes.toArray(new String[includes.size()]));
BufferedDataTable t = exec.createColumnRearrangeTable(inData[0], rearranger, exec);
return new BufferedDataTable[] { t };
}
use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.
the class DomainNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
// auto-configuration in case no user settings are available
DataTableSpec spec = inSpecs[0];
if (m_possValConfig == null) {
m_possValConfig = createDCSFilterConfigurationPossVals();
m_possValConfig.loadDefaults(DomainNodeModel.getAllCols(NominalValue.class, spec), null, EnforceOption.EnforceInclusion);
}
if (m_minMaxConfig == null) {
m_minMaxConfig = createDCSFilterConfigurationMinMax();
m_minMaxConfig.loadDefaults(DomainNodeModel.getAllCols(BoundedValue.class, spec), null, EnforceOption.EnforceInclusion);
}
FilterResult filter = m_possValConfig.applyTo(spec);
String[] rmFromIncl = filter.getRemovedFromIncludes();
if (m_possValConfig.isEnforceInclusion() && rmFromIncl.length != 0) {
throw new InvalidSettingsException("Input table does not contain the following column(s) selected in the " + "possible value panel: " + ConvenienceMethods.getShortStringFrom(new HashSet<String>(Arrays.asList(rmFromIncl)), 3));
}
filter = m_minMaxConfig.applyTo(spec);
rmFromIncl = filter.getRemovedFromIncludes();
if (m_possValConfig.isEnforceInclusion() && rmFromIncl.length != 0) {
throw new InvalidSettingsException("Input table does not contain the following column(s) selected in the " + "Min/Max value panel: " + ConvenienceMethods.getShortStringFrom(new HashSet<String>(Arrays.asList(rmFromIncl)), 3));
}
DataTableDomainCreator domainCreator = getDomainCreator(spec);
return new DataTableSpec[] { domainCreator.createSpec() };
}
use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.
the class CategoryToNumberNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec inSpec = (DataTableSpec) inSpecs[0];
List<String> inputCols = new ArrayList<String>();
for (DataColumnSpec column : inSpec) {
if (column.getType().isCompatible(StringValue.class)) {
inputCols.add(column.getName());
}
}
FilterResult filter = m_settings.getFilterConfiguration().applyTo(inSpec);
String[] rmFromIncl = filter.getRemovedFromIncludes();
if (m_settings.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));
}
m_included = filter.getIncludes();
if (m_included.length == 0) {
setWarningMessage("No columns selected.");
}
ColumnRearranger rearranger = createRearranger(inSpec);
PMMLPortObjectSpec pmmlSpec = m_pmmlInEnabled ? (PMMLPortObjectSpec) inSpecs[1] : null;
PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(pmmlSpec, inSpec);
pmmlSpecCreator.addPreprocColNames(inputCols);
return new PortObjectSpec[] { rearranger.createSpec(), pmmlSpecCreator.createSpec() };
}
use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.
the class ColumnAggregatorNodeDialog method getSuperType.
/**
* @return the {@link DataType} the selected columns are compatible with
* or <code>null</code> if none is available or no table exists
*/
private DataType getSuperType() {
final FilterResult filterResult = m_aggregationCols.applyTo(m_spec);
final List<String> includeList = Arrays.asList(filterResult.getIncludes());
if (includeList == null || includeList.isEmpty() || m_spec == null) {
return null;
}
final Set<DataType> types = new HashSet<DataType>(includeList.size());
final HashSet<String> inclCols = new HashSet<String>(includeList);
for (final DataColumnSpec colSpec : m_spec) {
if (inclCols.contains(colSpec.getName())) {
types.add(colSpec.getType());
}
}
final DataType superType = CollectionCellFactory.getElementType(types.toArray(new DataType[0]));
return superType;
}
use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.
the class EditNumericDomainNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
//
final DataTableSpec originalTableSpec = inData[0].getDataTableSpec();
DataTableSpec editedTableSpec = processDomainSettings(inData[0].getDataTableSpec());
FilterResult filterResult = m_configuration.getColumnspecFilterConfig().applyTo(originalTableSpec);
List<String> includedColumnNames = Arrays.asList(filterResult.getIncludes());
long currentRowIndex = 0;
long size = inData[0].size();
String[] tableNames = originalTableSpec.getColumnNames();
Map<Integer, DataColumnSpec> map = new HashMap<Integer, DataColumnSpec>();
for (int i = 0; i < originalTableSpec.getNumColumns(); i++) {
if (includedColumnNames.contains(tableNames[i])) {
map.put(i, editedTableSpec.getColumnSpec(i));
} else {
map.put(i, originalTableSpec.getColumnSpec(i));
}
}
CloseableRowIterator rowIterator = inData[0].iterator();
long rowIndex = 0;
try {
while (rowIterator.hasNext()) {
DataRow currentRow = rowIterator.next();
//
exec.setProgress(//
currentRowIndex++ / (double) size, "checking domains of row: " + currentRow.getKey().getString());
for (String colName : includedColumnNames) {
int currIndex = originalTableSpec.findColumnIndex(colName);
DataCell currCell = currentRow.getCell(currIndex);
if (!currCell.isMissing() && outOfDomain(currCell, map.get(currIndex))) {
switch(m_configuration.getDomainOverflowPolicy()) {
case CALCULATE_BOUNDS:
map.put(currIndex, calculateAndCreateBoundedColumnSpec(currCell, map.get(currIndex)));
break;
case USE_EXISTING_BOUNDS:
map.put(currIndex, originalTableSpec.getColumnSpec(currIndex));
break;
default:
throw new EditNumericDomainOverflowException(tableNames[currIndex], ((DoubleValue) currCell).getDoubleValue(), m_configuration.getLowerBound(), m_configuration.getUpperBound(), rowIndex, currentRow.getKey());
}
}
}
exec.checkCanceled();
rowIndex++;
}
} finally {
rowIterator.close();
}
DataTableSpecCreator newTableSpecCreator = new DataTableSpecCreator().setName(originalTableSpec.getName()).putProperties(originalTableSpec.getProperties());
for (int i = 0; i < originalTableSpec.getNumColumns(); i++) {
newTableSpecCreator.addColumns(map.get(i));
}
return new BufferedDataTable[] { exec.createSpecReplacerTable(inData[0], newTableSpecCreator.createSpec()) };
}
Aggregations