use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.
the class SplitNodeModel2 method createColumnRearrangers.
private ColumnRearranger[] createColumnRearrangers(final DataTableSpec s) {
// apply spec to settings to retrieve filter instance
final FilterResult filter = m_conf.applyTo(s);
final StringBuilder warn = new StringBuilder();
int maxToReport = 3;
final String[] unknownsIncl = filter.getRemovedFromIncludes();
final String[] unknownsExcl = filter.getRemovedFromExcludes();
final ArrayList<String> unknowns = new ArrayList<String>();
unknowns.addAll(Arrays.asList(unknownsIncl));
unknowns.addAll(Arrays.asList(unknownsExcl));
if (unknowns.size() > 0) {
warn.append("Some columns are no longer available: ");
for (int i = 0; i < unknowns.size(); i++) {
warn.append(i > 0 ? ", " : "");
if (i < maxToReport) {
warn.append("\"").append(unknowns.get(i)).append("\"");
} else {
warn.append("...<").append(unknowns.size() - maxToReport).append(" more>");
break;
}
}
}
final String[] incls = filter.getIncludes();
final String[] excls = filter.getExcludes();
if (incls.length == 0) {
if (excls.length > 0) {
if (warn.length() == 0) {
warn.append("All columns in top partition.");
} else {
warn.append("; all columns in top partition.");
}
}
} else {
if (excls.length == 0) {
if (warn.length() == 0) {
warn.append("All columns in bottom partition.");
} else {
warn.append("; all columns in bottom partition.");
}
}
}
// set warn message, if there is one
if (warn.length() > 0) {
setWarningMessage(warn.toString());
}
ColumnRearranger topArrange = new ColumnRearranger(s);
topArrange.keepOnly(filter.getExcludes());
ColumnRearranger bottomArrange = new ColumnRearranger(s);
bottomArrange.keepOnly(filter.getIncludes());
return new ColumnRearranger[] { topArrange, bottomArrange };
}
use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.
the class SplitNodeModel2 method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec in = inSpecs[0];
if (m_conf == null) {
m_conf = createColFilterConf();
m_conf.loadDefaults(in, false);
setWarningMessage("No settings available, " + "passing all columns to top output port.");
}
final FilterResult filter = m_conf.applyTo(in);
String[] top = filter.getExcludes();
String[] bottom = filter.getIncludes();
for (int i = 0; i < top.length; i++) {
if (!in.containsName(top[i])) {
throw new InvalidSettingsException("No such column: " + top[i]);
}
}
for (int i = 0; i < bottom.length; i++) {
if (!in.containsName(bottom[i])) {
throw new InvalidSettingsException("No such column: " + bottom[i]);
}
}
ColumnRearranger[] a = createColumnRearrangers(in);
return new DataTableSpec[] { a[0].createSpec(), a[1].createSpec() };
}
use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.
the class Normalizer3NodeModel method getIncludedComlumns.
/**
* @param spec the data table spec
* @throws InvalidSettingsException if no normalization mode is set
* @return the included columns
*/
private String[] getIncludedComlumns(final DataTableSpec spec) throws InvalidSettingsException {
boolean hasGuessedDefaults = false;
if (m_config == null) {
NormalizerConfig config = new NormalizerConfig();
config.guessDefaults(spec);
hasGuessedDefaults = true;
m_config = config;
}
FilterResult filterResult = m_config.getDataColumnFilterConfig().applyTo(spec);
String[] includes = filterResult.getIncludes();
if (includes.length == 0) {
StringBuilder warnings = new StringBuilder("No columns included - input stays unchanged.");
if (filterResult.getRemovedFromIncludes().length > 0) {
warnings.append("\nThe following columns were included before but no longer exist:\n");
warnings.append(ConvenienceMethods.getShortStringFrom(Arrays.asList(filterResult.getRemovedFromIncludes()), MAX_UNKNOWN_COLS));
}
setWarningMessage(warnings.toString());
} else if (hasGuessedDefaults) {
setWarningMessage("Auto-configure: [0, 1] normalization on all numeric columns: " + ConvenienceMethods.getShortStringFrom(Arrays.asList(includes), MAX_UNKNOWN_COLS));
}
return includes;
}
use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.
the class DataColumnSpecFilterPMMLNodeModel method configure.
/**
* Excludes a number of columns from the input spec and generates a new output spec.
*
* @param inSpecs the input table spec
* @return outSpecs the output table spec with some excluded columns
*
* @throws InvalidSettingsException if the selected column is not available
* in the table spec.
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
final DataTableSpec inSpec = (DataTableSpec) inSpecs[0];
final DataTableSpec outSpec = super.configure(new DataTableSpec[] { inSpec })[0];
final FilterResult res = getFilterResult(inSpec);
final PMMLPortObjectSpec pmmlSpec = createPMMLSpec((PMMLPortObjectSpec) inSpecs[1], inSpec, res);
return new PortObjectSpec[] { outSpec, pmmlSpec };
}
use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.
the class EditNominalDomainDicNodeModel method checkTypesAndAddValueTableDomainValuesContainedInSpec.
/**
* @param inSpecs
* @param config
* @param origSpec
* @param valueSpec
* @param orgIndexToNewValMap
* @throws InvalidSettingsException
*/
private void checkTypesAndAddValueTableDomainValuesContainedInSpec(final DataTableSpec origSpec, final DataTableSpec valueSpec, final Map<Integer, String> orgColIndexToColName, final Map<Integer, Set<DataCell>> orgColIndexToDomainVals) throws InvalidSettingsException {
EditNominalDomainDicConfiguration config = createDefaultConfigIfNotExist(origSpec, valueSpec);
FilterResult filterResult = config.getFilterConfiguration().applyTo(valueSpec);
List<Integer> toRemoveBecauseTypeIncompatible = new ArrayList<Integer>();
// check the correct data type and add the additional domain values if there already some.
for (Map.Entry<Integer, String> entry : orgColIndexToColName.entrySet()) {
DataType orgType = origSpec.getColumnSpec(entry.getKey()).getType();
DataType valueType = valueSpec.getColumnSpec(entry.getValue()).getType();
if (!orgType.equals(valueType)) {
if (!config.isIgnoreWrongTypes()) {
throw new InvalidSettingsException(String.format(Locale.US, "matching column '%s' has incompatible types: " + "input table [1] type: %s, domain value table type [2]: %s", origSpec.getColumnNames()[entry.getKey()], orgType, valueType));
} else {
// ignore this column on continue
toRemoveBecauseTypeIncompatible.add(entry.getKey());
}
} else {
Set<DataCell> values = valueSpec.getColumnSpec(entry.getValue()).getDomain().getValues();
if (values != null) {
orgColIndexToDomainVals.get(entry.getKey()).addAll(values);
}
}
}
for (Integer i : toRemoveBecauseTypeIncompatible) {
orgColIndexToDomainVals.remove(i);
orgColIndexToColName.remove(i);
}
StringBuilder warnings = new StringBuilder();
if (filterResult.getIncludes().length == 0) {
warnings.append("No columns in value table [2] 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());
}
}
Aggregations