Search in sources :

Example 41 with PMMLPortObject

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

the class BinnerNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inPorts, final ExecutionContext exec) throws Exception {
    BufferedDataTable inData = (BufferedDataTable) inPorts[DATA_INPORT];
    DataTableSpec spec = inData.getDataTableSpec();
    ColumnRearranger colReg = createColumnRearranger(spec);
    BufferedDataTable buf = exec.createColumnRearrangeTable(inData, colReg, exec);
    if (!m_pmmlOutEnabled) {
        return new PortObject[] { buf };
    }
    // handle the optional PMML in port (can be null)
    PMMLPortObject inPMMLPort = m_pmmlInEnabled ? (PMMLPortObject) inPorts[1] : null;
    PMMLPortObject outPMMLPort = createPMMLModel(inPMMLPort, spec, buf.getDataTableSpec());
    return new PortObject[] { buf, outPMMLPort };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) 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)

Example 42 with PMMLPortObject

use of org.knime.core.node.port.pmml.PMMLPortObject 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 43 with PMMLPortObject

use of org.knime.core.node.port.pmml.PMMLPortObject 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 44 with PMMLPortObject

use of org.knime.core.node.port.pmml.PMMLPortObject 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 45 with PMMLPortObject

use of org.knime.core.node.port.pmml.PMMLPortObject 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

PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)90 BufferedDataTable (org.knime.core.node.BufferedDataTable)53 DataTableSpec (org.knime.core.data.DataTableSpec)50 PortObject (org.knime.core.node.port.PortObject)47 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)35 PMMLPortObjectSpec (org.knime.core.node.port.pmml.PMMLPortObjectSpec)25 PMMLPortObjectSpecCreator (org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)21 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)18 ExecutionContext (org.knime.core.node.ExecutionContext)13 DataColumnSpec (org.knime.core.data.DataColumnSpec)12 DataRow (org.knime.core.data.DataRow)12 DerivedFieldMapper (org.knime.core.node.port.pmml.preproc.DerivedFieldMapper)11 StreamableOperator (org.knime.core.node.streamable.StreamableOperator)11 Node (org.w3c.dom.Node)10 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)9 IOException (java.io.IOException)8 DataCell (org.knime.core.data.DataCell)8 PMMLDocument (org.dmg.pmml.PMMLDocument)7 PMMLGeneralRegressionTranslator (org.knime.base.node.mine.regression.pmmlgreg.PMMLGeneralRegressionTranslator)7 StreamableFunction (org.knime.core.node.streamable.StreamableFunction)7