Search in sources :

Example 21 with PortObject

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

the class LogRegLearnerNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    final BufferedDataTable data = (BufferedDataTable) inObjects[0];
    DataTableSpec tableSpec = data.getDataTableSpec();
    // handle the optional PMML input
    PMMLPortObject inPMMLPort = m_pmmlInEnabled ? (PMMLPortObject) inObjects[1] : null;
    PMMLPortObjectSpec inPMMLSpec = null;
    if (inPMMLPort != null) {
        inPMMLSpec = inPMMLPort.getSpec();
    } else {
        PMMLPortObjectSpecCreator creator = new PMMLPortObjectSpecCreator(tableSpec);
        inPMMLSpec = creator.createSpec();
        inPMMLPort = new PMMLPortObject(inPMMLSpec);
    }
    LogRegLearner learner = new LogRegLearner(new PortObjectSpec[] { tableSpec, inPMMLSpec }, m_pmmlInEnabled, m_settings);
    m_content = learner.execute(new PortObject[] { data, inPMMLPort }, exec);
    String warn = learner.getWarningMessage();
    if (warn != null) {
        setWarningMessage(warn);
    }
    // third argument is ignored since we provide a port
    PMMLPortObject outPMMLPort = new PMMLPortObject((PMMLPortObjectSpec) learner.getOutputSpec()[0], inPMMLPort, null);
    PMMLGeneralRegressionTranslator trans = new PMMLGeneralRegressionTranslator(m_content.createGeneralRegressionContent());
    outPMMLPort.addModelTranslater(trans);
    return new PortObject[] { outPMMLPort, m_content.createTablePortObject(exec) };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PMMLGeneralRegressionTranslator(org.knime.base.node.mine.regression.pmmlgreg.PMMLGeneralRegressionTranslator) 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 22 with PortObject

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

the class Node method getDialogPaneWithSettings.

/**
 * @param inSpecs The input specs, which will be forwarded to the dialog's
 *        {@link NodeDialogPane#loadSettingsFrom(NodeSettingsRO,
 *        PortObjectSpec[])}.
 * @param settings The current settings of this node. The settings object
 *        will also contain the settings of the outer SNC.
 * @param isWriteProtected Whether write protected, see
 *        {@link org.knime.core.node.workflow.WorkflowManager#isWriteProtected()}.
 * @return The dialog pane which holds all the settings' components. In
 *         addition this method loads the settings from the model into the
 *         dialog pane.
 * @throws NotConfigurableException if the dialog cannot be opened because
 *             of real invalid settings or if any preconditions are not
 *             fulfilled, e.g. no predecessor node, no nominal column in
 *             input table, etc.
 * @throws IllegalStateException If node has no dialog.
 * @see #hasDialog()
 * @since 2.6
 */
