Search in sources :

Example 51 with PortObject

use of org.knime.core.node.port.PortObject in project knime-core by knime.

the class PCAApplyNodeModel method execute.

/**
 * Performs the PCA.
 *
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    final PCAModelPortObject model = (PCAModelPortObject) inData[MODEL_INPORT];
    final int dimensions = m_dimSelection.getNeededDimensions();
    if (dimensions == -1) {
        throw new IllegalArgumentException("Number of dimensions not correct configured");
    }
    if (m_failOnMissingValues.getBooleanValue()) {
        for (final DataRow row : (DataTable) inData[DATA_INPORT]) {
            for (int i = 0; i < m_inputColumnIndices.length; i++) {
                if (row.getCell(m_inputColumnIndices[i]).isMissing()) {
                    throw new IllegalArgumentException("data table contains missing values");
                }
            }
        }
    }
    final Matrix eigenvectors = EigenValue.getSortedEigenVectors(model.getEigenVectors(), model.getEigenvalues(), dimensions);
    final DataColumnSpec[] specs = PCANodeModel.createAddTableSpec((DataTableSpec) inData[DATA_INPORT].getSpec(), dimensions);
    final int dim = dimensions;
    final CellFactory fac = new CellFactory() {

        @Override
        public DataCell[] getCells(final DataRow row) {
            return PCANodeModel.convertInputRow(eigenvectors, row, model.getCenter(), m_inputColumnIndices, dim, m_failOnMissingValues.getBooleanValue());
        }

        @Override
        public DataColumnSpec[] getColumnSpecs() {
            return specs;
        }

        @Override
        public void setProgress(final int curRowNr, final int rowCount, final RowKey lastKey, final ExecutionMonitor texec) {
            texec.setProgress((double) curRowNr / rowCount, "converting input row " + curRowNr + " of " + rowCount);
        }
    };
    final ColumnRearranger cr = new ColumnRearranger((DataTableSpec) inData[DATA_INPORT].getSpec());
    cr.append(fac);
    if (m_removeOriginalCols.getBooleanValue()) {
        cr.remove(m_inputColumnNames);
    }
    final BufferedDataTable result = exec.createColumnRearrangeTable((BufferedDataTable) inData[DATA_INPORT], cr, exec);
    final PortObject[] out = { result };
    return out;
}
Also used : DataTable(org.knime.core.data.DataTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) RowKey(org.knime.core.data.RowKey) DataRow(org.knime.core.data.DataRow) Matrix(Jama.Matrix) DataColumnSpec(org.knime.core.data.DataColumnSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCell(org.knime.core.data.DataCell) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) CellFactory(org.knime.core.data.container.CellFactory) PortObject(org.knime.core.node.port.PortObject)

Example 52 with PortObject

use of org.knime.core.node.port.PortObject in project knime-core by knime.

the class PMMLKNNNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inPorts, final ExecutionContext exec) throws Exception {
    BufferedDataTable inTable = (BufferedDataTable) inPorts[0];
    if (m_limitRows.getBooleanValue() && inTable.size() > m_maxNumRows.getIntValue()) {
        setWarningMessage("The number of records in the table (" + inTable.size() + ") exceeds the maximum record number of " + m_maxNumRows.getIntValue());
    }
    PMMLPortObject outPort = new PMMLPortObject(createSpec(inTable.getDataTableSpec()));
    // -1 means that rows are not limited at all
    int maxRows = -1;
    if (m_limitRows.getBooleanValue()) {
        maxRows = m_maxNumRows.getIntValue();
    }
    String[] includes = m_learningColumns.applyTo(inTable.getDataTableSpec()).getIncludes();
    if (includes.length == 0) {
        throw new InvalidSettingsException("No learning columns are selected.");
    }
    outPort.addModelTranslater(new PMMLKNNTranslator(inTable, maxRows, m_numNeighbors.getIntValue(), includes));
    return new PortObject[] { outPort };
}
Also used : PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) BufferedDataTable(org.knime.core.node.BufferedDataTable) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PortObject(org.knime.core.node.port.PortObject)

Example 53 with PortObject

use of org.knime.core.node.port.PortObject in project knime-core by knime.

the class CategoryToNumberNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    BufferedDataTable inData = (BufferedDataTable) inObjects[0];
    DataTableSpec inSpec = (DataTableSpec) inObjects[0].getSpec();
    ColumnRearranger rearranger = createRearranger(inSpec);
    BufferedDataTable outTable = exec.createColumnRearrangeTable(inData, rearranger, exec);
    // the optional PMML in port (can be null)
    PMMLPortObject inPMMLPort = m_pmmlInEnabled ? (PMMLPortObject) inObjects[1] : null;
    PMMLPortObjectSpecCreator creator = new PMMLPortObjectSpecCreator(inPMMLPort, rearranger.createSpec());
    PMMLPortObject outPMMLPort = new PMMLPortObject(creator.createSpec(), inPMMLPort);
    for (CategoryToNumberCellFactory factory : m_factories) {
        PMMLMapValuesTranslator trans = new PMMLMapValuesTranslator(factory.getConfig(), new DerivedFieldMapper(inPMMLPort));
        outPMMLPort.addGlobalTransformations(trans.exportToTransDict());
    }
    return new PortObject[] { outTable, outPMMLPort };
}
Also used : DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) BufferedDataTable(org.knime.core.node.BufferedDataTable) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PortObject(org.knime.core.node.port.PortObject) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 54 with PortObject

use of org.knime.core.node.port.PortObject in project knime-core by knime.

the class CategoryToNumberApplyNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    PMMLPortObject model = (PMMLPortObject) inData[0];
    BufferedDataTable table = (BufferedDataTable) inData[1];
    ColumnRearranger rearranger = createRearranger(table.getDataTableSpec(), model);
    if (null == rearranger) {
        throw new IllegalArgumentException("No map values configuration found.");
    }
    BufferedDataTable outTable = exec.createColumnRearrangeTable(table, rearranger, exec);
    return new PortObject[] { model, outTable };
}
Also used : ColumnRearranger(org.knime.core.data.container.ColumnRearranger) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) BufferedDataTable(org.knime.core.node.BufferedDataTable) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PortObject(org.knime.core.node.port.PortObject)

Example 55 with PortObject

use of org.knime.core.node.port.PortObject in project knime-core by knime.

the class NumberToCategoryApplyNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    PMMLPortObject model = (PMMLPortObject) inData[0];
    BufferedDataTable table = (BufferedDataTable) inData[1];
    ColumnRearranger rearranger = createRearranger(table.getDataTableSpec(), model);
    if (null == rearranger) {
        throw new IllegalArgumentException("No map values configuration found.");
    }
    BufferedDataTable outTable = exec.createColumnRearrangeTable(table, rearranger, exec);
    return new PortObject[] { model, outTable };
}
Also used : ColumnRearranger(org.knime.core.data.container.ColumnRearranger) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) BufferedDataTable(org.knime.core.node.BufferedDataTable) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PortObject(org.knime.core.node.port.PortObject)

Aggregations

PortObject (org.knime.core.node.port.PortObject)173 BufferedDataTable (org.knime.core.node.BufferedDataTable)97 DataTableSpec (org.knime.core.data.DataTableSpec)68 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)59 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)39 InactiveBranchPortObject (org.knime.core.node.port.inactive.InactiveBranchPortObject)37 FlowVariablePortObject (org.knime.core.node.port.flowvariable.FlowVariablePortObject)35 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)34 IOException (java.io.IOException)33 DataRow (org.knime.core.data.DataRow)25 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)24 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)23 DataCell (org.knime.core.data.DataCell)20 FileStorePortObject (org.knime.core.data.filestore.FileStorePortObject)19 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)19 DatabasePortObject (org.knime.core.node.port.database.DatabasePortObject)18 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)16 ExecutionContext (org.knime.core.node.ExecutionContext)15 DataColumnSpec (org.knime.core.data.DataColumnSpec)14 InactiveBranchPortObjectSpec (org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec)13