use of org.knime.core.node.port.PortObjectSpec 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.PortObjectSpec in project knime-core by knime.
the class AbstractNormalizerPMMLNodeModel method prepareConfigure.
/**
* @param inSpecs An array of DataTableSpecs (as many as this model has
* inputs).
* @return An array of DataTableSpecs (as many as this model has outputs)
*
* @throws InvalidSettingsException if the <code>#configure()</code> failed,
* that is, the settings are inconsistent with given
* DataTableSpec elements.
*/
@Override
protected PortObjectSpec[] prepareConfigure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec spec = (DataTableSpec) inSpecs[0];
PMMLPortObjectSpecCreator pmmlSpecCreator;
if (m_hasModelIn) {
PMMLPortObjectSpec pmmlSpec = (PMMLPortObjectSpec) inSpecs[1];
// extract selected numeric columns
updateNumericColumnSelection(spec);
if (getMode() == NONORM_MODE) {
return new PortObjectSpec[] { spec, pmmlSpec };
}
pmmlSpecCreator = new PMMLPortObjectSpecCreator(pmmlSpec, spec);
} else {
// extract selected numeric columns
updateNumericColumnSelection(spec);
if (getMode() == NONORM_MODE) {
return new PortObjectSpec[] { spec };
}
pmmlSpecCreator = new PMMLPortObjectSpecCreator(spec);
}
return new PortObjectSpec[] { Normalizer2.generateNewSpec(spec, getColumns()), pmmlSpecCreator.createSpec() };
}
use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.
the class DiscretizationApplyNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
// if no columns are defined to discretize, return the input spec
DataTableSpec modelSpec = (DataTableSpec) inSpecs[MODEL_INPORT];
if (modelSpec == null || modelSpec.getNumColumns() == 0) {
return new PortObjectSpec[] { inSpecs[DATA_INPORT] };
} else {
// else replace for each included column the attribute type to
// string
DataTableSpec dataSpec = (DataTableSpec) inSpecs[DATA_INPORT];
if (dataSpec == null) {
return new DataTableSpec[] { null };
}
DataColumnSpec[] newColumnSpecs = new DataColumnSpec[dataSpec.getNumColumns()];
int counter = 0;
for (DataColumnSpec origColSpec : dataSpec) {
// if the column is included for discretizing, change the spec
int modelColIdx = modelSpec.findColumnIndex(origColSpec.getName());
if (modelColIdx >= 0) {
// types of columns must be compatible
if (!modelSpec.getColumnSpec(modelColIdx).getType().isASuperTypeOf(origColSpec.getType())) {
throw new InvalidSettingsException("The type of the" + " column used to create the model is not" + " compatible to the input column type (" + " column name = " + origColSpec.getName() + ")");
}
// create a nominal string column spec
newColumnSpecs[counter] = new DataColumnSpecCreator(origColSpec.getName(), StringCell.TYPE).createSpec();
} else {
// add it as is
newColumnSpecs[counter] = origColSpec;
}
counter++;
}
DataTableSpec[] newSpecs = new DataTableSpec[1];
newSpecs[0] = new DataTableSpec(newColumnSpecs);
return newSpecs;
}
}
use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.
the class CategoryToNumberNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec inSpec = (DataTableSpec) inSpecs[0];
List<String> inputCols = new ArrayList<String>();
for (DataColumnSpec column : inSpec) {
if (column.getType().isCompatible(StringValue.class)) {
inputCols.add(column.getName());
}
}
FilterResult filter = m_settings.getFilterConfiguration().applyTo(inSpec);
String[] rmFromIncl = filter.getRemovedFromIncludes();
if (m_settings.getFilterConfiguration().isEnforceInclusion() && rmFromIncl.length != 0) {
throw new InvalidSettingsException("Input table does not contain the following selected column(s): " + ConvenienceMethods.getShortStringFrom(new HashSet<String>(Arrays.asList(rmFromIncl)), 3));
}
m_included = filter.getIncludes();
if (m_included.length == 0) {
setWarningMessage("No columns selected.");
}
ColumnRearranger rearranger = createRearranger(inSpec);
PMMLPortObjectSpec pmmlSpec = m_pmmlInEnabled ? (PMMLPortObjectSpec) inSpecs[1] : null;
PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(pmmlSpec, inSpec);
pmmlSpecCreator.addPreprocColNames(inputCols);
return new PortObjectSpec[] { rearranger.createSpec(), pmmlSpecCreator.createSpec() };
}
use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.
the class CorrelationComputeNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec in = (DataTableSpec) inSpecs[0];
if (!in.containsCompatibleType(DoubleValue.class) && !in.containsCompatibleType(NominalValue.class)) {
throw new InvalidSettingsException("No double or nominal compatible columns in input");
}
final String[] includes;
if (m_columnFilterModel == null) {
m_columnFilterModel = createColumnFilterModel();
// auto-configure, no previous configuration
m_columnFilterModel.loadDefaults(in);
includes = m_columnFilterModel.applyTo(in).getIncludes();
setWarningMessage("Auto configuration: Using all suitable " + "columns (in total " + includes.length + ")");
} else {
FilterResult applyTo = m_columnFilterModel.applyTo(in);
includes = applyTo.getIncludes();
}
if (includes.length == 0) {
throw new InvalidSettingsException("No columns selected");
}
return new PortObjectSpec[] { PMCCPortObjectAndSpec.createOutSpec(includes), new PMCCPortObjectAndSpec(includes) };
}
Aggregations