use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class Statistics2Table 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);
Iterator[] it = new Iterator[outSpec.getNumColumns() / 2];
int idx = 0;
for (int i = 0; i < m_nominalValues.length; i++) {
if (m_nominalValues[i] != null) {
it[idx++] = m_nominalValues[i].entrySet().iterator();
}
}
DataContainer cont = new DataContainer(outSpec);
int rowIndex = 0;
do {
boolean addEnd = true;
DataCell[] cells = new DataCell[2 * it.length];
for (int i = 0; i < it.length; i++) {
if (it[i] != null && it[i].hasNext()) {
Map.Entry<DataCell, Integer> e = (Map.Entry<DataCell, Integer>) it[i].next();
cells[2 * i] = e.getKey();
cells[2 * i + 1] = new IntCell(e.getValue());
addEnd = false;
} else {
cells[2 * i] = DataType.getMissingCell();
cells[2 * i + 1] = DataType.getMissingCell();
}
}
if (addEnd) {
break;
}
cont.addRowToTable(new DefaultRow(RowKey.createRowKey(rowIndex++), cells));
} while (true);
cont.close();
return cont.getTable();
}
use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class Statistics2Table method load.
/**
* Load a new statistic table by the given settings object.
* @param sett to load this table from
* @return a new statistic table
* @throws InvalidSettingsException if the settings are corrupt
*/
public static Statistics2Table load(final NodeSettingsRO sett) throws InvalidSettingsException {
DataTableSpec spec = DataTableSpec.load(sett.getConfig("spec"));
Map<DataCell, Integer>[] nominalValues = new Map[spec.getNumColumns()];
for (int c = 0; c < nominalValues.length; c++) {
String name = spec.getColumnSpec(c).getName();
if (!sett.containsKey(name)) {
nominalValues[c] = null;
} else {
nominalValues[c] = new LinkedHashMap<DataCell, Integer>();
NodeSettingsRO subSett = sett.getNodeSettings(name);
for (String key : subSett.keySet()) {
NodeSettingsRO nomSett = subSett.getNodeSettings(key);
nominalValues[c].put(nomSett.getDataCell("key"), nomSett.getInt("value"));
}
}
}
double[] min = sett.getDoubleArray("minimum");
double[] max = sett.getDoubleArray("maximum");
double[] mean = sett.getDoubleArray("mean");
double[] var = sett.getDoubleArray("variance");
double[] median = sett.getDoubleArray("median");
double[] missings = sett.getDoubleArray("missings");
double[] sums = sett.getDoubleArray("sums");
// added with 2.7, fallback -1
int rowCount = sett.getInt("row_count", -1);
return new Statistics2Table(spec, min, max, mean, median, var, sums, missings, nominalValues, rowCount);
}
use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class ReadPNGFromURLNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
ColumnRearranger rearranger = createColumnRearranger(inSpecs[0], new AtomicLong());
DataTableSpec out = rearranger.createSpec();
return new DataTableSpec[] { out };
}
use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class ReadPNGFromURLNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
DataTableSpec spec = inData[0].getDataTableSpec();
AtomicLong failCount = new AtomicLong();
ColumnRearranger rearranger = createColumnRearranger(spec, failCount);
BufferedDataTable out = exec.createColumnRearrangeTable(inData[0], rearranger, exec);
long rowCount = out.size();
long fail = failCount.get();
if (rowCount > 0 && rowCount == fail) {
throw new Exception("None of the URLs could be read " + "as PNG (see log for details)");
} else if (fail > 0) {
setWarningMessage("Failed to read " + fail + "/" + rowCount + " files");
}
return new BufferedDataTable[] { out };
}
use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class AppendVariableToTableNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
BufferedDataTable t = (BufferedDataTable) inData[1];
DataTableSpec ts = t.getSpec();
ColumnRearranger ar = createColumnRearranger(ts);
BufferedDataTable out = exec.createColumnRearrangeTable(t, ar, exec);
return new BufferedDataTable[] { out };
}
Aggregations