use of org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator in project knime-core by knime.
the class BinnerNodeModel method configure.
/**
* Passes the input spec to the output.
*
* @param inSpecs The input spec.
* @return The generated output specs.
* @throws InvalidSettingsException If column to bin cannot be identified.
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec inDataSpec = (DataTableSpec) inSpecs[DATA_INPORT];
PMMLPortObjectSpec inModelSpec = m_pmmlInEnabled ? (PMMLPortObjectSpec) inSpecs[MODEL_INPORT] : null;
for (String columnKey : m_columnToBins.keySet()) {
assert m_columnToAppended.containsKey(columnKey) : columnKey;
if (!inDataSpec.containsName(columnKey)) {
throw new InvalidSettingsException("Binner: column \"" + columnKey + "\" not found in spec.");
}
if (!inDataSpec.getColumnSpec(columnKey).getType().isCompatible(DoubleValue.class)) {
throw new InvalidSettingsException("Binner: column \"" + columnKey + "\" not compatible with double-type.");
}
String appended = m_columnToAppended.get(columnKey);
if (appended != null) {
if (inDataSpec.containsName(appended)) {
throw new InvalidSettingsException("Binner: duplicate " + "appended column \"" + appended + "\" in spec.");
}
}
}
// set warning when no binning is defined
if (m_columnToBins.isEmpty()) {
super.setWarningMessage("No column select for binning.");
}
// generate numeric binned table spec
DataTableSpec outDataSpec = createColumnRearranger(inDataSpec).createSpec();
if (!m_pmmlOutEnabled) {
return new PortObjectSpec[] { outDataSpec };
}
PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(inModelSpec, outDataSpec);
return new PortObjectSpec[] { outDataSpec, pmmlSpecCreator.createSpec() };
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator in project knime-core by knime.
the class Many2OneCol2PMMLNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec inDataSpec = (DataTableSpec) inSpecs[0];
String[] includes = m_includedColumns.applyTo(inDataSpec).getIncludes();
if (includes.length <= 0) {
setWarningMessage("No column selected. Node will have no effect!");
}
// if it is not a reg exp it must be double compatible
if (!m_includeMethod.getStringValue().equals(IncludeMethod.RegExpPattern.name())) {
for (String colName : includes) {
if (!inDataSpec.getColumnSpec(colName).getType().isCompatible(DoubleValue.class)) {
throw new InvalidSettingsException("For selected include method '" + m_includeMethod.getStringValue() + "' only double compatible values are allowed." + " Column '" + colName + "' is not.");
}
}
}
ColumnRearranger rearranger = createRearranger(inDataSpec, getCellFactory(inDataSpec));
if (m_pmmlOutEnabled) {
PMMLPortObjectSpec pmmlSpec = m_pmmlInEnabled ? (PMMLPortObjectSpec) inSpecs[1] : null;
PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(pmmlSpec, inDataSpec);
return new PortObjectSpec[] { rearranger.createSpec(), pmmlSpecCreator.createSpec() };
} else {
return new DataTableSpec[] { rearranger.createSpec() };
}
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator 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.PMMLPortObjectSpecCreator 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.core.node.port.pmml.PMMLPortObjectSpecCreator in project knime-core by knime.
the class StringToNumberNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
// find indices to work on
DataTableSpec dts = (DataTableSpec) inSpecs[0];
int[] indices = findColumnIndices(dts);
ConverterFactory converterFac = new ConverterFactory(indices, dts, m_parseType);
ColumnRearranger colre = new ColumnRearranger(dts);
colre.replace(converterFac, indices);
DataTableSpec newspec = colre.createSpec();
// create the PMML spec based on the optional incoming PMML spec
PMMLPortObjectSpec pmmlSpec = m_pmmlInEnabled ? (PMMLPortObjectSpec) inSpecs[1] : null;
PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(pmmlSpec, dts);
return new PortObjectSpec[] { newspec, pmmlSpecCreator.createSpec() };
}
Aggregations