use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.
the class VirtualSubNodeInputNodeModel method pushFlowVariables.
/**
* @throws Exception
*/
private void pushFlowVariables() throws InvalidSettingsException {
String prefix = m_configuration.getFlowVariablePrefix() == null ? "" : m_configuration.getFlowVariablePrefix();
FlowVariableFilterConfiguration filterConfiguration = m_configuration.getFilterConfiguration();
Map<String, FlowVariable> availableVariables = getSubNodeContainerFlowObjectStack().getAvailableFlowVariables(Type.values());
FilterResult filtered = filterConfiguration.applyTo(availableVariables);
for (String include : filtered.getIncludes()) {
FlowVariable f = availableVariables.get(include);
switch(f.getScope()) {
case Global:
// ignore global flow vars
continue;
case Flow:
case Local:
default:
}
final String name = prefix + f.getName();
Node.invokePushFlowVariable(this, f.withNewName(name));
}
}
use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.
the class PatternFilterConfiguration method applyTo.
/**
* Applies this configuration to the array of given names.
*
* @param names The names to check
* @return FilterResult with the included and excluded names
*/
public FilterResult applyTo(final String[] names) {
Pattern regex = compilePattern(m_pattern, m_type, m_caseSensitive);
List<String> incls = new ArrayList<String>();
List<String> excls = new ArrayList<String>();
for (String name : names) {
if (regex.matcher(name).matches()) {
incls.add(name);
} else {
excls.add(name);
}
}
return new FilterResult(incls, excls, new ArrayList<String>(), new ArrayList<String>());
}
use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.
the class DataColumnSpecFilterPMMLNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] data, final ExecutionContext exec) throws Exception {
final BufferedDataTable inTable = (BufferedDataTable) data[0];
final BufferedDataTable outTable = super.execute(new BufferedDataTable[] { inTable }, exec)[0];
final FilterResult res = getFilterResult(inTable.getSpec());
final PMMLPortObject pmmlOut = createPMMLOut((PMMLPortObject) data[1], outTable.getSpec(), res);
return new PortObject[] { outTable, pmmlOut };
}
use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.
the class CreateBitVectorNodeModel method configure.
/**
* Assume to get numeric data only. Output is one column of type BitVector.
*
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
final DataTableSpec spec = inSpecs[0];
// check the uniqueness of the output column
if (spec.containsName(m_outputColumn.getStringValue())) {
throw new InvalidSettingsException("Input table contains column with name " + m_outputColumn.getStringValue() + " please specifiy a new output column name.");
}
final ColumnType columnType = ColumnType.getType(m_columnType.getStringValue());
final BitVectorType vectorType = BitVectorType.getType(m_vectorType.getStringValue());
final DataTableSpec newSpec;
if (columnType.isMultiColumn()) {
final FilterResult multiColFilter = m_multiColumnsConfig.applyTo(spec);
final String[] includes = multiColFilter.getIncludes();
if (includes == null || includes.length < 1) {
throw new InvalidSettingsException("No column selected in the multi column selection panel. Please (re-)configure the node.");
}
final String[] removedFromIncludes = multiColFilter.getRemovedFromIncludes();
if (removedFromIncludes != null && removedFromIncludes.length > 0) {
setWarningMessage("Columns " + convert2String(5, removedFromIncludes) + " not found in input table. ");
}
// create the output spec
final DataColumnSpec newColSpec = createMultiColumnOutputSpec(spec, includes, vectorType);
if (m_remove.getBooleanValue()) {
final ColumnRearranger colR = new ColumnRearranger(spec);
colR.remove(includes);
newSpec = new DataTableSpec(colR.createSpec(), new DataTableSpec(newColSpec));
} else {
newSpec = new DataTableSpec(spec, new DataTableSpec(newColSpec));
}
} else {
// parse from single column
if (m_singleColumn.getStringValue() == null) {
throw new InvalidSettingsException("No single column selected. Please (re-)configure the node.");
}
final int stringColIdx = spec.findColumnIndex(m_singleColumn.getStringValue());
// -> check if selected column exists in the input table
if (stringColIdx < 0) {
throw new InvalidSettingsException("Selected column " + m_singleColumn.getStringValue() + " not in the input table");
}
// check that the data type is supported by the selected method
final DataType selectedDataType = spec.getColumnSpec(m_singleColumn.getStringValue()).getType();
if (!columnType.isCompatible(selectedDataType)) {
throw new InvalidSettingsException("Data type of column " + m_singleColumn.getStringValue() + " is not compatible with selected method");
}
// create the output spec
final ColumnRearranger c = createSingleColumnRearranger(inSpecs[0], stringColIdx, columnType, vectorType);
newSpec = c.createSpec();
}
return new DataTableSpec[] { newSpec };
}
use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.
the class CreateBitVectorNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
final BufferedDataTable data = inData[0];
final DataTableSpec spec = data.getDataTableSpec();
final ColumnType columnType = ColumnType.getType(m_columnType.getStringValue());
final BitVectorType vectorType = BitVectorType.getType(m_vectorType.getStringValue());
final String[] parsedColumnNames;
final BitVectorCellFactory factory;
if (columnType.isMultiColumn()) {
final FilterResult multiColFilter = m_multiColumnsConfig.applyTo(spec);
parsedColumnNames = multiColFilter.getIncludes();
factory = createMultiColumnCellFactory(data, exec, columnType, vectorType, parsedColumnNames);
} else {
final int colIdx = spec.findColumnIndex(m_singleColumn.getStringValue());
factory = getSingleColFactory(exec, colIdx, spec, data, columnType, vectorType);
parsedColumnNames = new String[] { m_singleColumn.getStringValue() };
}
final ColumnRearranger c = new ColumnRearranger(spec);
if (m_remove.getBooleanValue()) {
if (columnType.isMultiColumn()) {
c.remove(parsedColumnNames);
c.append(factory);
} else {
c.replace(factory, m_singleColumn.getStringValue());
}
} else {
c.append(factory);
}
factory.setFailOnError(m_failOnError.getBooleanValue());
final ExecutionMonitor subExec;
if (ColumnType.MULTI_NUMERICAL.equals(columnType) || (ColumnType.MULTI_NUMERICAL.equals(columnType) && StringType.ID.equals(StringType.getType(m_singleStringColumnType.getStringValue()))) || ColumnType.SINGLE_COLLECTION.equals(columnType)) {
subExec = exec.createSubProgress(0.5);
} else {
subExec = exec;
}
final BufferedDataTable out = exec.createColumnRearrangeTable(data, c, subExec);
if (!factory.wasSuccessful() && data.size() > 0) {
final String errorMessage = factory.getNoOfPrintedErrors() + " errors found. Last message: " + factory.getLastErrorMessage() + ". See log file for details on all errors.";
setWarningMessage(errorMessage);
}
m_nrOfProcessedRows = factory.getNrOfProcessedRows();
m_totalNrOf0s = factory.getNumberOfNotSetBits();
m_totalNrOf1s = factory.getNumberOfSetBits();
return new BufferedDataTable[] { out };
}
Aggregations