use of org.knime.core.data.DataTable in project knime-core by knime.
the class PCAApplyNodeModel method execute.
/**
* Performs the PCA.
*
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
final PCAModelPortObject model = (PCAModelPortObject) inData[MODEL_INPORT];
final int dimensions = m_dimSelection.getNeededDimensions();
if (dimensions == -1) {
throw new IllegalArgumentException("Number of dimensions not correct configured");
}
if (m_failOnMissingValues.getBooleanValue()) {
for (final DataRow row : (DataTable) inData[DATA_INPORT]) {
for (int i = 0; i < m_inputColumnIndices.length; i++) {
if (row.getCell(m_inputColumnIndices[i]).isMissing()) {
throw new IllegalArgumentException("data table contains missing values");
}
}
}
}
final Matrix eigenvectors = EigenValue.getSortedEigenVectors(model.getEigenVectors(), model.getEigenvalues(), dimensions);
final DataColumnSpec[] specs = PCANodeModel.createAddTableSpec((DataTableSpec) inData[DATA_INPORT].getSpec(), dimensions);
final int dim = dimensions;
final CellFactory fac = new CellFactory() {
@Override
public DataCell[] getCells(final DataRow row) {
return PCANodeModel.convertInputRow(eigenvectors, row, model.getCenter(), m_inputColumnIndices, dim, m_failOnMissingValues.getBooleanValue());
}
@Override
public DataColumnSpec[] getColumnSpecs() {
return specs;
}
@Override
public void setProgress(final int curRowNr, final int rowCount, final RowKey lastKey, final ExecutionMonitor texec) {
texec.setProgress((double) curRowNr / rowCount, "converting input row " + curRowNr + " of " + rowCount);
}
};
final ColumnRearranger cr = new ColumnRearranger((DataTableSpec) inData[DATA_INPORT].getSpec());
cr.append(fac);
if (m_removeOriginalCols.getBooleanValue()) {
cr.remove(m_inputColumnNames);
}
final BufferedDataTable result = exec.createColumnRearrangeTable((BufferedDataTable) inData[DATA_INPORT], cr, exec);
final PortObject[] out = { result };
return out;
}
use of org.knime.core.data.DataTable in project knime-core by knime.
the class EndcaseNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
Vector<BufferedDataTable> tables = new Vector<BufferedDataTable>();
for (int i = 0; i < getNrInPorts(); i++) {
if (inData[i] != null) {
// if connected...
if (!(inData[i] instanceof InactiveBranchPortObject)) {
// ...and active, add it:
tables.add((BufferedDataTable) inData[i]);
}
}
}
if (tables.size() == 0) {
// be connected!)
assert inData[0] instanceof InactiveBranchPortObject;
if (m_enableHiliting) {
// create empty hilite translation map (so we correctly
// handle the internals).
Map<RowKey, Set<RowKey>> map = new HashMap<RowKey, Set<RowKey>>();
m_hiliteTranslator.setMapper(new DefaultHiLiteMapper(map));
}
return new PortObject[] { inData[0] };
}
assert tables.size() > 0;
// check compatibility of specs against first spec in list
for (int i = 1; i < tables.size(); i++) {
if (!(tables.get(0).getSpec().equalStructure(tables.get(i).getSpec()))) {
// incompatible - refuse to execute
throw new Exception("The data table structures of the active " + "ports are not compatible.");
}
}
int totalRowCount = 0;
DataTable[] dtables = new DataTable[tables.size()];
int i = 0;
for (BufferedDataTable t : tables) {
totalRowCount += t.getRowCount();
dtables[i] = t;
i++;
}
AppendedRowsTable out = new AppendedRowsTable((m_isAppendSuffix ? m_suffix : null), dtables);
// note, this iterator throws runtime exceptions when canceled.
AppendedRowsIterator it = out.iterator(exec, totalRowCount);
BufferedDataContainer c = exec.createDataContainer(out.getDataTableSpec());
try {
while (it.hasNext()) {
// may throw exception, also sets progress
c.addRowToTable(it.next());
}
} catch (RuntimeCanceledExecutionException rcee) {
throw rcee.getCause();
} finally {
c.close();
}
if (it.getNrRowsSkipped() > 0) {
setWarningMessage("Filtered out " + it.getNrRowsSkipped() + " duplicate row id(s).");
}
if (m_enableHiliting) {
// create hilite translation map
Map<RowKey, Set<RowKey>> map = new HashMap<RowKey, Set<RowKey>>();
// map of all RowKeys and duplicate RowKeys in the resulting table
Map<RowKey, RowKey> dupMap = it.getDuplicateNameMap();
for (Map.Entry<RowKey, RowKey> e : dupMap.entrySet()) {
// if a duplicate key
if (!e.getKey().equals(e.getValue())) {
Set<RowKey> set = Collections.singleton(e.getValue());
// put duplicate key and original key into map
map.put(e.getKey(), set);
} else {
// skip duplicate keys
if (!dupMap.containsKey(new RowKey(e.getKey().getString() + m_suffix))) {
Set<RowKey> set = Collections.singleton(e.getValue());
map.put(e.getKey(), set);
}
}
}
m_hiliteTranslator.setMapper(new DefaultHiLiteMapper(map));
}
return new BufferedDataTable[] { c.getTable() };
}
use of org.knime.core.data.DataTable in project knime-core by knime.
the class CorrelationComputeNodeView method modelChanged.
/**
* {@inheritDoc}
*/
@Override
protected void modelChanged() {
DataTable table = getNodeModel().getCorrelationTable();
tableChanged(table);
}
use of org.knime.core.data.DataTable in project knime-core by knime.
the class ReadTableNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
String warning = CheckUtils.checkSourceFile(m_fileName.getStringValue());
if (warning != null) {
setWarningMessage(warning);
}
InputStream in = null;
try {
in = openInputStream();
DataTableSpec spec = peekDataTableSpec(in);
if (spec == null) {
// if written with 1.3.x and before
in.close();
in = openInputStream();
LOGGER.debug("Table spec is not first entry in input file, " + "need to deflate entire file");
DataTable outTable = DataContainer.readFromStream(in);
spec = outTable.getDataTableSpec();
}
return new DataTableSpec[] { spec };
} catch (IOException ioe) {
String message = ioe.getMessage();
if (message == null) {
message = "Unable to read spec from file, " + "no detailed message available.";
}
throw new InvalidSettingsException(message);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException ioe) {
// ignore
}
}
}
}
use of org.knime.core.data.DataTable in project knime-core by knime.
the class HiLiteCollectorNodeView method modelChanged.
/**
* {@inheritDoc}
*/
@Override
public void modelChanged() {
DataTable data = super.getNodeModel().getHiLiteAnnotationsTable();
m_table.setDataTable(data);
HiLiteHandler hdl = super.getNodeModel().getInHiLiteHandler(0);
m_table.setHiLiteHandler(hdl);
m_table.setColumnWidth(50);
}
Aggregations