use of org.knime.core.data.def.StringCell in project knime-core by knime.
the class ColumnComparatorNodeModel method createColumnRearranger.
/**
* {@inheritDoc}
*/
@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec spec) throws InvalidSettingsException {
final ComparatorMethod method = ComparatorMethod.getMethod(m_operator.getStringValue());
final int idx1 = spec.findColumnIndex(m_firstColumn.getStringValue());
final int idx2 = spec.findColumnIndex(m_secondColumn.getStringValue());
DataColumnSpec leftSpec = spec.getColumnSpec(idx1);
DataColumnSpec rightSpec = spec.getColumnSpec(idx2);
ColumnRearranger colRe = new ColumnRearranger(spec);
colRe.append(new SingleCellFactory(createSpec(leftSpec, rightSpec)) {
private final StringCell m_matchRepl = new StringCell(m_matchValue.getStringValue());
private final StringCell m_mismatchRepl = new StringCell(m_mismatchValue.getStringValue());
@Override
public DataCell getCell(final DataRow row) {
DataCell cell1 = row.getCell(idx1);
DataCell cell2 = row.getCell(idx2);
if (method.compare(cell1, cell2)) {
String strMatch = m_matchOption.getStringValue();
if (strMatch.equals(REPL_OPTIONS[0])) {
return covertMatch(cell1);
} else if (strMatch.equals(REPL_OPTIONS[1])) {
return covertMatch(cell2);
} else if (strMatch.equals(REPL_OPTIONS[2])) {
return DataType.getMissingCell();
} else {
return m_matchRepl;
}
} else {
String strMismatch = m_mismatchOption.getStringValue();
if (strMismatch.equals(REPL_OPTIONS[0])) {
return covertMismatch(cell1);
} else if (strMismatch.equals(REPL_OPTIONS[1])) {
return covertMismatch(cell2);
} else if (strMismatch.equals(REPL_OPTIONS[2])) {
return DataType.getMissingCell();
} else {
return m_mismatchRepl;
}
}
}
});
return colRe;
}
use of org.knime.core.data.def.StringCell in project knime-core by knime.
the class LagColumnStreamableOperator method runFinal.
/**
* {@inheritDoc}
*/
@Override
public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
long counter = 0;
int maxLag = m_configuration.getLagInterval() * m_configuration.getLag();
RingBuffer ringBuffer = new RingBuffer(maxLag);
RowInput input = (RowInput) inputs[0];
RowOutput output = (RowOutput) outputs[0];
int skippedFirstCount = !m_configuration.isSkipInitialIncompleteRows() ? -1 : m_configuration.getLagInterval() * m_configuration.getLag();
DataRow row;
while ((row = input.poll()) != null) {
if (counter >= skippedFirstCount) {
DataCell[] newCells = getAdditionalCells(ringBuffer);
output.push(copyWithNewCells(row, newCells));
}
DataCell toBeCached = m_columnIndex < 0 ? new StringCell(row.getKey().toString()) : row.getCell(m_columnIndex);
ringBuffer.add(toBeCached);
setProgress(exec, counter, row);
counter += 1;
}
if (!m_configuration.isSkipLastIncompleteRows()) {
DataCell[] missings = new DataCell[input.getDataTableSpec().getNumColumns()];
Arrays.fill(missings, DataType.getMissingCell());
for (int i = 0; i < maxLag; i++) {
DataRow missingRow = new DefaultRow("overflow-" + i, missings);
DataCell[] newCells = getAdditionalCells(ringBuffer);
output.push(copyWithNewCells(missingRow, newCells));
ringBuffer.add(DataType.getMissingCell());
}
}
output.close();
}
use of org.knime.core.data.def.StringCell in project knime-core by knime.
the class CrossJoinerNodeModel method joinRow.
/**
* Joins the two rows into one.
* @param left the first data row (put at the beginning of the new one)
* @param right the second data row (at the end of the new one)
* @param showLeft if true there will be new column containing the rowid of the left column
* @param showRight if true there will be new column containing the rowid of the left column
* @param seperator String which will be put between the two rowkeys to generate the new one.
* @return a DataRow, containing the cells of both rows and if selected the rowkeys in new columns
* @since 2.9.1
*/
private DataRow joinRow(final DataRow left, final DataRow right, final boolean showLeft, final boolean showRight, final String seperator) {
int numCols = left.getNumCells() + right.getNumCells() + (showLeft ? 1 : 0) + (showRight ? 1 : 0);
DataCell[] cells = new DataCell[numCols];
for (int i = 0; i < left.getNumCells(); i++) {
cells[i] = left.getCell(i);
}
for (int i = 0; i < right.getNumCells(); i++) {
cells[i + left.getNumCells()] = right.getCell(i);
}
if (showLeft) {
cells[left.getNumCells() + right.getNumCells()] = new StringCell(left.getKey().toString());
}
if (showRight) {
cells[left.getNumCells() + right.getNumCells() + (showLeft ? 1 : 0)] = new StringCell(right.getKey().toString());
}
String newrowkey = left.getKey().getString() + seperator + right.getKey().getString();
return new DefaultRow(newrowkey, cells);
}
use of org.knime.core.data.def.StringCell in project knime-core by knime.
the class BinModelPlotter method updatePaintModel.
/**
* {@inheritDoc}
*/
@Override
public synchronized void updatePaintModel() {
if (m_discretizationModel == null) {
return;
}
// clear the drawing pane
((BinModelDrawingPane) getDrawingPane()).setBinningSchemes(null);
// get the first columns
if (m_selectedColumns == null) {
m_selectedColumns = new LinkedHashSet<String>();
String[] binnedColumnNames = m_discretizationModel.getIncludedColumnNames();
for (int i = 0; i < binnedColumnNames.length; i++) {
// add them to the selected columns
m_selectedColumns.add(binnedColumnNames[i]);
}
((MultiColumnPlotterProperties) getProperties()).updateColumnSelection(m_binnedColumnsSpec, m_selectedColumns);
}
if (m_selectedColumns.size() == 0) {
getDrawingPane().repaint();
return;
}
Set<DataCell> selectedColumnCells = new LinkedHashSet<DataCell>();
m_coordinates = new ArrayList<Coordinate>();
List<Integer> columnIndices = new ArrayList<Integer>();
for (String name : m_selectedColumns) {
int idx = m_binnedColumnsSpec.findColumnIndex(name);
if (idx >= 0) {
selectedColumnCells.add(new StringCell(name));
DataColumnSpec colSpec = m_binnedColumnsSpec.getColumnSpec(idx);
columnIndices.add(idx);
Coordinate coordinate = Coordinate.createCoordinate(colSpec);
m_coordinates.add(coordinate);
}
}
// get the binning schemes for the selected columns
DiscretizationScheme[] selectedSchemes = getSelectedSchemes();
String[] selectedColumnNames = getSelectedColumnNames();
// calculate the display coordinates for the drawing pane
BinRuler[] binRulers = new BinRuler[selectedSchemes.length];
// determine the width available for a bin ruler
int rulerWidth = getDrawingPaneDimension().width - 2 * m_hMargin;
for (int i = 0; i < selectedSchemes.length; i++) {
double[] bounds = selectedSchemes[i].getBounds();
double min = bounds[0];
double max = bounds[bounds.length - 1];
// first create a colum spec from the schemes
DataColumnSpecCreator columnSpecCreator = new DataColumnSpecCreator("", DoubleCell.TYPE);
columnSpecCreator.setDomain(new DataColumnDomainCreator(new DoubleCell(min), new DoubleCell(max)).createDomain());
DoubleCoordinate coordinate = (DoubleCoordinate) Coordinate.createCoordinate(columnSpecCreator.createSpec());
Point leftStart = new Point(m_hMargin, m_vMargin + (i + 1) * m_columnDisplayHeight);
int[] binPositions = new int[bounds.length];
String[] binLabels = new String[bounds.length];
int count = 0;
for (double bound : bounds) {
binPositions[count] = (int) coordinate.calculateMappedValue(new DoubleCell(bound), rulerWidth, true);
binLabels[count] = coordinate.formatNumber(bounds[count]);
count++;
}
binRulers[i] = new BinRuler(leftStart, rulerWidth, binPositions, binLabels, selectedColumnNames[i]);
}
((BinModelDrawingPane) getDrawingPane()).setBinningSchemes(binRulers);
m_hMargin = 10;
m_vMargin = 10;
((BinModelDrawingPane) getDrawingPane()).setHorizontalMargin(m_hMargin);
setHeight(binRulers[binRulers.length - 1].getLeftStartPoint().y + 40);
}
use of org.knime.core.data.def.StringCell in project knime-core by knime.
the class EditNominalDomainNodeDialogPane method addStringCell.
/**
* @return
*/
private ActionListener addStringCell() {
return new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
String s = (String) JOptionPane.showInputDialog(EditNominalDomainNodeDialogPane.this.getPanel(), "Value: ", "Add Data Cell", JOptionPane.PLAIN_MESSAGE, null, null, "");
if (s != null && !s.isEmpty() && m_currentColSpec != null) {
int index = m_jlist.getSelectedIndex() == -1 ? 0 : m_jlist.getSelectedIndex();
StringCell stringCell = new StringCell(s);
int lastIndexOf = m_currentSorting.lastIndexOf(stringCell);
if (lastIndexOf != -1) {
JOptionPane.showMessageDialog(EditNominalDomainNodeDialogPane.this.getPanel(), String.format("Value: '%s' does already exist at index: %d", s, lastIndexOf));
} else {
m_currentSorting.add(index, stringCell);
m_configuration.addCreatedValue(m_currentColSpec.getName(), stringCell);
m_jlist.setSelectedIndices(new int[] { index });
LOGGER.info("created new value: " + s);
}
}
}
};
}
Aggregations