use of org.knime.core.data.DataColumnSpec in project knime-core by knime.
the class TimeMissingValueHandlingNodeDialogPane method markIncompatibleTypedColumns.
private static void markIncompatibleTypedColumns(final ConfigType type, final List<DataColumnSpec> colSpecs) {
ListIterator<DataColumnSpec> iterator = colSpecs.listIterator();
while (iterator.hasNext()) {
DataColumnSpec dataColumnSpec = iterator.next();
if (isIncompatible(type, dataColumnSpec)) {
iterator.remove();
iterator.add(createAsIncompatibleMarkedColumnSpec(dataColumnSpec));
}
}
}
use of org.knime.core.data.DataColumnSpec in project knime-core by knime.
the class RuleEngineNodeModel method createRearranger.
private ColumnRearranger createRearranger(final DataTableSpec inSpec, final List<Rule> rules, final long rowCount, final boolean updateColSpec) throws InvalidSettingsException {
if (m_settings.isAppendColumn() && m_settings.getNewColName().isEmpty()) {
throw new InvalidSettingsException("No name for prediction column provided");
}
ColumnRearranger crea = new ColumnRearranger(inSpec);
String newColName = m_settings.isAppendColumn() ? DataTableSpec.getUniqueColumnName(inSpec, m_settings.getNewColName()) : m_settings.getReplaceColumn();
final DataType outType = computeOutputType(rules, RuleNodeSettings.RuleEngine, m_settings.isDisallowLongOutputForCompatibility());
DataColumnSpecCreator colSpecCreator = new DataColumnSpecCreator(newColName, outType);
if (updateColSpec) {
// only update in configure, execute will compute properly
updateColSpec(rules, outType, colSpecCreator, this);
}
DataColumnSpec cs = colSpecCreator.createSpec();
final boolean disallowLongOutputForCompatibility = m_settings.isDisallowLongOutputForCompatibility();
VariableProvider.SingleCellFactoryProto cellFactory = new VariableProvider.SingleCellFactoryProto(cs) {
private long m_rowIndex = -1L;
@Override
public DataCell getCell(final DataRow row) {
m_rowIndex++;
return getRulesOutcome(outType, row, rules, disallowLongOutputForCompatibility, this);
}
@Override
public Object readVariable(final String name, final Class<?> type) {
return RuleEngineNodeModel.this.readVariable(name, type);
}
@Deprecated
@Override
public int getRowIndex() {
return (int) m_rowIndex;
}
@Override
public long getRowIndexLong() {
return m_rowIndex;
}
@Deprecated
@Override
public int getRowCount() {
return (int) rowCount;
}
@Override
public long getRowCountLong() {
return rowCount;
}
};
if (m_settings.isAppendColumn()) {
crea.append(cellFactory);
} else {
crea.replace(cellFactory, m_settings.getReplaceColumn());
}
return crea;
}
use of org.knime.core.data.DataColumnSpec in project knime-core by knime.
the class PMMLRuleEditorNodeModel method computeSpecs.
/**
* Computes the specs after applying the derived fields.
*
* @param specs The input table and the possible preprocessing port.
* @return The computed (original+preproc) input table's specification.
*/
@Deprecated
static DataTableSpec computeSpecs(final PortObjectSpec[] specs) {
final DataTableSpec tableSpec = (DataTableSpec) specs[0];
if (specs[1] == null) {
return tableSpec;
}
PMMLPortObjectSpec portObjectSpec = (PMMLPortObjectSpec) specs[1];
List<DataColumnSpec> preprocessingCols = portObjectSpec.getPreprocessingCols();
DataTableSpecCreator creator = new DataTableSpecCreator(tableSpec);
for (DataColumnSpec spec : preprocessingCols) {
creator.addColumns(spec);
}
return creator.createSpec();
}
use of org.knime.core.data.DataColumnSpec in project knime-core by knime.
the class PMMLRuleEditorNodeModel method createPMMLPortObjectSpec.
/**
* Initializes the {@link PMMLPortObjectSpec} based on the model, input and the used column.
*
* @param modelSpec The preprocessing model, can be {@code null}.
* @param spec The input table spec.
* @param usedColumns The columns used by the rules.
* @return The {@link PMMLPortObjectSpec} filled with proper data for configuration.
*/
private PMMLPortObjectSpec createPMMLPortObjectSpec(final DataTableSpec spec, final List<String> usedColumns) {
// this assumes that the new column is always the last column in the spec; which is the case if
// #createRearranger uses ColumnRearranger.append.
String targetCol = m_settings.isAppendColumn() ? spec.getColumnSpec(spec.getNumColumns() - 1).getName() : m_settings.getReplaceColumn();
Set<String> set = new LinkedHashSet<>(usedColumns);
List<String> learnCols = new LinkedList<>();
for (int i = 0; i < spec.getNumColumns(); i++) {
DataColumnSpec columnSpec = spec.getColumnSpec(i);
String col = columnSpec.getName();
if (!col.equals(targetCol) && set.contains(col) && (columnSpec.getType().isCompatible(DoubleValue.class) || columnSpec.getType().isCompatible(NominalValue.class) && (/*!m_skipColumns.getBooleanValue() ||*/
columnSpec.getDomain().hasValues()))) {
learnCols.add(spec.getColumnSpec(i).getName());
}
}
PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(spec);
pmmlSpecCreator.setLearningColsNames(learnCols);
pmmlSpecCreator.setTargetColName(targetCol);
return pmmlSpecCreator.createSpec();
}
use of org.knime.core.data.DataColumnSpec in project knime-core by knime.
the class PMMLRuleSetPredictorNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec original = (DataTableSpec) inSpecs[DATA_INDEX];
ColumnRearranger rearranger = new ColumnRearranger(original);
PMMLPortObjectSpec portObjectSpec = (PMMLPortObjectSpec) inSpecs[MODEL_INDEX];
List<DataColumnSpec> activeColumnList = portObjectSpec.getActiveColumnList();
List<DataColumnSpec> notFound = new ArrayList<DataColumnSpec>();
for (DataColumnSpec dataColumnSpec : activeColumnList) {
if (original.containsName(dataColumnSpec.getName())) {
DataColumnSpec origSpec = original.getColumnSpec(dataColumnSpec.getName());
if (!origSpec.getType().equals(dataColumnSpec.getType())) {
notFound.add(dataColumnSpec);
}
} else {
notFound.add(dataColumnSpec);
}
}
if (!notFound.isEmpty()) {
StringBuilder sb = new StringBuilder("Incompatible to the table, the following columns are not present, or have a wrong type:");
for (DataColumnSpec dataColumnSpec : notFound) {
sb.append("\n ").append(dataColumnSpec);
}
throw new InvalidSettingsException(sb.toString());
}
List<DataColumnSpec> targetCols = portObjectSpec.getTargetCols();
final DataType dataType = targetCols.isEmpty() ? StringCell.TYPE : targetCols.get(0).getType();
DataColumnSpecCreator specCreator;
if (m_doReplaceColumn.getBooleanValue()) {
String col = m_replaceColumn.getStringValue();
specCreator = new DataColumnSpecCreator(col, dataType);
} else {
specCreator = new DataColumnSpecCreator(DataTableSpec.getUniqueColumnName(original, m_outputColumn.getStringValue()), dataType);
}
SingleCellFactory dummy = new SingleCellFactory(specCreator.createSpec()) {
/**
* {@inheritDoc}
*/
@Override
public DataCell getCell(final DataRow row) {
throw new IllegalStateException();
}
};
if (m_addConfidence.getBooleanValue()) {
rearranger.append(new SingleCellFactory(new DataColumnSpecCreator(DataTableSpec.getUniqueColumnName(rearranger.createSpec(), m_confidenceColumn.getStringValue()), DoubleCell.TYPE).createSpec()) {
@Override
public DataCell getCell(final DataRow row) {
throw new IllegalStateException();
}
});
}
if (m_doReplaceColumn.getBooleanValue()) {
rearranger.replace(dummy, m_replaceColumn.getStringValue());
} else {
rearranger.append(dummy);
}
return new DataTableSpec[] { rearranger.createSpec() };
}
Aggregations