use of org.knime.core.data.def.StringCell in project knime-core by knime.
the class OneSampleTTestStatistics method getDescStats.
/**
* Get descriptive statistics for the given column
* @param rowID the row key
* @param column the name of the column
* @param stats the statistics of the column
* @param missing the missing values in this column
* @return a DataRow with descriptive statistics
*/
private List<DataCell> getDescStats(final String column, final SummaryStatistics stats, final MutableInteger missing) {
List<DataCell> cells = new ArrayList<DataCell>();
cells.add(new StringCell(column));
cells.add(new IntCell((int) stats.getN()));
cells.add(new IntCell(missing.intValue()));
cells.add(new DoubleCell(stats.getMean()));
cells.add(new DoubleCell(stats.getStandardDeviation()));
cells.add(new DoubleCell(StatsUtil.getStandardError(stats)));
return cells;
}
use of org.knime.core.data.def.StringCell in project knime-core by knime.
the class AppendVariableToTableNodeModel method createColumnRearranger.
private ColumnRearranger createColumnRearranger(final DataTableSpec spec) throws InvalidSettingsException {
ColumnRearranger arranger = new ColumnRearranger(spec);
Set<String> nameHash = new HashSet<String>();
for (DataColumnSpec c : spec) {
nameHash.add(c.getName());
}
List<Pair<String, FlowVariable.Type>> vars;
if (m_settings.getIncludeAll()) {
vars = getAllVariables();
} else {
vars = m_settings.getVariablesOfInterest();
}
if (vars.isEmpty()) {
throw new InvalidSettingsException("No variables selected");
}
DataColumnSpec[] specs = new DataColumnSpec[vars.size()];
final DataCell[] values = new DataCell[vars.size()];
for (int i = 0; i < vars.size(); i++) {
Pair<String, FlowVariable.Type> c = vars.get(i);
String name = c.getFirst();
DataType type;
switch(c.getSecond()) {
case DOUBLE:
type = DoubleCell.TYPE;
try {
double dValue = peekFlowVariableDouble(name);
values[i] = new DoubleCell(dValue);
} catch (NoSuchElementException e) {
throw new InvalidSettingsException("No such flow variable (of type double): " + name);
}
break;
case INTEGER:
type = IntCell.TYPE;
try {
int iValue = peekFlowVariableInt(name);
values[i] = new IntCell(iValue);
} catch (NoSuchElementException e) {
throw new InvalidSettingsException("No such flow variable (of type int): " + name);
}
break;
case STRING:
type = StringCell.TYPE;
try {
String sValue = peekFlowVariableString(name);
sValue = sValue == null ? "" : sValue;
values[i] = new StringCell(sValue);
} catch (NoSuchElementException e) {
throw new InvalidSettingsException("No such flow variable (of type String): " + name);
}
break;
default:
throw new InvalidSettingsException("Unsupported variable type: " + c.getSecond());
}
if (nameHash.contains(name) && !name.toLowerCase().endsWith("(variable)")) {
name = name.concat(" (variable)");
}
String newName = name;
int uniquifier = 1;
while (!nameHash.add(newName)) {
newName = name + " (#" + (uniquifier++) + ")";
}
specs[i] = new DataColumnSpecCreator(newName, type).createSpec();
}
arranger.append(new AbstractCellFactory(specs) {
/**
* {@inheritDoc}
*/
@Override
public DataCell[] getCells(final DataRow row) {
return values;
}
});
return arranger;
}
use of org.knime.core.data.def.StringCell in project knime-core by knime.
the class ListFiles method addLocationToContainer.
/**
* Adds a File to the table.
*
* @param file
*/
private void addLocationToContainer(final File file) {
try {
DataCell[] row = new DataCell[2];
row[0] = new StringCell(file.getAbsolutePath());
row[1] = new StringCell(file.getAbsoluteFile().toURI().toURL().toString());
m_dc.addRowToTable(new DefaultRow("Row " + m_currentRowID, row));
m_currentRowID++;
} catch (MalformedURLException e) {
LOGGER.error("Unable to URL to file " + file.getAbsolutePath(), e);
}
}
use of org.knime.core.data.def.StringCell in project knime-core by knime.
the class SVMPredictor method getCells.
/**
* {@inheritDoc}
*/
@Override
public DataCell[] getCells(final DataRow row) {
ArrayList<Double> values = new ArrayList<Double>();
for (int i = 0; i < m_colindices.length; i++) {
if (row.getCell(m_colindices[i]).isMissing()) {
return new DataCell[] { DataType.getMissingCell() };
}
DoubleValue dv = (DoubleValue) row.getCell(m_colindices[i]);
values.add(dv.getDoubleValue());
}
String classvalue = doPredict(values);
return new DataCell[] { new StringCell(classvalue) };
}
use of org.knime.core.data.def.StringCell in project knime-core by knime.
the class ColCombineNodeModel method createColumnRearranger.
private ColumnRearranger createColumnRearranger(final DataTableSpec spec) {
ColumnRearranger result = new ColumnRearranger(spec);
DataColumnSpec append = new DataColumnSpecCreator(m_newColName, StringCell.TYPE).createSpec();
final int[] indices = new int[m_columns.length];
List<String> colNames = Arrays.asList(m_columns);
int j = 0;
for (int k = 0; k < spec.getNumColumns(); k++) {
DataColumnSpec cs = spec.getColumnSpec(k);
if (colNames.contains(cs.getName())) {
indices[j] = k;
j++;
}
}
// ", " -> ","
// " " -> " " (do not let the resulting string be empty)
// " bla bla " -> "bla bla"
final String delimTrim = trimDelimString(m_delimString);
result.append(new SingleCellFactory(append) {
@Override
public DataCell getCell(final DataRow row) {
String[] cellContents = new String[indices.length];
for (int i = 0; i < indices.length; i++) {
DataCell c = row.getCell(indices[i]);
String s = c instanceof StringValue ? ((StringValue) c).getStringValue() : c.toString();
cellContents[i] = s;
}
return new StringCell(handleContent(cellContents, delimTrim));
}
});
return result;
}
Aggregations