Search in sources :

Example 71 with ExecutionContext

use of org.knime.core.node.ExecutionContext in project knime-core by knime.

the class AutoHiLiteNodeFactory method createNodeModel.

/**
 * {@inheritDoc}
 */
@Override
public NodeModel createNodeModel() {
    return new NodeModel(1, 1) {

        private SettingsModelBoolean m_smClearHiLites = createClearHilitesModel();

        /**
         * {@inheritDoc}
         */
        @Override
        protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
            return inSpecs;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
            if (m_smClearHiLites.getBooleanValue()) {
                getInHiLiteHandler(0).fireClearHiLiteEvent();
            }
            final Set<RowKey> keys = new HashSet<RowKey>();
            final HiLiteHandler hlh = getInHiLiteHandler(0);
            long counter = 0;
            long numOfRows = inData[0].size();
            for (final DataRow row : inData[0]) {
                keys.add(row.getKey());
                if (keys.size() == NUMBER_OF_ROWS_HILITED_AT_ONCE) {
                    exec.setProgress(++counter * NUMBER_OF_ROWS_HILITED_AT_ONCE / (double) numOfRows, "HiLiting all rows...");
                    hlh.fireHiLiteEvent(keys);
                    keys.clear();
                }
            }
            hlh.fireHiLiteEvent(keys);
            // wait for hilite to propagate
            ViewUtils.invokeAndWaitInEDT(() -> {
            });
            return inData;
        }

        @Override
        protected void loadInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
        }

        @Override
        protected void saveInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
        }

        @Override
        protected void saveSettingsTo(final NodeSettingsWO settings) {
            m_smClearHiLites.saveSettingsTo(settings);
        }

        @Override
        protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
            m_smClearHiLites.validateSettings(settings);
        }

        @Override
        protected void loadValidatedSettingsFrom(final NodeSettingsRO settings) throws InvalidSettingsException {
            m_smClearHiLites.loadSettingsFrom(settings);
        }

        @Override
        protected void reset() {
        // no op
        }
    };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) HiLiteHandler(org.knime.core.node.property.hilite.HiLiteHandler) RowKey(org.knime.core.data.RowKey) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) DataRow(org.knime.core.data.DataRow) SettingsModelBoolean(org.knime.core.node.defaultnodesettings.SettingsModelBoolean) NodeModel(org.knime.core.node.NodeModel) ExecutionContext(org.knime.core.node.ExecutionContext) BufferedDataTable(org.knime.core.node.BufferedDataTable) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) File(java.io.File) HashSet(java.util.HashSet)

Example 72 with ExecutionContext

use of org.knime.core.node.ExecutionContext in project knime-core by knime.

the class SVMPredictorNodeModel method createStreamableOperator.

/**
 * {@inheritDoc}
 */
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    return new StreamableOperator() {

        @Override
        public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
            PMMLPortObject pmmlModel = (PMMLPortObject) ((PortObjectInput) inputs[0]).getPortObject();
            ColumnRearranger colre = createColumnRearranger(pmmlModel, (DataTableSpec) inSpecs[1]);
            StreamableFunction func = colre.createStreamableFunction(1, 0);
            func.runFinal(inputs, outputs, exec);
        }
    };
}
Also used : ExecutionContext(org.knime.core.node.ExecutionContext) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) StreamableFunction(org.knime.core.node.streamable.StreamableFunction)

Example 73 with ExecutionContext

use of org.knime.core.node.ExecutionContext in project knime-core by knime.

the class AddEmptyRowsNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    BufferedDataTable in = inData[0];
    long nrRowsToAdd;
    if (m_config.isAtLeastMode()) {
        if (in.getRowCount() < m_config.getRowCount()) {
            nrRowsToAdd = m_config.getRowCount() - in.getRowCount();
        } else {
            nrRowsToAdd = 0;
        }
    } else {
        nrRowsToAdd = m_config.getRowCount();
    }
    // do not copy data if there are enough rows
    if (nrRowsToAdd == 0) {
        return inData;
    }
    exec.setMessage("Creating append table");
    ExecutionContext createContext = exec.createSubExecutionContext(0.5);
    ExecutionContext checkContext = exec.createSubExecutionContext(0.5);
    BufferedDataTable appendTable = createNewRowsTable(in.getDataTableSpec(), nrRowsToAdd, createContext);
    exec.setMessage("Checking output");
    BufferedDataTable outTable = exec.createConcatenateTable(checkContext, in, appendTable);
    return new BufferedDataTable[] { outTable };
}
Also used : ExecutionContext(org.knime.core.node.ExecutionContext) BufferedDataTable(org.knime.core.node.BufferedDataTable)

Example 74 with ExecutionContext

use of org.knime.core.node.ExecutionContext in project knime-core by knime.

the class AppendedRowsNodeModel method createStreamableOperator.

