Search in sources :

Example 66 with PortObject

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

the class MissingValueHandlerNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    BufferedDataTable inTable = (BufferedDataTable) inData[0];
    DataTableSpec inSpec = inTable.getDataTableSpec();
    MissingCellReplacingDataTable mvTable = new MissingCellReplacingDataTable(inSpec, m_settings);
    // Calculate the statistics
    exec.setMessage("Calculating statistics");
    mvTable.init(inTable, exec.createSubExecutionContext(0.5));
    long rowCounter = 0;
    final long numOfRows = inTable.size();
    DataContainer container = exec.createDataContainer(mvTable.getDataTableSpec());
    ExecutionContext tableSubExec = exec.createSubExecutionContext(0.4);
    exec.setMessage("Replacing missing values");
    for (DataRow row : mvTable) {
        tableSubExec.checkCanceled();
        if (row != null) {
            tableSubExec.setProgress(++rowCounter / (double) numOfRows, "Processed row " + rowCounter + "/" + numOfRows + " (\"" + row.getKey() + "\")");
            container.addRowToTable(row);
        } else {
            tableSubExec.setProgress(++rowCounter / (double) numOfRows, "Processed row " + rowCounter + "/" + numOfRows);
        }
    }
    container.close();
    // Collect warning messages
    String warnings = mvTable.finish();
    // Handle the warnings
    if (warnings.length() > 0) {
        setWarningMessage(warnings);
    }
    exec.setMessage("Generating PMML");
    // Init PMML output port
    PMMLPortObject pmmlPort = new PMMLPortObject(new PMMLPortObjectSpecCreator(inSpec).createSpec());
    pmmlPort.addModelTranslater(mvTable.getPMMLTranslator());
    return new PortObject[] { (BufferedDataTable) container.getTable(), pmmlPort };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataContainer(org.knime.core.data.container.DataContainer) MissingCellReplacingDataTable(org.knime.base.node.preproc.pmml.missingval.MissingCellReplacingDataTable) ExecutionContext(org.knime.core.node.ExecutionContext) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataRow(org.knime.core.data.DataRow) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PortObject(org.knime.core.node.port.PortObject) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 67 with PortObject

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

the class NormalizerPMMLApplyNodeModel 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];
    PMMLNormalizeTranslator translator = new PMMLNormalizeTranslator();
    translator.initializeFrom(model.getDerivedFields());
    AffineTransConfiguration config = getAffineTrans(translator.getAffineTransConfig());
    if (config.getNames().length == 0) {
        throw new IllegalArgumentException("No normalization configuration " + "found.");
    }
    AffineTransTable t = new AffineTransTable(table, config);
    BufferedDataTable bdt = exec.createBufferedDataTable(t, exec);
    if (t.getErrorMessage() != null) {
        setWarningMessage(t.getErrorMessage());
    }
    return new PortObject[] { model, bdt };
}
Also used : PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) BufferedDataTable(org.knime.core.node.BufferedDataTable) AffineTransTable(org.knime.base.data.normalize.AffineTransTable) AffineTransConfiguration(org.knime.base.data.normalize.AffineTransConfiguration) PMMLNormalizeTranslator(org.knime.base.data.normalize.PMMLNormalizeTranslator) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PortObject(org.knime.core.node.port.PortObject)

Example 68 with PortObject

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

the class StringToNumberNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    StringBuilder warnings = new StringBuilder();
    BufferedDataTable inData = (BufferedDataTable) inObjects[0];
    DataTableSpec inSpec = inData.getDataTableSpec();
    // find indices to work on.
    List<String> inclcols = m_inclCols.getIncludeList();
    BufferedDataTable resultTable = null;
    if (inclcols.size() == 0) {
        // nothing to convert, let's return the input table.
        resultTable = inData;
        setWarningMessage("No columns selected," + " returning input DataTable.");
    } else {
        int[] indices = findColumnIndices(inSpec);
        ConverterFactory converterFac = new ConverterFactory(indices, inSpec, m_parseType);
        ColumnRearranger colre = new ColumnRearranger(inSpec);
        colre.replace(converterFac, indices);
        resultTable = exec.createColumnRearrangeTable(inData, colre, exec);
        String errorMessage = converterFac.getErrorMessage();
        if (errorMessage.length() > 0) {
            warnings.append("Problems occurred, see Console messages.\n");
        }
        if (warnings.length() > 0) {
            LOGGER.warn(errorMessage);
            setWarningMessage(warnings.toString());
        }
    }
    // the optional PMML in port (can be null)
    PMMLPortObject inPMMLPort = m_pmmlInEnabled ? (PMMLPortObject) inObjects[1] : null;
    PMMLStringConversionTranslator trans = new PMMLStringConversionTranslator(m_inclCols.getIncludeList(), m_parseType, new DerivedFieldMapper(inPMMLPort));
    PMMLPortObjectSpecCreator creator = new PMMLPortObjectSpecCreator(inPMMLPort, inSpec);
    PMMLPortObject outPMMLPort = new PMMLPortObject(creator.createSpec(), inPMMLPort, inSpec);
    outPMMLPort.addGlobalTransformations(trans.exportToTransDict());
    return new PortObject[] { resultTable, outPMMLPort };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) 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) PMMLStringConversionTranslator(org.knime.base.node.preproc.pmml.PMMLStringConversionTranslator) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 69 with PortObject

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

