Search in sources :

Example 81 with PortObject

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

the class DBColumnRenameNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    final DatabasePortObject dbObject = (DatabasePortObject) inObjects[0];
    final DatabasePortObject outObject = new DatabasePortObject(createDBOutSpec(dbObject.getSpec()));
    return new PortObject[] { outObject };
}
Also used : DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) PortObject(org.knime.core.node.port.PortObject)

Example 82 with PortObject

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

the class BWElimFilterNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    BWElimModel model = (BWElimModel) inData[0];
    BufferedDataTable table = (BufferedDataTable) inData[1];
    ColumnRearranger crea = createRearranger(((DataTable) inData[1]).getDataTableSpec(), m_settings.includedColumns(model));
    return new PortObject[] { exec.createColumnRearrangeTable(table, crea, exec) };
}
Also used : ColumnRearranger(org.knime.core.data.container.ColumnRearranger) BufferedDataTable(org.knime.core.node.BufferedDataTable) PortObject(org.knime.core.node.port.PortObject)

Example 83 with PortObject

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

the class FeatureSelectionFilterNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    FeatureSelectionModel model = (FeatureSelectionModel) inData[0];
    BufferedDataTable table = (BufferedDataTable) inData[1];
    String warning = model.getTableSpecAndWarning(m_settings, table.getDataTableSpec()).getFirst();
    if (warning != null) {
        setWarningMessage(warning);
    }
    BufferedDataTable outTable = model.createTable(m_settings, table, exec);
    return new PortObject[] { outTable };
}
Also used : BufferedDataTable(org.knime.core.node.BufferedDataTable) PortObject(org.knime.core.node.port.PortObject)

Example 84 with PortObject

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

the class FeatureSelectionLoopEndNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    final FlowVariable scoreVariable = getAvailableInputFlowVariables().get(m_settings.getScoreVariableName());
    final double score = scoreVariable.getDoubleValue();
    if (m_resultTable == null) {
        m_resultTable = exec.createDataContainer(m_featureSelector.getSpecForResultTable());
        m_featureSelector.setResultTableContainer(m_resultTable);
    }
    m_featureSelector.addScore(score);
    m_iteration++;
    if (m_featureSelector.continueLoop()) {
        continueLoop();
        return null;
    }
    m_resultTable.close();
    return new PortObject[] { m_resultTable.getTable(), m_featureSelector.getFeatureSelectionModel() };
}
Also used : FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) PortObject(org.knime.core.node.port.PortObject) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 85 with PortObject

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

the class SleepNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    if (m_selection == 0) {
        // wait for
        exec.setMessage("Waiting for " + (m_waittime / 1000) + " seconds");
        waitFor(m_waittime);
    } else if (m_selection == 1) {
        // wait to
        Calendar c = Calendar.getInstance();
        c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DATE), m_toHours, m_toMin, m_toSec);
        if (c.getTimeInMillis() - System.currentTimeMillis() <= 0) {
            c.add(Calendar.DAY_OF_YEAR, 1);
        }
        exec.setMessage("Waiting until " + c.getTime());
        final long sleepTime = c.getTimeInMillis() - System.currentTimeMillis();
        waitFor(sleepTime);
    } else if (m_selection == 2) {
        WatchService w = FileSystems.getDefault().newWatchService();
        Path p = FileUtil.resolveToPath(FileUtil.toURL(m_filePath));
        if (p == null) {
            throw new IllegalArgumentException("File location '" + m_filePath + "' is not a local file.");
        }
        exec.setMessage("Waiting for file '" + p + "'");
        Path fileName = p.subpath(p.getNameCount() - 1, p.getNameCount());
        Path parent = p.getParent();
        Kind<Path> e = null;
        if (m_fileStatus.equals("Creation")) {
            e = StandardWatchEventKinds.ENTRY_CREATE;
        } else if (m_fileStatus.equals("Modification")) {
            e = StandardWatchEventKinds.ENTRY_MODIFY;
        } else if (m_fileStatus.equals("Deletion")) {
            e = StandardWatchEventKinds.ENTRY_DELETE;
        } else {
            throw new RuntimeException("Selected watchservice event is not available. Selected watchservice : " + m_fileStatus);
        }
        parent.register(w, e);
        boolean keepLooking = true;
        while (keepLooking) {
            // watch file until the event appears
            WatchKey key;
            // wait for a key to be available
            key = w.take();
            for (WatchEvent<?> event : key.pollEvents()) {
                if (fileName.equals(event.context())) {
                    keepLooking = false;
                }
            }
            // reset key
            boolean valid = key.reset();
            if (!valid) {
                break;
            }
        }
    }
    if (inData[0] == null) {
        return new PortObject[] { FlowVariablePortObject.INSTANCE };
    } else {
        return inData;
    }
}
Also used : Path(java.nio.file.Path) Calendar(java.util.Calendar) WatchKey(java.nio.file.WatchKey) WatchService(java.nio.file.WatchService) FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) 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