Search in sources :

Example 61 with StringCell

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;
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) ColumnComparatorNodeDialogPane.createComparatorMethod(org.knime.base.node.preproc.colcompare.ColumnComparatorNodeDialogPane.createComparatorMethod) ComparatorMethod(org.knime.base.node.preproc.colcompare.ColumnComparatorNodeDialogPane.ComparatorMethod) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) DataRow(org.knime.core.data.DataRow)

Example 62 with StringCell

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();
}
Also used : RowOutput(org.knime.core.node.streamable.RowOutput) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) RowInput(org.knime.core.node.streamable.RowInput) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) BlobSupportDataRow(org.knime.core.data.container.BlobSupportDataRow) DataRow(org.knime.core.data.DataRow)

Example 63 with StringCell

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);
}
Also used : StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 64 with StringCell

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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DoubleCell(org.knime.core.data.def.DoubleCell) DiscretizationScheme(org.knime.base.node.preproc.discretization.caim2.DiscretizationScheme) ArrayList(java.util.ArrayList) DoubleCoordinate(org.knime.base.util.coordinate.DoubleCoordinate) DataColumnSpec(org.knime.core.data.DataColumnSpec) MultiColumnPlotterProperties(org.knime.base.node.viz.plotter.columns.MultiColumnPlotterProperties) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator) Point(java.awt.Point) Point(java.awt.Point) DoubleCoordinate(org.knime.base.util.coordinate.DoubleCoordinate) Coordinate(org.knime.base.util.coordinate.Coordinate) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell)

Example 65 with StringCell

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);
                }
            }
        }
    };
}
Also used : ActionListener(java.awt.event.ActionListener) StringCell(org.knime.core.data.def.StringCell) ActionEvent(java.awt.event.ActionEvent)

Aggregations

StringCell (org.knime.core.data.def.StringCell)176 DataCell (org.knime.core.data.DataCell)130 DoubleCell (org.knime.core.data.def.DoubleCell)67 DefaultRow (org.knime.core.data.def.DefaultRow)65 IntCell (org.knime.core.data.def.IntCell)55 DataRow (org.knime.core.data.DataRow)52 DataTableSpec (org.knime.core.data.DataTableSpec)49 ArrayList (java.util.ArrayList)41 DataColumnSpec (org.knime.core.data.DataColumnSpec)37 RowKey (org.knime.core.data.RowKey)36 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)26 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)26 DataType (org.knime.core.data.DataType)22 LinkedHashSet (java.util.LinkedHashSet)21 BufferedDataTable (org.knime.core.node.BufferedDataTable)20 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)19 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)16 LinkedHashMap (java.util.LinkedHashMap)15 Test (org.junit.Test)15 HashMap (java.util.HashMap)11