Search in sources :

Example 16 with DataContainer

use of org.knime.core.data.container.DataContainer in project knime-core by knime.

the class NextValidValueStatisticTB method init.

/**
 * {@inheritDoc}
 */
@Override
protected void init(final DataTableSpec spec, final int amountOfColumns) {
    m_index = spec.findColumnIndex(m_columnName);
    m_nextCells = new DataContainer(new DataTableSpec(spec.getColumnSpec(m_index)));
}
Also used : DataContainer(org.knime.core.data.container.DataContainer) DataTableSpec(org.knime.core.data.DataTableSpec)

Example 17 with DataContainer

use of org.knime.core.data.container.DataContainer 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 18 with DataContainer

use of org.knime.core.data.container.DataContainer in project knime-core by knime.

the class DataColumnPropertiesView method createPropsTable.

private DataTable createPropsTable(final DataTableSpec tableSpec) {
    // output has as many cols
    int numOfCols = tableSpec.getNumColumns();
    String[] colNames = new String[numOfCols];
    DataType[] colTypes = new DataType[numOfCols];
    // colnames are the same as incoming, types are all StringTypes
    for (int c = 0; c < numOfCols; c++) {
        colNames[c] = tableSpec.getColumnSpec(c).getName();
        colTypes[c] = StringCell.TYPE;
    }
    // get keys for ALL props in the table. Each will show in one row.
    HashSet<String> allKeys = new LinkedHashSet<String>();
    for (int c = 0; c < numOfCols; c++) {
        Enumeration<String> props = tableSpec.getColumnSpec(c).getProperties().properties();
        while (props.hasMoreElements()) {
            allKeys.add(props.nextElement());
        }
    }
    DataContainer result = new DataContainer(new DataTableSpec(colNames, colTypes));
    // now construct the rows we wanna display
    for (String key : allKeys) {
        DataCell[] cells = new DataCell[numOfCols];
        for (int c = 0; c < numOfCols; c++) {
            String cellValue = "";
            if (tableSpec.getColumnSpec(c).getProperties().containsProperty(key)) {
                cellValue = tableSpec.getColumnSpec(c).getProperties().getProperty(key);
            }
            cells[c] = new StringCell(cellValue);
        }
        result.addRowToTable(new DefaultRow(key, cells));
    }
    result.close();
    return result.getTable();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataTableSpec(org.knime.core.data.DataTableSpec) DataContainer(org.knime.core.data.container.DataContainer) StringCell(org.knime.core.data.def.StringCell) DataType(org.knime.core.data.DataType) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 19 with DataContainer

use of org.knime.core.data.container.DataContainer in project knime-core by knime.

the class SQLExtractNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    DatabasePortObject dbIn = (DatabasePortObject) inData[0];
    String query = dbIn.getConnectionSettings(getCredentialsProvider()).getQuery();
    final String flowVarName = m_flowVariableName.getStringValue();
    pushFlowVariableString(flowVarName, query);
    // Create a table with the SQL query in a StringCell
    DataContainer container = exec.createDataContainer(createSpec(flowVarName));
    container.addRowToTable(new DefaultRow(RowKey.createRowKey(0), new StringCell(query)));
    container.close();
    BufferedDataTable outTable = (BufferedDataTable) container.getTable();
    return new PortObject[] { FlowVariablePortObject.INSTANCE, outTable };
}
Also used : DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) DataContainer(org.knime.core.data.container.DataContainer) StringCell(org.knime.core.data.def.StringCell) BufferedDataTable(org.knime.core.node.BufferedDataTable) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DefaultRow(org.knime.core.data.def.DefaultRow) FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) PortObject(org.knime.core.node.port.PortObject)

Example 20 with DataContainer

use of org.knime.core.data.container.DataContainer in project knime-core by knime.

the class Statistics3Table method createNominalValueTable.

/**
 * Create nominal value table containing all possible values together with their occurrences.
 *
 * @param nominal value output table
 * @return data table with nominal values for each column
 */
public DataTable createNominalValueTable(final List<String> nominal) {
    DataTableSpec outSpec = createOutSpecNominal(m_spec, nominal);
    @SuppressWarnings("unchecked") Iterator<Entry<DataCell, Integer>>[] it = new Iterator[(outSpec.getNumColumns() / 3)];
    long[] totals = new long[it.length];
    for (int i = 0, index = 0; i < m_nominalValues.size(); i++) {
        Map<DataCell, Integer> currentMap = m_nominalValues.get(i);
        if (currentMap != null) {
            it[index] = currentMap.entrySet().iterator();
            totals[index] = currentMap.values().stream().collect(Collectors.summingLong(Integer::valueOf));
            index += 1;
        }
    }
    DataContainer cont = new DataContainer(outSpec, true);
    int rowIndex = 0;
    do {
        boolean addEnd = true;
        DataCell[] cells = new DataCell[3 * it.length];
        for (int i = 0; i < it.length; i++) {
            if (it[i].hasNext()) {
                Map.Entry<DataCell, Integer> e = it[i].next();
                cells[3 * i] = e.getKey();
                int count = e.getValue().intValue();
                cells[3 * i + 1] = new IntCell(count);
                cells[3 * i + 2] = new DoubleCell((double) count / totals[i]);
                addEnd = false;
            } else {
                cells[3 * i] = DataType.getMissingCell();
                cells[3 * i + 1] = DataType.getMissingCell();
                cells[3 * i + 2] = DataType.getMissingCell();
            }
        }
        if (addEnd) {
            break;
        }
        cont.addRowToTable(new DefaultRow(RowKey.createRowKey(rowIndex++), cells));
    } while (true);
    cont.close();
    return cont.getTable();
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DoubleCell(org.knime.core.data.def.DoubleCell) IntCell(org.knime.core.data.def.IntCell) MutableInteger(org.knime.core.util.MutableInteger) DataContainer(org.knime.core.data.container.DataContainer) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) Iterator(java.util.Iterator) RowIterator(org.knime.core.data.RowIterator) DataCell(org.knime.core.data.DataCell) BlobWrapperDataCell(org.knime.core.data.container.BlobWrapperDataCell) DefaultRow(org.knime.core.data.def.DefaultRow) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

DataContainer (org.knime.core.data.container.DataContainer)35 DataTableSpec (org.knime.core.data.DataTableSpec)25 DefaultRow (org.knime.core.data.def.DefaultRow)21 DataRow (org.knime.core.data.DataRow)19 DataCell (org.knime.core.data.DataCell)17 BufferedDataTable (org.knime.core.node.BufferedDataTable)15 RowKey (org.knime.core.data.RowKey)10 ArrayList (java.util.ArrayList)9 DoubleCell (org.knime.core.data.def.DoubleCell)9 IntCell (org.knime.core.data.def.IntCell)8 LinkedHashMap (java.util.LinkedHashMap)7 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)7 HashSet (java.util.HashSet)6 DataColumnSpec (org.knime.core.data.DataColumnSpec)6 RowIterator (org.knime.core.data.RowIterator)6 StringCell (org.knime.core.data.def.StringCell)6 Map (java.util.Map)5 Set (java.util.Set)5 SortedTable (org.knime.base.data.sort.SortedTable)5 DataTable (org.knime.core.data.DataTable)5