use of org.knime.core.node.port.pmml.preproc.DerivedFieldMapper in project knime-core by knime.
the class PMMLMissingValueReplacementTranslator method exportTo.
/**
* {@inheritDoc}
*/
@Override
public SchemaType exportTo(final PMMLDocument pmmlDoc, final PMMLPortObjectSpec spec) {
TransformationDictionary td = pmmlDoc.getPMML().getTransformationDictionary();
if (td == null) {
td = pmmlDoc.getPMML().addNewTransformationDictionary();
}
DerivedFieldMapper mapper = new DerivedFieldMapper(pmmlDoc);
for (MissingCellHandler handler : m_handlers) {
DerivedField f = handler.getPMMLDerivedField();
if (f != null) {
f.setDisplayName(f.getName());
f.setName(mapper.createDerivedFieldName(f.getName()));
td.getDerivedFieldList().add(f);
}
}
return null;
}
use of org.knime.core.node.port.pmml.preproc.DerivedFieldMapper 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.preproc.DerivedFieldMapper in project knime-core by knime.
the class DBNumericBinnerNodeModel method createPMMLPortObject.
private PMMLPortObject createPMMLPortObject(final DataTableSpec inDataTableSpec, final DataTableSpec outDataTableSpec) {
PMMLPortObjectSpec initPMMLSpec = new PMMLPortObjectSpecCreator(outDataTableSpec).createSpec();
PMMLPortObject initPMMLPortObject = new PMMLPortObject(initPMMLSpec, null, outDataTableSpec);
PMMLBinningTranslator pmmlBinningTranslator = new PMMLBinningTranslator(m_columnToBins, m_columnToAppended, new DerivedFieldMapper(initPMMLPortObject));
PMMLPortObject outPMMLPortObject = new PMMLPortObject(initPMMLSpec, initPMMLPortObject, inDataTableSpec);
outPMMLPortObject.addGlobalTransformations(pmmlBinningTranslator.exportToTransDict());
return outPMMLPortObject;
}
use of org.knime.core.node.port.pmml.preproc.DerivedFieldMapper in project knime-core by knime.
the class DBAutoBinner method translate.
/**
* This method translates a {@link PMMLPreprocDiscretize} object into {@link PMMLPortObject}.
*
* @param pmmlDiscretize {@link PMMLPreprocDiscretize} object
* @param dataTableSpec {@link DataTableSpec} if incoming {@link BufferedDataTable}
* @return a {@link PMMLPortObject} containing required parameters for binning operation
*/
public static PMMLPortObject translate(final PMMLPreprocDiscretize pmmlDiscretize, final DataTableSpec dataTableSpec) {
final Map<String, Bin[]> columnToBins = new HashMap<>();
final Map<String, String> columnToAppend = new HashMap<>();
List<String> replacedColumnNames = pmmlDiscretize.getConfiguration().getNames();
for (String replacedColumnName : replacedColumnNames) {
PMMLDiscretize discretize = pmmlDiscretize.getConfiguration().getDiscretize(replacedColumnName);
List<PMMLDiscretizeBin> bins = discretize.getBins();
String originalColumnName = discretize.getField();
if (replacedColumnName.equals(originalColumnName)) {
// wenn replaced, dann nicht anhängen
columnToAppend.put(originalColumnName, null);
} else {
// nicht replaced -> anhängen
columnToAppend.put(originalColumnName, replacedColumnName);
}
NumericBin[] numericBin = new NumericBin[bins.size()];
int counter = 0;
for (PMMLDiscretizeBin bin : bins) {
String binName = bin.getBinValue();
List<PMMLInterval> intervals = bin.getIntervals();
boolean leftOpen = false;
boolean rightOpen = false;
double leftMargin = 0;
double rightMargin = 0;
// always returns only one interval
for (PMMLInterval interval : intervals) {
Closure closure = interval.getClosure();
switch(closure) {
case openClosed:
leftOpen = true;
rightOpen = false;
break;
case openOpen:
leftOpen = true;
rightOpen = true;
break;
case closedOpen:
leftOpen = false;
rightOpen = true;
case closedClosed:
leftOpen = false;
rightOpen = false;
break;
default:
leftOpen = true;
rightOpen = false;
break;
}
leftMargin = interval.getLeftMargin();
rightMargin = interval.getRightMargin();
}
numericBin[counter] = new NumericBin(binName, leftOpen, leftMargin, rightOpen, rightMargin);
counter++;
}
columnToBins.put(originalColumnName, numericBin);
}
// ColumnRearranger createColReg = createColReg(dataTableSpec, columnToBins, columnToAppended);
DataTableSpec newDataTableSpec = createNewDataTableSpec(dataTableSpec, columnToAppend);
PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(newDataTableSpec);
PMMLPortObject pmmlPortObject = new PMMLPortObject(pmmlSpecCreator.createSpec(), null, newDataTableSpec);
PMMLBinningTranslator trans = new PMMLBinningTranslator(columnToBins, columnToAppend, new DerivedFieldMapper(pmmlPortObject));
TransformationDictionary exportToTransDict = trans.exportToTransDict();
pmmlPortObject.addGlobalTransformations(exportToTransDict);
return pmmlPortObject;
}
use of org.knime.core.node.port.pmml.preproc.DerivedFieldMapper in project knime-core by knime.
the class One2ManyColPMMLNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
BufferedDataTable inData = (BufferedDataTable) inObjects[0];
DataTableSpec dts = inData.getDataTableSpec();
checkColumnsSpecs(dts);
One2ManyCellFactory cellFactory = new One2ManyCellFactory(dts, m_includedColumns.getIncludeList(), m_appendOrgColName);
BufferedDataTable outData = exec.createColumnRearrangeTable(inData, createRearranger(dts, cellFactory), exec);
if (m_pmmlEnabled) {
// the optional PMML in port (can be null)
PMMLPortObject inPMMLPort = (PMMLPortObject) inObjects[1];
PMMLOne2ManyTranslator trans = new PMMLOne2ManyTranslator(cellFactory.getColumnMapping(), new DerivedFieldMapper(inPMMLPort));
PMMLPortObjectSpecCreator creator = new PMMLPortObjectSpecCreator(inPMMLPort, outData.getDataTableSpec());
PMMLPortObject outPMMLPort = new PMMLPortObject(creator.createSpec(), inPMMLPort);
outPMMLPort.addGlobalTransformations(trans.exportToTransDict());
return new PortObject[] { outData, outPMMLPort };
} else {
return new PortObject[] { outData };
}
}
Aggregations