public NodeDialogPane getDialogPaneWithSettings(final PortObjectSpec[] inSpecs, final PortObject[] inData, final NodeSettingsRO settings, final boolean isWriteProtected) throws NotConfigurableException {
    NodeDialogPane dialogPane = getDialogPane();
    PortObjectSpec[] corrInSpecs = new PortObjectSpec[inSpecs.length - 1];
    PortObject[] corrInData = new PortObject[inData.length - 1];
    for (int i = 1; i < inSpecs.length; i++) {
        if (inSpecs[i] instanceof InactiveBranchPortObjectSpec) {
            if (!isInactiveBranchConsumer()) {
                throw new NotConfigurableException("Cannot configure nodes in inactive branches.");
            }
        }
        PortType t = getInputType(i);
        if (!t.acceptsPortObjectSpec(inSpecs[i]) && !(inSpecs[i] instanceof InactiveBranchPortObjectSpec)) {
            // table(!) connection)
            throw new NotConfigurableException("Invalid incoming port object spec \"" + inSpecs[i].getClass().getSimpleName() + "\", expected \"" + t.getPortObjectSpecClass().getSimpleName() + "\"");
        } else if (inSpecs[i] == null && BufferedDataTable.TYPE.equals(t) && !t.isOptional()) {
            corrInSpecs[i - 1] = new DataTableSpec();
        } else {
            corrInSpecs[i - 1] = inSpecs[i];
            corrInData[i - 1] = inData[i];
        }
    }
    // the sub node virtual input node shows in its dialog all flow variables that are available to the rest
    // of the subnode. It's the only case where the flow variables shown in the dialog are not the ones available
    // to the node model class ...
    final FlowObjectStack flowObjectStack = m_model instanceof VirtualSubNodeInputNodeModel ? ((VirtualSubNodeInputNodeModel) m_model).getSubNodeContainerFlowObjectStack() : getFlowObjectStack();
    dialogPane.internalLoadSettingsFrom(settings, corrInSpecs, corrInData, flowObjectStack, getCredentialsProvider(), isWriteProtected);
    if (m_model instanceof ValueControlledNode && dialogPane instanceof ValueControlledDialogPane) {
        NodeSettings currentValue = new NodeSettings("currentValue");
        try {
            ((ValueControlledNode) m_model).saveCurrentValue(currentValue);
            ((ValueControlledDialogPane) dialogPane).loadCurrentValue(currentValue);
        } catch (Exception ise) {
            final String msg = "Could not load current value into dialog: " + ise.getMessage();
            if (ise instanceof InvalidSettingsException) {
                LOGGER.warn(msg, ise);
            } else {
                LOGGER.coding(msg, ise);
            }
        }
    }
    return dialogPane;
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) InactiveBranchPortObjectSpec(org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec) FlowObjectStack(org.knime.core.node.workflow.FlowObjectStack) IOException(java.io.IOException) DataContainerException(org.knime.core.data.container.DataContainerException) VirtualSubNodeInputNodeModel(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeModel) InactiveBranchPortObjectSpec(org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) FlowVariablePortObjectSpec(org.knime.core.node.port.flowvariable.FlowVariablePortObjectSpec) ValueControlledDialogPane(org.knime.core.node.dialog.ValueControlledDialogPane) ValueControlledNode(org.knime.core.node.dialog.ValueControlledNode) PortObject(org.knime.core.node.port.PortObject) FileStorePortObject(org.knime.core.data.filestore.FileStorePortObject) FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) InactiveBranchPortObject(org.knime.core.node.port.inactive.InactiveBranchPortObject) PortType(org.knime.core.node.port.PortType)

Example 23 with PortObject

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

the class Node method removeOutputTablesFromGlobalRepository.

/**
 * Reverse operation to
 * {@link #putOutputTablesIntoGlobalRepository(HashMap)}. It will remove
 * all output tables and its delegates from the global table repository.
 * @param rep The global table rep.
 * @return The number of tables effectively removed, used for assertions.
 */
public int removeOutputTablesFromGlobalRepository(final HashMap<Integer, ContainerTable> rep) {
    int result = 0;
    for (int i = 0; i < m_outputs.length; i++) {
        PortObject portObject = m_outputs[i].object;
        if (portObject instanceof BufferedDataTable) {
            BufferedDataTable t = (BufferedDataTable) portObject;
            result += t.removeFromTableRepository(rep, this);
        }
    }
    return result;
}
Also used : PortObject(org.knime.core.node.port.PortObject) FileStorePortObject(org.knime.core.data.filestore.FileStorePortObject) FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) InactiveBranchPortObject(org.knime.core.node.port.inactive.InactiveBranchPortObject)

Example 24 with PortObject

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

the class Node method cleanOutPorts.

/**
 * Sets output objects to null.
 * @param isLoopRestart If true, does not clear tables that are part
 * of the internally held tables (loop start nodes implements the
 * {@link BufferedDataTableHolder} interface). This can only be true
 * between two loop iterations.
 * @noreference This method is not intended to be referenced by clients.
 */
