Search in sources :

Example 31 with RowIterator

use of org.knime.core.data.RowIterator in project knime-core by knime.

the class SubgroupMinerModel method preprocess.

private List<BitVectorValue> preprocess(final DataTable inData, final ExecutionMonitor exec) throws CanceledExecutionException {
    // TODO: check in configure that only Double values are in the table
    m_tidRowKeyMapping = new HashMap<Integer, RowKey>();
    m_nrOfRows = 0;
    int totalNrRows = ((BufferedDataTable) inData).getRowCount();
    m_maxBitsetLength = 0;
    List<BitVectorValue> bitSets = new ArrayList<BitVectorValue>();
    int bitVectorIndex = inData.getDataTableSpec().findColumnIndex(m_bitVectorColumn.getStringValue());
    if (bitVectorIndex < 0) {
        return new ArrayList<BitVectorValue>();
    }
    for (RowIterator itr = inData.iterator(); itr.hasNext(); ) {
        exec.checkCanceled();
        DataRow currRow = itr.next();
        DataCell dc = currRow.getCell(bitVectorIndex);
        if (dc.isMissing()) {
            continue;
        }
        BitVectorValue currCell = ((BitVectorValue) currRow.getCell(bitVectorIndex));
        if (currCell.length() > Integer.MAX_VALUE) {
            throw new IllegalArgumentException("bit vector in row " + currRow.getKey().getString() + " is too long: " + currCell.length() + ". Only bit vectors up to " + Integer.MAX_VALUE + " are supported by this node.");
        }
        m_maxBitsetLength = Math.max(m_maxBitsetLength, (int) currCell.length());
        bitSets.add(currCell);
        m_tidRowKeyMapping.put(m_nrOfRows, currRow.getKey());
        m_nrOfRows++;
        exec.setProgress((double) m_nrOfRows / (double) totalNrRows, "preprocessing......." + m_nrOfRows);
    }
    LOGGER.debug("max length: " + m_maxBitsetLength);
    return bitSets;
}
Also used : RowKey(org.knime.core.data.RowKey) RowIterator(org.knime.core.data.RowIterator) BufferedDataTable(org.knime.core.node.BufferedDataTable) ArrayList(java.util.ArrayList) DataCell(org.knime.core.data.DataCell) BitVectorValue(org.knime.core.data.vector.bitvector.BitVectorValue) DataRow(org.knime.core.data.DataRow)

Example 32 with RowIterator

use of org.knime.core.data.RowIterator in project knime-core by knime.

the class Rule2DDrawingPane method paintRules.

private synchronized void paintRules(final Graphics g) {
    if (m_normRules == null || !m_normRules.iterator().hasNext()) {
        return;
    }
    m_coreRegions = new HashMap<RowKey, Rectangle>();
    Graphics2D g2 = (Graphics2D) g;
    RowIterator orgItr = m_orgData.iterator();
    for (Iterator<DataRow> it = m_normRules.iterator(); it.hasNext(); ) {
        DataRow row = it.next();
        DataRow orgRow = orgItr.next();
        // or if rule is hilited
        if (!m_hideUnhilitedRules || m_hiLiteHandler.isHiLit(row.getKey())) {
            // check whether the rule is selected or hilited
            boolean selected = m_selectedRules.contains(row.getKey());
            boolean hilite = false;
            if (m_hiLiteHandler != null) {
                hilite = m_hiLiteHandler.isHiLit(row.getKey());
            }
            Color currColor = m_orgData.getDataTableSpec().getRowColor(orgRow).getColor(selected, hilite);
            FuzzyIntervalValue x = (FuzzyIntervalValue) row.getCell(0);
            FuzzyIntervalValue y = (FuzzyIntervalValue) row.getCell(1);
            // fuzzy rule
            if (x.getMinSupport() != x.getMinCore() || x.getMaxCore() != x.getMaxSupport() || y.getMinSupport() != y.getMinCore() || y.getMaxCore() != y.getMaxSupport()) {
                paintSupportArea(g2, row, currColor);
            }
            paintCoreArea(g2, row, currColor);
        }
    // end is unhiliting?
    }
// end for
}
Also used : FuzzyIntervalValue(org.knime.core.data.FuzzyIntervalValue) RowKey(org.knime.core.data.RowKey) RowIterator(org.knime.core.data.RowIterator) Color(java.awt.Color) Rectangle(java.awt.Rectangle) DataRow(org.knime.core.data.DataRow) Graphics2D(java.awt.Graphics2D)

Example 33 with RowIterator

use of org.knime.core.data.RowIterator in project knime-core by knime.

the class Rule2DPlotter method updatePaintModel.

/**
 * {@inheritDoc}
 */
