Search in sources :

Example 86 with StringCell

use of org.knime.core.data.def.StringCell in project knime-core by knime.

the class ExpressionFactoryTest method testConstantStringDataType.

/**
 * Test method for {@link ExpressionFactory#constant(String, DataType)} .
 */
@Test
public void testConstantStringDataType() {
    final Expression hello = m_factory.constant("Hello", StringCell.TYPE);
    assertTrue(hello.isConstant());
    final ExpressionValue mockResult = hello.evaluate(m_rows[0], null);
    assertEquals(new StringCell("Hello"), mockResult.getValue());
    assertEquals(new StringCell("Hello"), hello.evaluate(m_rows[0], null).getValue());
    assertEquals(Collections.emptyMap(), mockResult.getMatchedObjects());
    final ExpressionValue nullResult = hello.evaluate(null, null);
    assertEquals(new StringCell("Hello"), nullResult.getValue());
    assertEquals(Collections.emptyMap(), nullResult.getMatchedObjects());
}
Also used : StringCell(org.knime.core.data.def.StringCell) Test(org.junit.Test)

Example 87 with StringCell

use of org.knime.core.data.def.StringCell in project knime-core by knime.

the class ExpressionFactoryTest method testColumnRef.

/**
 * Test method for {@link ExpressionFactory#columnRef(DataTableSpec, java.lang.String)} .
 */
@Test
public void testColumnRef() {
    final DefaultRow row0 = new DefaultRow(new RowKey("0"), new IntCell(3));
    final DefaultRow row1 = new DefaultRow(new RowKey("1"), new IntCell(3), new DoubleCell(3.14159));
    final DefaultRow row2 = new DefaultRow(new RowKey("1"), new DoubleCell(3.14159), new StringCell("Hi"));
    final ExpressionValue firstVal = m_factory.columnRef(new DataTableSpec(new String[] { "Num" }, new DataType[] { IntCell.TYPE }), "Num").evaluate(row0, null);
    assertEquals(row0.getCell(0), firstVal.getValue());
    assertEquals(row1.getCell(0), m_factory.columnRef(new DataTableSpec(new String[] { "Num", "Pi" }, new DataType[] { IntCell.TYPE, DoubleCell.TYPE }), "Num").evaluate(row0, null).getValue());
    final ExpressionValue secondVal = m_factory.columnRef(new DataTableSpec(new String[] { "Num", "Pi" }, new DataType[] { IntCell.TYPE, DoubleCell.TYPE }), "Pi").evaluate(row1, null);
    assertEquals(row1.getCell(1), secondVal.getValue());
    final ExpressionValue thirdVal = m_factory.columnRef(new DataTableSpec(new String[] { "Pi", "Greeting" }, new DataType[] { DoubleCell.TYPE, StringCell.TYPE }), "Greeting").evaluate(row2, null);
    assertEquals(row2.getCell(1), thirdVal.getValue());
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) RowKey(org.knime.core.data.RowKey) StringCell(org.knime.core.data.def.StringCell) DoubleCell(org.knime.core.data.def.DoubleCell) DefaultRow(org.knime.core.data.def.DefaultRow) IntCell(org.knime.core.data.def.IntCell) Test(org.junit.Test)

Example 88 with StringCell

use of org.knime.core.data.def.StringCell in project knime-core by knime.

the class MissingValuePanel method getSettings.

/**
 * Get the settings currently entered in the dialog.
 *
 * @return the current settings
 */
public ColSetting getSettings() {
    int method;
    if (m_nothingButton.isSelected()) {
        method = ColSetting.METHOD_NO_HANDLING;
    } else if (m_removeButton.isSelected()) {
        method = ColSetting.METHOD_IGNORE_ROWS;
    } else if (m_fixButton != null && m_fixButton.isSelected()) {
        method = ColSetting.METHOD_FIX_VAL;
        DataCell cell;
        switch(m_setting.getType()) {
            case ColSetting.TYPE_INT:
                Object value = ((JFormattedTextField) m_fixText).getValue();
                cell = new IntCell(((Number) value).intValue());
                break;
            case ColSetting.TYPE_DOUBLE:
                value = ((JFormattedTextField) m_fixText).getValue();
                cell = new DoubleCell(((Number) value).doubleValue());
                break;
            case ColSetting.TYPE_STRING:
                value = ((JComboBox) m_fixText).getEditor().getItem();
                cell = new StringCell(value.toString());
                break;
            default:
                throw new RuntimeException("You shouldn't have come here.");
        }
        m_setting.setFixCell(cell);
    } else if (m_maxButton != null && m_maxButton.isSelected()) {
        method = ColSetting.METHOD_MAX;
    } else if (m_minButton != null && m_minButton.isSelected()) {
        method = ColSetting.METHOD_MIN;
    } else if (m_meanButton != null && m_meanButton.isSelected()) {
        method = ColSetting.METHOD_MEAN;
    } else if (m_mostFrequentButton != null && m_mostFrequentButton.isSelected()) {
        method = ColSetting.METHOD_MOST_FREQUENT;
    } else {
        assert false : "One button must be selected.";
        method = ColSetting.METHOD_NO_HANDLING;
    }
    m_setting.setMethod(method);
    return m_setting;
}
Also used : JComboBox(javax.swing.JComboBox) StringCell(org.knime.core.data.def.StringCell) DoubleCell(org.knime.core.data.def.DoubleCell) JFormattedTextField(javax.swing.JFormattedTextField) DataCell(org.knime.core.data.DataCell) IntCell(org.knime.core.data.def.IntCell)

