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 };
}
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() };
}
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() };
}
Aggregations