use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class ColumnListLoopStartNodeModel method createRearranger.
private ColumnRearranger createRearranger(final DataTableSpec inSpec) {
String[] includedCols;
if (m_settings.iterateAllColumns()) {
includedCols = new String[] { inSpec.getColumnSpec(m_currentColIndex).getName() };
pushFlowVariableString("currentColumnName", inSpec.getColumnSpec(m_currentColIndex).getName());
} else {
List<String> temp = new ArrayList<String>();
for (String s : m_settings.alwaysIncludeColumns()) {
if (inSpec.containsName(s)) {
temp.add(s);
}
}
includedCols = new String[temp.size() + 1];
int i = 0;
for (String s : temp) {
includedCols[i++] = s;
}
includedCols[i] = m_settings.iterateOverColumns().get(m_currentColIndex);
pushFlowVariableString("currentColumnName", m_settings.iterateOverColumns().get(m_currentColIndex));
}
ColumnRearranger crea = new ColumnRearranger(inSpec);
crea.keepOnly(includedCols);
return crea;
}
use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class ColumnListLoopStartNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
ColumnRearranger crea = createRearranger(inData[0].getDataTableSpec());
m_currentColIndex++;
if (m_settings.iterateAllColumns()) {
m_lastIteration = m_currentColIndex >= inData[0].getDataTableSpec().getNumColumns();
} else {
m_lastIteration = m_currentColIndex >= m_settings.iterateOverColumns().size();
}
pushFlowVariableInt("currentIteration", m_iteration);
// increment counter for next iteration
m_iteration++;
return new BufferedDataTable[] { exec.createColumnRearrangeTable(inData[0], crea, exec) };
}
use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class ColumnListLoopStartNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
if ((m_settings.iterateOverColumns().size() < 1) && !m_settings.iterateAllColumns()) {
throw new InvalidSettingsException("No columns to iterate over selected");
}
if (!m_settings.iterateAllColumns()) {
for (String col : m_settings.iterateOverColumns()) {
if (!inSpecs[0].containsName(col)) {
throw new IllegalArgumentException("Column '" + col + "' does not exist in input table");
}
}
}
assert m_iteration == 0;
pushFlowVariableInt("currentIteration", m_iteration);
ColumnRearranger crea = createRearranger(inSpecs[0]);
return new DataTableSpec[] { crea.createSpec() };
}
use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class NaiveBayesPredictorNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
LOGGER.debug("Entering execute(inData, exec) of class " + "NaiveBayesPredictorNodeModel.");
// check input data
assert (inData != null && inData.length == 2 && inData[DATA_IN_PORT] != null && inData[MODEL_IN_PORT] != null);
final PortObject dataObject = inData[DATA_IN_PORT];
if (!(dataObject instanceof BufferedDataTable)) {
throw new IllegalArgumentException("Invalid input data");
}
final BufferedDataTable data = (BufferedDataTable) dataObject;
final PortObject modelObject = inData[MODEL_IN_PORT];
if (!(modelObject instanceof NaiveBayesPortObject)) {
throw new IllegalArgumentException("Invalid input data");
}
final NaiveBayesModel model = ((NaiveBayesPortObject) modelObject).getModel();
exec.setMessage("Classifying rows...");
if (model == null) {
throw new Exception("Node not properly configured. " + "No Naive Bayes Model available.");
}
final double laplaceCorrector = m_laplaceCorrector.getDoubleValue();
final NaiveBayesCellFactory appender = new NaiveBayesCellFactory(model, data.getDataTableSpec(), m_inclProbVals.getBooleanValue(), laplaceCorrector);
final ColumnRearranger rearranger = new ColumnRearranger(data.getDataTableSpec());
rearranger.append(appender);
final BufferedDataTable returnVal = exec.createColumnRearrangeTable(data, rearranger, exec);
LOGGER.debug("Exiting execute(inData, exec) of class " + "NaiveBayesPredictorNodeModel.");
return new PortObject[] { returnVal };
}
use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class MLPPredictorNodeModel method configure.
/**
* The additional columns are created based on the model which is loaded in
* the execute-method. Therefore, new DataTableSpecs are not available until
* execute has been called.
*
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
PMMLPortObjectSpec modelspec = (PMMLPortObjectSpec) inSpecs[0];
DataTableSpec testSpec = (DataTableSpec) inSpecs[1];
List<DataColumnSpec> targetCols = modelspec.getTargetCols();
if (targetCols.isEmpty()) {
throw new InvalidSettingsException("The PMML model" + " does not specify a target column for the prediction.");
}
DataColumnSpec targetCol = targetCols.iterator().next();
/*
* Check consistency between model and inputs, find columns to work on.
*/
for (String incol : modelspec.getLearningFields()) {
if (!testSpec.containsName(incol)) {
throw new InvalidSettingsException("Could not find " + incol + " in inputspec");
}
}
m_columns = getLearningColumnIndices(testSpec, modelspec);
MLPClassificationFactory mymlp;
// Regression
if (targetCol.getType().isCompatible(DoubleValue.class)) {
mymlp = new MLPClassificationFactory(true, m_columns, targetCol);
} else {
// Classification
mymlp = new MLPClassificationFactory(false, m_columns, targetCol);
}
ColumnRearranger colre = new ColumnRearranger(testSpec);
colre.append(mymlp);
return new DataTableSpec[] { colre.createSpec() };
}
Aggregations