Example 89 with StringCell

use of org.knime.core.data.def.StringCell in project knime-core by knime.

the class HiLiteCollectorNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    if (m_annotationMap.isEmpty()) {
        return inData;
    }
    DataTableSpec inSpec = (DataTableSpec) inData[0].getSpec();
    final DataColumnSpec[] cspecs = createSpecs(inSpec);
    ColumnRearranger cr = new ColumnRearranger(inSpec);
    cr.append(new CellFactory() {

        /**
         * {@inheritDoc}
         */
        @Override
        public DataCell[] getCells(final DataRow row) {
            if (m_annotationMap.isEmpty()) {
                return new DataCell[0];
            }
            DataCell[] cells = new DataCell[m_lastIndex + 1];
            for (int i = 0; i < cells.length; i++) {
                Map<Integer, String> map = m_annotationMap.get(row.getKey());
                if (map == null) {
                    cells[i] = DataType.getMissingCell();
                } else {
                    String str = map.get(i);
                    if (str == null) {
                        cells[i] = DataType.getMissingCell();
                    } else {
                        cells[i] = new StringCell(str);
                    }
                }
            }
            return cells;
        }

        @Override
        public DataColumnSpec[] getColumnSpecs() {
            return cspecs;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void setProgress(final int curRowNr, final int rowCount, final RowKey lastKey, final ExecutionMonitor em) {
            em.setProgress((double) curRowNr / rowCount);
        }
    });
    return new BufferedDataTable[] { exec.createColumnRearrangeTable((BufferedDataTable) inData[0], cr, exec) };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) RowKey(org.knime.core.data.RowKey) DataRow(org.knime.core.data.DataRow) DataColumnSpec(org.knime.core.data.DataColumnSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) StringCell(org.knime.core.data.def.StringCell) BufferedDataTable(org.knime.core.node.BufferedDataTable) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) CellFactory(org.knime.core.data.container.CellFactory) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 90 with StringCell

use of org.knime.core.data.def.StringCell in project knime-core by knime.

the class BatchExecutor method setNodeOptions.

private static void setNodeOptions(final Collection<Option> options, final WorkflowManager wfm) throws InvalidSettingsException, IllegalOptionException {
    for (Option o : options) {
        int[] idPath = o.m_nodeIDs;
        NodeID subID = new NodeID(wfm.getID(), idPath[0]);
        NodeContainer cont = null;
        try {
            cont = wfm.getNodeContainer(subID);
            for (int i = 1; i < idPath.length; i++) {
                if (cont instanceof WorkflowManager) {
                    WorkflowManager subWM = (WorkflowManager) cont;
                    subID = new NodeID(subID, idPath[i]);
                    cont = subWM.getNodeContainer(subID);
                } else {
                    cont = null;
                }
            }
        } catch (IllegalArgumentException ex) {
            // throw by getNodeContainer if no node with the id exists
            cont = null;
        }
        if (cont == null) {
            LOGGER.warn("No node with id " + Arrays.toString(idPath) + " found.");
        } else {
            WorkflowManager parent = cont.getParent();
            NodeSettings settings = new NodeSettings("something");
            parent.saveNodeSettings(cont.getID(), settings);
            NodeSettings model = settings.getNodeSettings(Node.CFG_MODEL);
            String[] splitName = o.m_name.split("/");
            String name = splitName[splitName.length - 1];
            String[] pathElements = new String[splitName.length - 1];
            System.arraycopy(splitName, 0, pathElements, 0, pathElements.length);
            for (String s : pathElements) {
                model = model.getNodeSettings(s);
            }
            if ("int".equals(o.m_type)) {
                model.addInt(name, Integer.parseInt(o.m_value));
            } else if ("long".equals(o.m_type)) {
                model.addLong(name, Long.parseLong(o.m_value));
            } else if ("short".equals(o.m_type)) {
                model.addShort(name, Short.parseShort(o.m_value));
            } else if ("byte".equals(o.m_type)) {
                model.addByte(name, Byte.parseByte(o.m_value));
            } else if ("boolean".equals(o.m_type)) {
                model.addBoolean(name, Boolean.parseBoolean(o.m_value));
            } else if ("char".equals(o.m_type)) {
                model.addChar(name, o.m_value.charAt(0));
            } else if ("float".equals(o.m_type) || ("double".equals(o.m_type))) {
                model.addDouble(name, Double.parseDouble(o.m_value));
            } else if ("String".equals(o.m_type)) {
                model.addString(name, o.m_value);
            } else if ("StringCell".equals(o.m_type)) {
                model.addDataCell(name, new StringCell(o.m_value));
            } else if ("DoubleCell".equals(o.m_type)) {
                double d = Double.parseDouble(o.m_value);
                model.addDataCell(name, new DoubleCell(d));
            } else if ("IntCell".equals(o.m_type)) {
                int i = Integer.parseInt(o.m_value);
                model.addDataCell(name, new IntCell(i));
            } else if ("LongCell".equals(o.m_type)) {
                long i = Long.parseLong(o.m_value);
                model.addDataCell(name, new LongCell(i));
            } else {
                throw new IllegalOptionException("Unknown option type for " + o.m_name + ": " + o.m_type);
            }
            parent.loadNodeSettings(cont.getID(), settings);
        }
    }
}
Also used : DoubleCell(org.knime.core.data.def.DoubleCell) IntCell(org.knime.core.data.def.IntCell) NodeSettings(org.knime.core.node.NodeSettings) LongCell(org.knime.core.data.def.LongCell) StringCell(org.knime.core.data.def.StringCell)

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