use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.
the class NameFilterConfigurationTest method testShuffledWithSomeMissingAndSomeExtra_Include.
@Test
public void testShuffledWithSomeMissingAndSomeExtra_Include() throws Exception {
NameFilterConfiguration conf = createConfiguration(EnforceOption.EnforceInclusion);
FilterResult applyTo = conf.applyTo(new String[] { "N1", "E1", "I3", "I2", "N2", "N3" });
Assert.assertArrayEquals(applyTo.getIncludes(), new String[] { "I3", "I2" });
Assert.assertArrayEquals(applyTo.getExcludes(), new String[] { "N1", "E1", "N2", "N3" });
Assert.assertArrayEquals(applyTo.getRemovedFromIncludes(), new String[] { "I1" });
Assert.assertArrayEquals(applyTo.getRemovedFromExcludes(), new String[] { "E2" });
}
use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.
the class ColumnListLoopStartNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec spec = inSpecs[0];
if (m_filterConfig == null) {
m_filterConfig = createDCSFilterConfiguration();
m_filterConfig.loadDefaults(spec, true);
throw new InvalidSettingsException("No settings available.");
}
FilterResult filter = m_filterConfig.applyTo(spec);
assert m_iteration == 0;
pushFlowVariableInt("currentIteration", m_iteration);
m_included = filter.getIncludes();
m_alwaysIncludedColumns = filter.getExcludes();
boolean runOneIter = m_noColumnsSettings.getBooleanValue();
if (m_included.length == 0 && !runOneIter) {
throw new InvalidSettingsException("No columns selected.");
}
ColumnRearranger crea = createRearranger(inSpecs[0]);
return new DataTableSpec[] { crea.createSpec() };
}
use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.
the class LinReg2Learner method init.
/**
* Initialize instance and check if settings are consistent.
*/
private void init(final DataTableSpec inSpec, final PMMLPortObjectSpec pmmlSpec, final Set<String> exclude) throws InvalidSettingsException {
m_warningMessage = null;
// Auto configuration when target is not set
if (m_settings.getTargetColumn() == null) {
List<DataColumnSpec> possibleTargets = new ArrayList<DataColumnSpec>();
for (DataColumnSpec colSpec : inSpec) {
if (colSpec.getType().isCompatible(DoubleValue.class)) {
possibleTargets.add(colSpec);
}
}
if (possibleTargets.size() > 1) {
String colName = possibleTargets.get(possibleTargets.size() - 1).getName();
m_settings.setTargetColumn(colName);
String warning = "The target column is not set. Using " + colName;
m_warningMessage = (m_warningMessage == null ? "" : m_warningMessage + "\n") + warning;
} else if (possibleTargets.size() == 1) {
m_settings.setTargetColumn(possibleTargets.get(0).getName());
} else {
throw new InvalidSettingsException("No column in " + "spec with numeric data.");
}
}
FilterResult colFilter = m_settings.getFilterConfiguration().applyTo(inSpec);
List<String> inputCols = new ArrayList<String>();
inputCols.addAll(Arrays.asList(colFilter.getIncludes()));
inputCols.remove(m_settings.getTargetColumn());
// remove all columns that should not be used
inputCols.removeAll(exclude);
if (inputCols.isEmpty()) {
throw new InvalidSettingsException("At least one column must be included.");
}
DataColumnSpec targetColSpec = null;
List<DataColumnSpec> regressorColSpecs = new ArrayList<DataColumnSpec>();
// Check type of target and input columns
for (int i = 0; i < inSpec.getNumColumns(); i++) {
DataColumnSpec colSpec = inSpec.getColumnSpec(i);
String colName = colSpec.getName();
if (m_settings.getTargetColumn().equals(colName)) {
if (colSpec.getType().isCompatible(DoubleValue.class)) {
targetColSpec = colSpec;
} else {
throw new InvalidSettingsException("Type of column \"" + colName + "\" is not numeric.");
}
} else if (inputCols.contains(colName)) {
if (colSpec.getType().isCompatible(DoubleValue.class) || colSpec.getType().isCompatible(NominalValue.class)) {
regressorColSpecs.add(colSpec);
} else {
throw new InvalidSettingsException("Type of column \"" + colName + "\" is not one of the allowed types, " + "which are numeric or nominal.");
}
}
}
if (targetColSpec != null) {
String[] learnerCols = new String[regressorColSpecs.size() + 1];
for (int i = 0; i < regressorColSpecs.size(); i++) {
learnerCols[i] = regressorColSpecs.get(i).getName();
}
learnerCols[learnerCols.length - 1] = targetColSpec.getName();
PMMLPortObjectSpecCreator creator = new PMMLPortObjectSpecCreator(pmmlSpec, inSpec);
creator.setTargetCols(Arrays.asList(targetColSpec));
creator.setLearningCols(regressorColSpecs);
m_pmmlOutSpec = creator.createSpec();
m_learner = new Learner(m_pmmlOutSpec, m_settings.getIncludeConstant(), m_settings.getOffsetValue(), m_settings.getMissingValueHandling2().equals(MissingValueHandling.fail));
} else {
throw new InvalidSettingsException("The target is " + "not in the input.");
}
}
use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.
the class AutoBinnerLearnNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec dataSpec = (DataTableSpec) inSpecs[0];
FilterResult filter = m_settings.getFilterConfiguration().applyTo(dataSpec);
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));
}
AutoBinner binner = new AutoBinner(m_settings, dataSpec);
return binner.getOutputSpec(dataSpec);
}
use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.
the class LowVarFilter2NodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
if (m_conf == null) {
// auto-guess
m_conf = createColFilterConf();
m_conf.loadDefaults(inSpecs[0], true);
m_varianceThreshold = 0.0;
setWarningMessage("Auto-configuration: Using all double-compatible " + "columns and a threshold value of 0");
}
final FilterResult filter = m_conf.applyTo(inSpecs[0]);
String[] includedColumns = filter.getIncludes();
// contains null elements in include list
if (Arrays.asList(includedColumns).contains(null)) {
throw new InvalidSettingsException("Null elements not allowed in include list");
}
// threshold check
if (m_varianceThreshold < 0.0) {
throw new InvalidSettingsException("Not configured: Please set " + "variance threshold to value >= 0");
}
HashSet<String> hash = new LinkedHashSet<String>(Arrays.asList(includedColumns));
for (DataColumnSpec s : inSpecs[0]) {
hash.remove(s.getName());
}
if (!hash.isEmpty()) {
StringBuilder missing = new StringBuilder();
Iterator<String> it = hash.iterator();
for (int i = 0; i < 3 && it.hasNext(); i++) {
if (i != 0) {
missing.append(", ");
}
missing.append('\"');
missing.append(it.next());
missing.append('\"');
}
if (it.hasNext()) {
missing.append(", ...");
}
throw new InvalidSettingsException("No such column(s): " + missing);
}
// unable to say anything about the outspec here.
return new DataTableSpec[1];
}
Aggregations