the class CorrelationComputeNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    final BufferedDataTable in = (BufferedDataTable) inData[0];
    final DataTableSpec inSpec = in.getDataTableSpec();
    ColumnRearranger filteredTableRearranger = new ColumnRearranger(inSpec);
    String[] includeNames = m_columnFilterModel.applyTo(inSpec).getIncludes();
    filteredTableRearranger.keepOnly(includeNames);
    final BufferedDataTable filteredTable = exec.createColumnRearrangeTable(in, filteredTableRearranger, exec.createSilentSubExecutionContext(0.0));
    final DataTableSpec filteredTableSpec = filteredTable.getDataTableSpec();
    double progStep1 = 0.48;
    double progStep2 = 0.48;
    double progFinish = 1.0 - progStep1 - progStep2;
    CorrelationComputer calculator = new CorrelationComputer(filteredTableSpec, m_maxPossValueCountModel.getIntValue());
    exec.setMessage("Calculating table statistics");
    ExecutionContext execStep1 = exec.createSubExecutionContext(progStep1);
    calculator.calculateStatistics(filteredTable, execStep1);
    execStep1.setProgress(1.0);
    exec.setMessage("Calculating correlation values");
    ExecutionMonitor execStep2 = exec.createSubExecutionContext(progStep2);
    HalfDoubleMatrix correlationMatrix = calculator.calculateOutput(filteredTable, execStep2);
    execStep2.setProgress(1.0);
    exec.setMessage("Assembling output");
    ExecutionContext execFinish = exec.createSubExecutionContext(progFinish);
    PMCCPortObjectAndSpec pmccModel = new PMCCPortObjectAndSpec(includeNames, correlationMatrix);
    BufferedDataTable out = pmccModel.createCorrelationMatrix(execFinish);
    m_correlationTable = out;
    String missValueString = calculator.getNumericMissingValueWarning(4);
    StringBuilder warning = null;
    if (missValueString != null) {
        LOGGER.debug(calculator.getNumericMissingValueWarning(1000));
        warning = new StringBuilder(missValueString);
    }
    String constantColString = calculator.getNumericConstantColumnPairs(4);
    if (constantColString != null) {
        LOGGER.debug(calculator.getNumericConstantColumnPairs(1000));
        if (warning == null) {
            warning = new StringBuilder(constantColString);
        } else {
            warning.append("\n");
            warning.append(constantColString);
        }
    }
    if (warning != null) {
        setWarningMessage(warning.toString());
    }
    return new PortObject[] { out, pmccModel };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) PMCCPortObjectAndSpec(org.knime.base.node.preproc.correlation.pmcc.PMCCPortObjectAndSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) ExecutionContext(org.knime.core.node.ExecutionContext) HalfDoubleMatrix(org.knime.base.util.HalfDoubleMatrix) BufferedDataTable(org.knime.core.node.BufferedDataTable) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) PortObject(org.knime.core.node.port.PortObject)

Example 70 with PortObject

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

the class PMMLWriterNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    CheckUtils.checkDestinationFile(m_outfile.getStringValue(), m_overwriteOK.getBooleanValue());
    URL url = FileUtil.toURL(m_outfile.getStringValue());
    Path localPath = FileUtil.resolveToPath(url);
    PMMLPortObject pmml = (PMMLPortObject) inData[0];
    if (m_validatePMML.getBooleanValue()) {
        pmml.validate();
    }
    try (OutputStream os = openOutputStream(localPath, url)) {
        pmml.save(os);
    }
    return new PortObject[] {};
}
Also used : Path(java.nio.file.Path) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) OutputStream(java.io.OutputStream) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PortObject(org.knime.core.node.port.PortObject) URL(java.net.URL)

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