/**
 * {@inheritDoc}
 */
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    return new StreamableOperator() {

        @Override
        public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
            List<RowInput> noNullList = new ArrayList<RowInput>();
            for (PortInput p : inputs) {
                if (p != null) {
                    noNullList.add((RowInput) p);
                }
            }
            RowInput[] rowInputs = noNullList.toArray(new RowInput[noNullList.size()]);
            run(rowInputs, (RowOutput) outputs[0], exec, -1);
        }
    };
}
Also used : ExecutionContext(org.knime.core.node.ExecutionContext) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) ArrayList(java.util.ArrayList) FilterColumnRowInput(org.knime.base.data.filter.column.FilterColumnRowInput) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) RowInput(org.knime.core.node.streamable.RowInput) AppendedRowsRowInput(org.knime.core.data.append.AppendedRowsRowInput) PortInput(org.knime.core.node.streamable.PortInput)

Example 75 with ExecutionContext

use of org.knime.core.node.ExecutionContext in project knime-core by knime.

the class PCANodeModel method execute.

/**
 * Performs the PCA.
 *
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    // remove all non-numeric columns from the input date
    // final DataTable filteredTable =
    // filterNonNumericalColumns(inData[DATA_INPORT]);
    final BufferedDataTable dataTable = (BufferedDataTable) inData[DATA_INPORT];
    if (dataTable.size() == 0) {
        throw new IllegalArgumentException("Input table is empty!");
    }
    if (dataTable.size() == 1) {
        throw new IllegalArgumentException("Input table has only one row!");
    }
    final double[] meanVector = getMeanVector(dataTable, m_inputColumnIndices, false, exec.createSubExecutionContext(0.2));
    final double[][] m = new double[m_inputColumnIndices.length][m_inputColumnIndices.length];
    final int missingValues = getCovarianceMatrix(exec.createSubExecutionContext(0.2), dataTable, m_inputColumnIndices, meanVector, m);
    final Matrix covarianceMatrix = new Matrix(m);
    if (missingValues > 0) {
        if (m_failOnMissingValues.getBooleanValue()) {
            throw new IllegalArgumentException("missing, infinite or impossible values in table");
        }
        setWarningMessage(missingValues + " rows ignored because of missing" + ", infinite or impossible values");
    }
    final ExecutionContext evdContext = exec.createSubExecutionContext(0.2);
    evdContext.setMessage("computing spectral decomposition");
    final EigenvalueDecomposition eig = covarianceMatrix.eig();
    exec.checkCanceled();
    evdContext.setProgress(0.8);
    final double[] evs = EigenValue.extractEVVector(eig);
    m_dimSelection.setEigenValues(evs);
    final int dimensions = m_dimSelection.getNeededDimensions();
    // don't remember these in case input changes
    m_dimSelection.setEigenValues(null);
    // adjust to selected numerical columns
    if (dimensions > m_inputColumnIndices.length || dimensions < 1) {
        throw new IllegalArgumentException("invalid number of dimensions to reduce to: " + dimensions);
    }
    exec.checkCanceled();
    evdContext.setProgress(0.9);
    final Matrix eigenvectors = EigenValue.getSortedEigenVectors(eig.getV().getArray(), evs, dimensions);
    exec.checkCanceled();
    evdContext.setProgress(1);
    exec.checkCanceled();
    final DataColumnSpec[] specs = createAddTableSpec((DataTableSpec) inData[DATA_INPORT].getSpec(), dimensions);
    final CellFactory fac = new CellFactory() {

        @Override
        public DataCell[] getCells(final DataRow row) {
            return convertInputRow(eigenvectors, row, meanVector, m_inputColumnIndices, dimensions, false);
        }

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

        @Override
        public void setProgress(final int curRowNr, final int rowCount, final RowKey lastKey, final ExecutionMonitor texec) {
            texec.setProgress(curRowNr / (double) rowCount, "processing " + curRowNr + " of " + rowCount);
        }
    };
    final ColumnRearranger cr = new ColumnRearranger((DataTableSpec) inData[0].getSpec());
    cr.append(fac);
    if (m_removeOriginalCols.getBooleanValue()) {
        cr.remove(m_inputColumnIndices);
    }
    final BufferedDataTable result = exec.createColumnRearrangeTable((BufferedDataTable) inData[0], cr, exec.createSubProgress(0.4));
    final PortObject[] out = new PortObject[1];
    out[DATA_OUTPORT] = result;
    // m_inputColumnNames);
    return out;
}
Also used : RowKey(org.knime.core.data.RowKey) EigenvalueDecomposition(Jama.EigenvalueDecomposition) DataRow(org.knime.core.data.DataRow) Matrix(Jama.Matrix) ExecutionContext(org.knime.core.node.ExecutionContext) 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)

Aggregations

ExecutionContext (org.knime.core.node.ExecutionContext)107 DataTableSpec (org.knime.core.data.DataTableSpec)61 StreamableOperator (org.knime.core.node.streamable.StreamableOperator)57 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)45 BufferedDataTable (org.knime.core.node.BufferedDataTable)44 DataRow (org.knime.core.data.DataRow)35 RowInput (org.knime.core.node.streamable.RowInput)26 RowOutput (org.knime.core.node.streamable.RowOutput)24 StreamableFunction (org.knime.core.node.streamable.StreamableFunction)23 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)20 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)20 DataColumnSpec (org.knime.core.data.DataColumnSpec)19 DataCell (org.knime.core.data.DataCell)18 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)15 NodeModel (org.knime.core.node.NodeModel)14 PortObject (org.knime.core.node.port.PortObject)14 RowKey (org.knime.core.data.RowKey)13 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)13 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)13 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)12