Search in sources :

Example 1 with PortObject

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

the class RuleEngine2PortsNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    BufferedDataTable data = (BufferedDataTable) inData[DATA_PORT];
    m_rowCount = data.size();
    try {
        Pair<ColumnRearranger, PortObject> rearrangerPair = createColumnRearranger((DataTableSpec) inData[DATA_PORT].getSpec(), new DataTableRowInput((DataTable) inData[RULE_PORT]));
        BufferedDataTable predictedTable = exec.createColumnRearrangeTable(data, rearrangerPair.getFirst(), exec);
        PortObject second = rearrangerPair.getSecond();
        if (m_settings.isPMMLRuleSet()) {
            if (m_settings.isProvideStatistics()) {
                PMMLPortObject po = (PMMLPortObject) rearrangerPair.getSecond();
                PMMLPortObject pmmlPortObject = new PMMLPortObject(m_copy.getSpec(), po);
                // Remove extra model.
                pmmlPortObject.addModelTranslater(new PMMLTranslator() {

                    @Override
                    public void initializeFrom(final PMMLDocument pmmlDoc) {
                    }

                    @Override
                    public SchemaType exportTo(final PMMLDocument pmmlDoc, final PMMLPortObjectSpec spec) {
                        return null;
                    }
                });
                second = pmmlPortObject;
            } else {
                second = m_copy;
            }
        }
        return new PortObject[] { predictedTable, second };
    } finally {
        m_rowCount = -1;
    }
}
Also used : BufferedDataTable(org.knime.core.node.BufferedDataTable) DataTable(org.knime.core.data.DataTable) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) PMMLDocument(org.dmg.pmml.PMMLDocument) PMMLTranslator(org.knime.core.node.port.pmml.PMMLTranslator) PortObject(org.knime.core.node.port.PortObject) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) InactiveBranchPortObject(org.knime.core.node.port.inactive.InactiveBranchPortObject) SchemaType(org.apache.xmlbeans.SchemaType)

Example 2 with PortObject

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

the class RuleEngine2PortsNodeModel method createStreamableOperator.

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

        private StreamInternalWithPortObject m_internals;

        /**
         * {@inheritDoc}
         */
        @Override
        public void loadInternals(final StreamableOperatorInternals internals) {
            m_internals = (StreamInternalWithPortObject) internals;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void runIntermediate(final PortInput[] inputs, final ExecutionContext exec) throws Exception {
            // count number of rows
            long count = 0;
            final RowInput rowInput = (RowInput) inputs[DATA_PORT];
            while (rowInput.poll() != null) {
                count++;
            }
            if (inputs[RULE_PORT] instanceof RowInput) {
                final RowInput ruleInput = (RowInput) inputs[RULE_PORT];
                final Pair<ColumnRearranger, PortObject> pair = createColumnRearranger(rowInput.getDataTableSpec(), ruleInput);
                final ColumnRearranger rearranger = pair.getFirst();
                final DataTableSpec spec = rearranger.createSpec();
                m_internals.setTableSpec(spec);
                if (pair.getSecond() instanceof PMMLPortObject) {
                    PMMLPortObject po = (PMMLPortObject) pair.getSecond();
                    m_internals.setObject(po);
                } else {
                    m_internals.setObject(null);
                }
            }
            m_internals.setRowCount(count);
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public StreamableOperatorInternals saveInternals() {
            return m_internals;
        }

        @Override
        public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
            if (m_internals.getTableSpec() != null) {
                m_rowCount = m_internals.getRowCount();
            }
            final Pair<ColumnRearranger, PortObject> pair = createColumnRearranger((DataTableSpec) inSpecs[DATA_PORT], (RowInput) inputs[RULE_PORT]);
            pair.getFirst().createStreamableFunction(0, 0).runFinal(inputs, outputs, exec);
            if (pair.getSecond() != null) {
                ((PortObjectOutput) outputs[1]).setPortObject(pair.getSecond());
            }
        }
    };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) 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) StreamableOperatorInternals(org.knime.core.node.streamable.StreamableOperatorInternals) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) RowInput(org.knime.core.node.streamable.RowInput) PortObject(org.knime.core.node.port.PortObject) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) InactiveBranchPortObject(org.knime.core.node.port.inactive.InactiveBranchPortObject) PortObjectOutput(org.knime.core.node.streamable.PortObjectOutput)

Example 3 with PortObject

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