public void cleanOutPorts(final boolean isLoopRestart) {
    if (isLoopRestart) {
        // just as an assertion
        FlowObjectStack inStack = getFlowObjectStack();
        FlowLoopContext flc = inStack.peek(FlowLoopContext.class);
        if (flc != null && flc.isInactiveScope()) {
            LOGGER.coding("Encountered an inactive FlowLoopContext in a loop restart.");
            // continue with historically "correct" solution:
            flc = inStack.peekScopeContext(FlowLoopContext.class, false);
        }
        if (flc == null && !this.isModelCompatibleTo(LoopStartNode.class)) {
            LOGGER.coding("Encountered a loop restart action but there is" + " no loop context on the flow object stack (node " + getName() + ")");
        }
    }
    LOGGER.debug("clean output ports.");
    Set<BufferedDataTable> disposableTables = new LinkedHashSet<BufferedDataTable>();
    for (int i = 0; i < m_outputs.length; i++) {
        PortObject portObject = m_outputs[i].object;
        if (portObject instanceof BufferedDataTable) {
            final BufferedDataTable table = (BufferedDataTable) portObject;
            table.collectTableAndReferencesOwnedBy(this, disposableTables);
        }
        m_outputs[i].spec = null;
        m_outputs[i].object = null;
        m_outputs[i].summary = null;
    }
    if (m_internalHeldPortObjects != null) {
        Set<BufferedDataTable> internalTableSet = collectTableAndReferences(m_internalHeldPortObjects);
        // internal table reference that must not be cleared).
        if (isLoopRestart) {
            disposableTables.removeAll(internalTableSet);
        } else {
            disposableTables.addAll(internalTableSet);
            m_internalHeldPortObjects = null;
        }
    }
    for (BufferedDataTable disposable : disposableTables) {
        disposable.clearSingle(this);
    }
    // clear temporary tables that have been created during execute
    for (ContainerTable t : m_localTempTables) {
        t.clear();
    }
    m_localTempTables.clear();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) FlowObjectStack(org.knime.core.node.workflow.FlowObjectStack) FlowLoopContext(org.knime.core.node.workflow.FlowLoopContext) PortObject(org.knime.core.node.port.PortObject) FileStorePortObject(org.knime.core.data.filestore.FileStorePortObject) FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) InactiveBranchPortObject(org.knime.core.node.port.inactive.InactiveBranchPortObject) ContainerTable(org.knime.core.data.container.ContainerTable)

Example 25 with PortObject

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

the class PortObjectInNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    int id = m_portObjectIDSettings.getId();
    PortObject obj = PortObjectRepository.get(id);
    if (obj == null) {
        throw new RuntimeException("No port object for id " + id);
    }
    pushFlowVariables();
    PortObject cloneOrSelf = m_portObjectIDSettings.isCopyData() ? PortObjectRepository.copy(obj, exec, exec) : obj;
    return new PortObject[] { cloneOrSelf };
}
Also used : PortObject(org.knime.core.node.port.PortObject)

Aggregations

PortObject (org.knime.core.node.port.PortObject)207 BufferedDataTable (org.knime.core.node.BufferedDataTable)103 DataTableSpec (org.knime.core.data.DataTableSpec)69 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)63 InactiveBranchPortObject (org.knime.core.node.port.inactive.InactiveBranchPortObject)49 FlowVariablePortObject (org.knime.core.node.port.flowvariable.FlowVariablePortObject)47 IOException (java.io.IOException)44 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)43 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)39 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)29 File (java.io.File)27 FileStorePortObject (org.knime.core.data.filestore.FileStorePortObject)27 DataRow (org.knime.core.data.DataRow)26 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)25 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)23 DataCell (org.knime.core.data.DataCell)21 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)20 ArrayList (java.util.ArrayList)19 DatabasePortObject (org.knime.core.node.port.database.DatabasePortObject)18 ExecutionContext (org.knime.core.node.ExecutionContext)17