Search in sources :

Example 41 with ColumnRearranger

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;
}
Also used : ColumnRearranger(org.knime.core.data.container.ColumnRearranger) ArrayList(java.util.ArrayList)

Example 42 with ColumnRearranger

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) };
}
Also used : ColumnRearranger(org.knime.core.data.container.ColumnRearranger) BufferedDataTable(org.knime.core.node.BufferedDataTable)

Example 43 with ColumnRearranger

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() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Example 44 with ColumnRearranger

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 };
}
Also used : ColumnRearranger(org.knime.core.data.container.ColumnRearranger) NaiveBayesPortObject(org.knime.base.node.mine.bayes.naivebayes.port.NaiveBayesPortObject) BufferedDataTable(org.knime.core.node.BufferedDataTable) NaiveBayesModel(org.knime.base.node.mine.bayes.naivebayes.datamodel.NaiveBayesModel) NaiveBayesPortObject(org.knime.base.node.mine.bayes.naivebayes.port.NaiveBayesPortObject) PortObject(org.knime.core.node.port.PortObject) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Example 45 with ColumnRearranger

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() };
}
Also used : PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Aggregations

ColumnRearranger (org.knime.core.data.container.ColumnRearranger)393 DataTableSpec (org.knime.core.data.DataTableSpec)221 BufferedDataTable (org.knime.core.node.BufferedDataTable)153 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)125 DataColumnSpec (org.knime.core.data.DataColumnSpec)116 DataRow (org.knime.core.data.DataRow)79 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)69 DataCell (org.knime.core.data.DataCell)63 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)55 SingleCellFactory (org.knime.core.data.container.SingleCellFactory)49 ExecutionContext (org.knime.core.node.ExecutionContext)46 PortObject (org.knime.core.node.port.PortObject)39 ArrayList (java.util.ArrayList)38 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)36 DataType (org.knime.core.data.DataType)34 StreamableOperator (org.knime.core.node.streamable.StreamableOperator)32 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)27 DoubleValue (org.knime.core.data.DoubleValue)26 SettingsModelFilterString (org.knime.core.node.defaultnodesettings.SettingsModelFilterString)26 TreeEnsembleModelPortObjectSpec (org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec)25