@Override
protected void updatePaintModel() {
    super.updatePaintModel();
    if (m_rules != null) {
        Rule2DDrawingPane drawingPane = getDrawingPane();
        drawingPane.setOriginalRuleTable(m_rules);
        String xName = getXColName();
        String yName = getYColName();
        int xIdx = -1;
        int yIdx = -1;
        if (xName != null && yName != null) {
            xIdx = m_rules.getDataTableSpec().findColumnIndex(xName);
            yIdx = m_rules.getDataTableSpec().findColumnIndex(yName);
        }
        if (xIdx >= 0 && yIdx >= 0) {
            Coordinate x = getColHeader().getCoordinate();
            Coordinate y = getRowHeader().getCoordinate();
            // check if the coordinates are valid
            if (x == null || y == null) {
                return;
            }
            // calculate the coordinates of the rules here
            // List<DataRow> rows = new ArrayList<DataRow>();
            DataColumnSpecCreator creator = new DataColumnSpecCreator("xValues", FuzzyIntervalCell.TYPE);
            DataColumnSpec col1 = creator.createSpec();
            creator = new DataColumnSpecCreator("yValues", FuzzyIntervalCell.TYPE);
            DataColumnSpec col2 = creator.createSpec();
            DataTableSpec spec = new DataTableSpec(new DataColumnSpec[] { col1, col2 });
            DataContainer rows = new DataContainer(spec);
            for (RowIterator itr = m_rules.iterator(); itr.hasNext(); ) {
                DataRow currRow = itr.next();
                DataCell[] newCells = new DataCell[2];
                for (int cell = 0; cell < currRow.getNumCells(); cell++) {
                    // if (!m_rules.getDataTableSpec().getColumnSpec(cell)
                    // .getType().isCompatible(
                    // FuzzyIntervalValue.class)) {
                    // continue;
                    // }
                    Rectangle rect = calculateDrawingRectangle();
                    double a;
                    double b;
                    double c;
                    double d;
                    if (cell == xIdx) {
                        if (currRow.getCell(cell).isMissing()) {
                            // normalize xValues
                            a = getXmin();
                            b = getXmin();
                            c = getXmax();
                            d = getXmax();
                        } else {
                            // normalize xValues
                            a = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinSupport();
                            b = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinCore();
                            c = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxCore();
                            d = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxSupport();
                        }
                        double newA = x.calculateMappedValue(new DoubleCell(a), rect.width, true);
                        double newB = x.calculateMappedValue(new DoubleCell(b), rect.width, true);
                        double newC = x.calculateMappedValue(new DoubleCell(c), rect.width, true);
                        double newD = x.calculateMappedValue(new DoubleCell(d), rect.width, true);
                        DataCell newInterval = new FuzzyIntervalCell(rect.x + newA, rect.x + newB, rect.x + newC, rect.x + newD);
                        newCells[0] = newInterval;
                    }
                    if (cell == yIdx) {
                        if (currRow.getCell(cell).isMissing()) {
                            a = getYmin();
                            b = getYmin();
                            c = getYmax();
                            d = getYmax();
                        } else {
                            // normalize yValues
                            a = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinSupport();
                            b = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinCore();
                            c = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxCore();
                            d = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxSupport();
                        }
                        double newA = y.calculateMappedValue(new DoubleCell(a), rect.height, true);
                        double newB = y.calculateMappedValue(new DoubleCell(b), rect.height, true);
                        double newC = y.calculateMappedValue(new DoubleCell(c), rect.height, true);
                        double newD = y.calculateMappedValue(new DoubleCell(d), rect.height, true);
                        DataCell newInterval = new FuzzyIntervalCell(rect.y + rect.height - newD, rect.y + rect.height - newC, rect.y + rect.height - newB, rect.y + rect.height - newA);
                        newCells[1] = newInterval;
                    }
                }
                // create new row out of the normalized cells
                rows.addRowToTable(new DefaultRow(currRow.getKey(), newCells));
            }
            rows.close();
            drawingPane.setNormalizedRules(new DefaultDataArray(rows.getTable(), 1, m_rules.size()));
        }
        super.updatePaintModel();
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DoubleCell(org.knime.core.data.def.DoubleCell) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) Rectangle(java.awt.Rectangle) DataRow(org.knime.core.data.DataRow) FuzzyIntervalCell(org.knime.core.data.def.FuzzyIntervalCell) DataContainer(org.knime.core.data.container.DataContainer) DataColumnSpec(org.knime.core.data.DataColumnSpec) Coordinate(org.knime.base.util.coordinate.Coordinate) RowIterator(org.knime.core.data.RowIterator) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 34 with RowIterator

use of org.knime.core.data.RowIterator in project knime-core by knime.

the class TableRowToImageNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    BufferedDataTable inTable = (BufferedDataTable) inObjects[0];
    // check for empty table
    if (inTable.size() == 0) {
        throw new IllegalArgumentException("Input table is empty.");
    }
    // warn if more than one row
    if (inTable.size() > 1) {
        setWarningMessage("Input data table has more than one rows! " + "Using first row only.");
    }
    String column = m_imageColSettingsModel.getStringValue();
    DataTableSpec inSpec = inTable.getDataTableSpec();
    int columnIndex = inSpec.findColumnIndex(column);
    if (columnIndex < 0) {
        columnIndex = findImageColumnIndex(inSpec);
    }
    ImagePortObjectSpec imagePortObjectSpec = new ImagePortObjectSpec(inSpec.getColumnSpec(columnIndex).getType());
    final RowIterator it = inTable.iterator();
    while (it.hasNext()) {
        DataRow row = it.next();
        DataCell cell = row.getCell(columnIndex);
        if (!cell.isMissing()) {
            ImageContent ic = ((ImageValue) cell).getImageContent();
            return new PortObject[] { new ImagePortObject(ic, imagePortObjectSpec) };
        } else {
            setWarningMessage("Found missing image cell, skipping it...");
        }
    }
    throw new IllegalArgumentException("Input table contains only missing cells.");
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ImagePortObjectSpec(org.knime.core.node.port.image.ImagePortObjectSpec) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) ImagePortObject(org.knime.core.node.port.image.ImagePortObject) DataRow(org.knime.core.data.DataRow) ImageContent(org.knime.core.data.image.ImageContent) RowIterator(org.knime.core.data.RowIterator) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCell(org.knime.core.data.DataCell) ImageValue(org.knime.core.data.image.ImageValue) PortObject(org.knime.core.node.port.PortObject) ImagePortObject(org.knime.core.node.port.image.ImagePortObject)