the class RuleEngine2PortsSimpleNodeDialog method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObject[] input) throws NotConfigurableException {
    PortObject inputPort = input[RuleEngine2PortsNodeModel.DATA_PORT];
    BufferedDataTable data = inputPort instanceof BufferedDataTable ? (BufferedDataTable) inputPort : null;
    BufferedDataTable rules = (BufferedDataTable) input[RuleEngine2PortsNodeModel.RULE_PORT];
    loadSettingsFrom(settings, new PortObjectSpec[] { data == null ? null : data.getDataTableSpec(), rules == null ? null : rules.getDataTableSpec() });
    setRules(rules);
    updateErrorsAndWarnings();
}
Also used : BufferedDataTable(org.knime.core.node.BufferedDataTable) PortObject(org.knime.core.node.port.PortObject)

Example 4 with PortObject

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

the class NodeMonitorView method updateDataTable.

/*
     *  Put (static and simple) content of one output port table into table.
     */
private void updateDataTable(final NodeContainer nc, final int port) {
    assert Display.getCurrent().getThread() == Thread.currentThread();
    m_info.setText("Port Output");
    m_table.removeAll();
    for (TableColumn tc : m_table.getColumns()) {
        tc.dispose();
    }
    // check if we can display something at all:
    int index = port;
    if (nc instanceof SingleNodeContainer) {
        // we don't care about (hidden) variable OutPort
        index++;
    }
    if (nc.getNrOutPorts() <= index) {
        // no (real) port available
        TableItem item = new TableItem(m_table, SWT.NONE);
        item.setText(0, "No output ports");
        return;
    }
    NodeOutPort nop = nc.getOutPort(index);
    PortObject po = nop.getPortObject();
    if ((po == null) || !(po instanceof BufferedDataTable)) {
        // no table in port - ignore.
        TableItem item = new TableItem(m_table, SWT.NONE);
        item.setText(0, "Unknown or no PortObject");
        return;
    }
    // retrieve table
    BufferedDataTable bdt = (BufferedDataTable) po;
    TableColumn column = new TableColumn(m_table, SWT.NONE);
    column.setText("ID");
    for (int i = 0; i < bdt.getDataTableSpec().getNumColumns(); i++) {
        column = new TableColumn(m_table, SWT.NONE);
        column.setText(bdt.getDataTableSpec().getColumnSpec(i).getName());
    }
    int rowIndex = 0;
    Iterator<DataRow> rowIt = bdt.iteratorFailProve();
    while (rowIndex < 42 && rowIt.hasNext()) {
        DataRow thisRow = rowIt.next();
        TableItem item = new TableItem(m_table, SWT.NONE);
        item.setText(0, thisRow.getKey().getString());
        for (int i = 0; i < thisRow.getNumCells(); i++) {
            DataCell c = thisRow.getCell(i);
            String s = c.toString().replaceAll("\\p{Cntrl}", "_");
            item.setText(i + 1, s);
        }
        rowIndex++;
    }
    for (int i = 0; i < m_table.getColumnCount(); i++) {
        m_table.getColumn(i).pack();
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) BufferedDataTable(org.knime.core.node.BufferedDataTable) NodeOutPort(org.knime.core.node.workflow.NodeOutPort) DataCell(org.knime.core.data.DataCell) TableColumn(org.eclipse.swt.widgets.TableColumn) PortObject(org.knime.core.node.port.PortObject) DataRow(org.knime.core.data.DataRow) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer)

Example 5 with PortObject

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

the class NodeOutputView method updateDataTable.

/*
     *  Put (static and simple) content of one output port table into table.
     */
private void updateDataTable(final NodeContainer nc, final int port) {
    assert Display.getCurrent().getThread() == Thread.currentThread();
    // display data table
    ((StackLayout) m_stackPanel.getLayout()).topControl = m_tableViewPanel;
    m_stackPanel.layout();
    m_info.setText("Port Output");
    m_tableView.setDataTable(null);
    // check if we can display something at all:
    int index = port;
    if (nc instanceof SingleNodeContainer) {
        // we don't care about (hidden) variable OutPort
        index++;
    }
    if (nc.getNrOutPorts() <= index) {
        // no (real) port available
        m_errorLabel.setText("No output ports");
        ((StackLayout) m_stackPanel.getLayout()).topControl = m_errorLabel;
        m_stackPanel.layout();
        return;
    }
    NodeOutPort nop = nc.getOutPort(index);
    PortObject po = nop.getPortObject();
    if ((po == null) || !(po instanceof BufferedDataTable)) {
        // no table in port - ignore.
        m_errorLabel.setText("Unknown or no PortObject");
        ((StackLayout) m_stackPanel.getLayout()).topControl = m_errorLabel;
        m_stackPanel.layout();
        return;
    }
    // retrieve table
    m_tableView.setDataTable((DataTable) po);
    m_tableView.repaint();
}
Also used : BufferedDataTable(org.knime.core.node.BufferedDataTable) NodeOutPort(org.knime.core.node.workflow.NodeOutPort) PortObject(org.knime.core.node.port.PortObject) Point(org.eclipse.swt.graphics.Point) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer)

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