Search in sources :

Example 1 with MissingCellReplacingDataTable

use of org.knime.base.node.preproc.pmml.missingval.MissingCellReplacingDataTable 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 2 with MissingCellReplacingDataTable

use of org.knime.base.node.preproc.pmml.missingval.MissingCellReplacingDataTable in project knime-core by knime.

the class MissingValueHandlerNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    m_settings.configure((DataTableSpec) inSpecs[0]);
    MissingCellReplacingDataTable mvTable = new MissingCellReplacingDataTable((DataTableSpec) inSpecs[0], m_settings);
    PMMLPortObjectSpecCreator pmmlC = new PMMLPortObjectSpecCreator((DataTableSpec) inSpecs[0]);
    return new PortObjectSpec[] { mvTable.getDataTableSpec(), pmmlC.createSpec() };
}
Also used : MissingCellReplacingDataTable(org.knime.base.node.preproc.pmml.missingval.MissingCellReplacingDataTable) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 3 with MissingCellReplacingDataTable

use of org.knime.base.node.preproc.pmml.missingval.MissingCellReplacingDataTable in project knime-core by knime.

the class MissingValueApplyNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    BufferedDataTable inTable = (BufferedDataTable) inData[DATA_PORT_IDX];
    DataTableSpec inSpec = inTable.getDataTableSpec();
    PMMLPortObject pmmlIn = (PMMLPortObject) inData[PMML_PORT_IDX];
    MissingCellReplacingDataTable mvTable;
    try (LockedSupplier<Document> supplier = pmmlIn.getPMMLValue().getDocumentSupplier()) {
        mvTable = new MissingCellReplacingDataTable(inSpec, PMMLDocument.Factory.parse(supplier.get()));
    }
    // Calculate the statistics
    mvTable.init(inTable, exec.createSubExecutionContext(0.5));
    long rowCounter = 0;
    final long numOfRows = inTable.size();
    DataContainer container = exec.createDataContainer(mvTable.getDataTableSpec());
    for (DataRow row : mvTable) {
        exec.checkCanceled();
        if (row != null) {
            exec.setProgress(++rowCounter / (double) numOfRows, "Processed row " + rowCounter + "/" + numOfRows + " (\"" + row.getKey() + "\")");
            container.addRowToTable(row);
        } else {
            exec.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);
    }
    return new PortObject[] { (BufferedDataTable) container.getTable() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataContainer(org.knime.core.data.container.DataContainer) MissingCellReplacingDataTable(org.knime.base.node.preproc.pmml.missingval.MissingCellReplacingDataTable) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) BufferedDataTable(org.knime.core.node.BufferedDataTable) PMMLDocument(org.dmg.pmml.PMMLDocument) Document(org.w3c.dom.Document) DataRow(org.knime.core.data.DataRow) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PortObject(org.knime.core.node.port.PortObject)

Aggregations

MissingCellReplacingDataTable (org.knime.base.node.preproc.pmml.missingval.MissingCellReplacingDataTable)3 DataRow (org.knime.core.data.DataRow)2 DataTableSpec (org.knime.core.data.DataTableSpec)2 DataContainer (org.knime.core.data.container.DataContainer)2 BufferedDataTable (org.knime.core.node.BufferedDataTable)2 PortObject (org.knime.core.node.port.PortObject)2 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)2 PMMLPortObjectSpecCreator (org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)2 PMMLDocument (org.dmg.pmml.PMMLDocument)1 ExecutionContext (org.knime.core.node.ExecutionContext)1 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)1 Document (org.w3c.dom.Document)1