Example 35 with RowIterator

use of org.knime.core.data.RowIterator in project knime-core by knime.

the class AppendedRowsIterator method initNextTable.

/**
 * Start iterator on next table.
 */
private void initNextTable() {
    assert (m_curItIndex < m_iteratorSuppliers.length - 1);
    m_curItIndex++;
    Pair<RowIterator, DataTableSpec> pair = m_iteratorSuppliers[m_curItIndex].get();
    m_curIterator = pair.getFirst();
    DataTableSpec spec = pair.getSecond();
    int missingNumber = m_spec.getNumColumns() - spec.getNumColumns();
    m_curMissingCells = new DataCell[missingNumber];
    int missingCounter = 0;
    m_curMapping = new int[m_spec.getNumColumns()];
    for (int c = 0; c < m_spec.getNumColumns(); c++) {
        DataColumnSpec colSpec = m_spec.getColumnSpec(c);
        int targetCol = spec.findColumnIndex(colSpec.getName());
        if (targetCol < 0) {
            // that is one of the "missing" columns
            targetCol = spec.getNumColumns() + missingCounter;
            // create the missing cell
            m_curMissingCells[missingCounter] = DataType.getMissingCell();
            missingCounter++;
        }
        m_curMapping[c] = targetCol;
    }
    boolean leaveUntouched = missingCounter == 0;
    for (int i = 0; leaveUntouched && i < m_curMapping.length; i++) {
        if (m_curMapping[i] != i) {
            leaveUntouched = false;
        }
    }
    if (leaveUntouched) {
        m_curMapping = null;
        m_curMissingCells = null;
    }
    assert missingCounter == missingNumber;
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) CloseableRowIterator(org.knime.core.data.container.CloseableRowIterator) RowIterator(org.knime.core.data.RowIterator)

Aggregations

RowIterator (org.knime.core.data.RowIterator)77 DataRow (org.knime.core.data.DataRow)62 DataCell (org.knime.core.data.DataCell)28 DataTableSpec (org.knime.core.data.DataTableSpec)20 RowKey (org.knime.core.data.RowKey)16 DoubleValue (org.knime.core.data.DoubleValue)14 BufferedDataTable (org.knime.core.node.BufferedDataTable)13 DataColumnSpec (org.knime.core.data.DataColumnSpec)11 ArrayList (java.util.ArrayList)9 DefaultRow (org.knime.core.data.def.DefaultRow)8 PreparedStatement (java.sql.PreparedStatement)7 DataType (org.knime.core.data.DataType)6 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)6 HashSet (java.util.HashSet)5 Random (java.util.Random)5 TimeZone (java.util.TimeZone)5 DataTable (org.knime.core.data.DataTable)5 DoubleCell (org.knime.core.data.def.DoubleCell)5 StringCell (org.knime.core.data.def.StringCell)5 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)5