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 };
}
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 };
}
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 };
}
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 };
}
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[] {};
}
Aggregations