use of org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator in project knime-core by knime.
the class ClusterNodeModel method createPMMLSpec.
private PMMLPortObjectSpec createPMMLSpec(final PMMLPortObjectSpec pmmlSpec, final DataTableSpec originalSpec) throws InvalidSettingsException {
List<String> includes;
if (m_usedColumns.isKeepAllSelected()) {
includes = new ArrayList<String>();
for (DataColumnSpec col : originalSpec) {
if (col.getType().isCompatible(DoubleValue.class)) {
includes.add(col.getName());
}
}
} else {
includes = new ArrayList<String>();
for (String s : m_usedColumns.getIncludeList()) {
if (originalSpec.getColumnSpec(s).getType().isCompatible(DoubleValue.class)) {
includes.add(s);
}
}
}
HashSet<String> colNameHash = new HashSet<String>(includes);
// the order in this list is important, need to use the order defined
// by DTS, not m_usedColumns
List<String> activeCols = new LinkedList<String>();
for (DataColumnSpec colSpec : originalSpec) {
String name = colSpec.getName();
if (colNameHash.remove(name)) {
activeCols.add(name);
}
}
if (!colNameHash.isEmpty()) {
throw new InvalidSettingsException("Input table does not match " + "selected columns, unable to find column(s): " + colNameHash);
}
PMMLPortObjectSpecCreator creator = new PMMLPortObjectSpecCreator(pmmlSpec, originalSpec);
creator.setLearningColsNames(activeCols);
return creator.createSpec();
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator in project knime-core by knime.
the class NaiveBayesLearnerNodeModel2 method createPMMLSpec.
private PMMLPortObjectSpec createPMMLSpec(final DataTableSpec tableSpec, final PMMLPortObjectSpec modelSpec, final List<String> learnCols, final String classColumn) {
final PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(modelSpec, tableSpec);
pmmlSpecCreator.setLearningColsNames(learnCols);
pmmlSpecCreator.setTargetColName(classColumn);
final PMMLPortObjectSpec pmmlSpec = pmmlSpecCreator.createSpec();
return pmmlSpec;
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator in project knime-core by knime.
the class One2ManyCol2PMMLNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec inDataSpec = (DataTableSpec) inSpecs[0];
m_appendOrgColName = false;
String[] includes = m_includedColumns.applyTo(inDataSpec).getIncludes();
if (includes.length <= 0) {
setWarningMessage("No columns to transfrom selected. Will have no effect!");
}
// check if the values are present in the current spec
if (includes.length > 0) {
checkColumnsSpecs(inDataSpec);
}
CellFactory cellFactory = new One2ManyCellFactory(inDataSpec, Arrays.asList(includes), m_appendOrgColName);
ColumnRearranger rearranger = createRearranger(inDataSpec, cellFactory);
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 PortObjectSpec[] { rearranger.createSpec() };
}
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator in project knime-core by knime.
the class BinnerNodeModel method createPMMLModel.
/**
* Creates the pmml port object.
* @param the in-port pmml object. Can be <code>null</code> (optional in-port)
*/
private PMMLPortObject createPMMLModel(final PMMLPortObject inPMMLPort, final DataTableSpec inSpec, final DataTableSpec outSpec) {
PMMLBinningTranslator trans = new PMMLBinningTranslator(m_columnToBins, m_columnToAppended, new DerivedFieldMapper(inPMMLPort));
PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(inPMMLPort, outSpec);
PMMLPortObject outPMMLPort = new PMMLPortObject(pmmlSpecCreator.createSpec(), inPMMLPort, inSpec);
outPMMLPort.addGlobalTransformations(trans.exportToTransDict());
return outPMMLPort;
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator 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