use of org.knime.core.data.container.CellFactory in project knime-core by knime.
the class One2ManyColPMMLNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec inDataSpec = (DataTableSpec) inSpecs[0];
m_appendOrgColName = false;
if (m_includedColumns.getIncludeList() == null || m_includedColumns.getIncludeList().size() <= 0) {
setWarningMessage("No columns to transfrom selected. Will have no effect!");
}
// check if the values are present in the current spec
if (m_includedColumns.getIncludeList() != null && m_includedColumns.getIncludeList().size() > 0) {
checkColumnsSpecs(inDataSpec);
}
CellFactory cellFactory = new One2ManyCellFactory(inDataSpec, m_includedColumns.getIncludeList(), m_appendOrgColName);
ColumnRearranger rearranger = createRearranger(inDataSpec, cellFactory);
if (m_pmmlEnabled) {
PMMLPortObjectSpec pmmlSpec = (PMMLPortObjectSpec) inSpecs[1];
PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(pmmlSpec, inDataSpec);
return new PortObjectSpec[] { rearranger.createSpec(), pmmlSpecCreator.createSpec() };
} else {
return new PortObjectSpec[] { rearranger.createSpec() };
}
}
use of org.knime.core.data.container.CellFactory in project knime-core by knime.
the class CollectionCreate2NodeModel method createColumnRearranger.
@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec in) throws InvalidSettingsException {
FilterResult filterResult = m_includeModel.applyTo(in);
List<String> includes = Arrays.asList(filterResult.getIncludes());
String[] names = includes.toArray(new String[includes.size()]);
final int[] colIndices = new int[names.length];
for (int i = 0; i < names.length; i++) {
int index = in.findColumnIndex(names[i]);
if (index < 0) {
throw new InvalidSettingsException("No column \"" + names[i] + "\" in input table");
}
colIndices[i] = index;
}
DataType comType;
if (includes.size() == 0) {
comType = DataType.getType(DataCell.class);
} else {
comType = CollectionCellFactory.getElementType(in, colIndices);
}
String newColName = m_newColName.getStringValue();
DataType type;
if (m_createSet.getBooleanValue()) {
type = SetCell.getCollectionType(comType);
} else {
type = ListCell.getCollectionType(comType);
}
DataColumnSpecCreator newColSpecC = new DataColumnSpecCreator(newColName, type);
newColSpecC.setElementNames(names);
DataColumnSpec newColSpec = newColSpecC.createSpec();
CellFactory appendFactory = new SingleCellFactory(newColSpec) {
/**
* {@inheritDoc}
*/
@Override
public DataCell getCell(final DataRow row) {
int[] validColIndices = colIndices;
// iff ignore missing value is switched on
if (m_ignoreMissing.getBooleanValue()) {
List<Integer> vCI = new ArrayList<Integer>();
for (int i : validColIndices) {
if (!row.getCell(i).isMissing()) {
vCI.add(i);
}
}
validColIndices = buildIntArray(vCI);
}
// based on given column indices
if (m_createSet.getBooleanValue()) {
return CollectionCellFactory.createSetCell(row, validColIndices);
} else {
return CollectionCellFactory.createListCell(row, validColIndices);
}
}
};
ColumnRearranger rearranger = new ColumnRearranger(in);
if (m_removeCols.getBooleanValue()) {
rearranger.remove(colIndices);
}
rearranger.append(appendFactory);
return rearranger;
}
use of org.knime.core.data.container.CellFactory in project knime-core by knime.
the class SearchReplaceDictNodeModel method createColumnRearranger.
@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec spec) {
ColumnRearranger result = new ColumnRearranger(spec);
final int targetColIndex = spec.findColumnIndex(m_targetColumnName);
DataColumnSpecCreator newColCreator;
if (m_newColumnName == null) {
DataColumnSpec old = spec.getColumnSpec(m_targetColumnName);
newColCreator = new DataColumnSpecCreator(old);
newColCreator.setType(StringCell.TYPE);
newColCreator.setDomain(null);
} else {
newColCreator = new DataColumnSpecCreator(m_newColumnName, StringCell.TYPE);
}
CellFactory amendedCol = new SingleCellFactory(newColCreator.createSpec()) {
@Override
public DataCell getCell(final DataRow row) {
DataCell c = row.getCell(targetColIndex);
if (c.isMissing()) {
return c;
}
String cellContent = c.toString();
String replacement = m_replacementMap.get(cellContent);
if (replacement != null) {
return new StringCell(replacement);
} else {
// StringCell.TYPE!)
return new StringCell(cellContent);
}
}
};
if (m_newColumnName != null) {
result.append(amendedCol);
} else {
result.replace(amendedCol, targetColIndex);
}
return result;
}
use of org.knime.core.data.container.CellFactory in project knime-core by knime.
the class RowKeyUtil2 method createColumnRearranger.
/**
* Creates the {@link ColumnRearranger} that appends a new column with the
* values of the row id to a data table.
*
* @param inSpec the <code>DataTableSpec</code> of table were the column
* should be appended
* @param newColName the name of the added column
* @param type the <code>DataType</code> of the new column
* @return the {@link ColumnRearranger} to use
*/
public static ColumnRearranger createColumnRearranger(final DataTableSpec inSpec, final String newColName, final DataType type) {
final ColumnRearranger c = new ColumnRearranger(inSpec);
// column specification of the appended column
final DataColumnSpecCreator colSpecCreater = new DataColumnSpecCreator(newColName, type);
final DataColumnSpec newColSpec = colSpecCreater.createSpec();
// utility object that performs the calculation
final CellFactory factory = new SingleCellFactory(newColSpec) {
@Override
public DataCell getCell(final DataRow row) {
return new StringCell(row.getKey().getString());
}
};
c.append(factory);
return c;
}
use of org.knime.core.data.container.CellFactory in project knime-core by knime.
the class ThreadedColAppenderNodeModel method createOutputSpec.
/**
* Returns the output spec based on the input spec and the cell factory.
*
* @param inSpec the input spec
* @param cellFactory the cell factory used
* @return the output spec
*/
protected static DataTableSpec createOutputSpec(final DataTableSpec inSpec, final ExtendedCellFactory cellFactory) {
ColumnRearranger rea = new ColumnRearranger(inSpec);
ColumnDestination[] dests = cellFactory.getColumnDestinations();
for (int k = 0; k < dests.length; k++) {
ColumnDestination cd = dests[k];
CellFactory cf = new SingleCellFactory(cellFactory.getColumnSpecs()[k]) {
@Override
public DataCell getCell(final DataRow row) {
return null;
}
};
if (cd instanceof AppendColumn) {
rea.append(cf);
} else if (cd instanceof InsertColumn) {
rea.insertAt(((InsertColumn) cd).getIndex(), cf);
} else {
rea.replace(cf, ((ReplaceColumn) cd).getIndex());
}
}
return rea.createSpec();
}
Aggregations