use of org.knime.base.node.preproc.columntrans2.AbstractMany2OneCellFactory in project knime-core by knime.
the class Many2OneCol2PMMLNodeModel method getCellFactory.
private AbstractMany2OneCellFactory getCellFactory(final DataTableSpec spec) {
AbstractMany2OneCellFactory cellFactory;
IncludeMethod method = IncludeMethod.valueOf(m_includeMethod.getStringValue());
FilterResult filterResult = m_includedColumns.applyTo(spec);
String[] includes = filterResult.getIncludes();
int[] includedColIndices = new int[includes.length];
int index = 0;
for (String colName : includes) {
includedColIndices[index++] = spec.findColumnIndex(colName);
}
String newColName = DataTableSpec.getUniqueColumnName(spec, m_appendedColumnName.getStringValue());
m_appendedColumnName.setStringValue(newColName);
if (method.equals(IncludeMethod.RegExpPattern)) {
cellFactory = new RegExpCellFactory(spec, newColName, includedColIndices, m_pattern.getStringValue());
} else if (method.equals(IncludeMethod.Minimum)) {
cellFactory = new MinMaxCellFactory(spec, newColName, includedColIndices, false);
} else if (method.equals(IncludeMethod.Binary)) {
cellFactory = new BinaryCellFactory(spec, newColName, includedColIndices);
} else {
cellFactory = new MinMaxCellFactory(spec, newColName, includedColIndices, true);
}
return cellFactory;
}
use of org.knime.base.node.preproc.columntrans2.AbstractMany2OneCellFactory in project knime-core by knime.
the class Many2OneCol2PMMLNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws CanceledExecutionException, Exception {
BufferedDataTable inData = (BufferedDataTable) inObjects[0];
AbstractMany2OneCellFactory cellFactory = getCellFactory(inData.getDataTableSpec());
BufferedDataTable outData = exec.createColumnRearrangeTable(inData, createRearranger(inData.getDataTableSpec(), cellFactory), exec);
if (m_pmmlOutEnabled) {
if (IncludeMethod.valueOf(m_includeMethod.getStringValue()) == IncludeMethod.RegExpPattern) {
setWarningMessage("Regular Expressions are not supported in PMML. " + "The generated PMML document is invalid.");
}
// the optional PMML in port (can be null)
PMMLPortObject inPMMLPort = m_pmmlInEnabled ? (PMMLPortObject) inObjects[1] : null;
/*
PMMLOne2ManyTranslator trans = new PMMLOne2ManyTranslator(
cellFactory.getColumnMapping(),
new DerivedFieldMapper(inPMMLPort));
*/
int[] sourceColIndices = cellFactory.getIncludedColIndices();
String[] sourceColNames = new String[sourceColIndices.length];
for (int i = 0; i < sourceColIndices.length; i++) {
sourceColNames[i] = inData.getDataTableSpec().getColumnSpec(sourceColIndices[i]).getName();
}
PMMLMany2OneTranslator trans = new PMMLMany2OneTranslator(cellFactory.getAppendedColumnName(), sourceColNames, IncludeMethod.valueOf(m_includeMethod.getStringValue()));
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