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