use of org.knime.core.data.DataTable in project knime-core by knime.
the class TableSorterWorker method done.
/**
* {@inheritDoc}
*/
@Override
protected void done() {
m_progBar.dispose();
if (isCancelled()) {
return;
}
DataTable sortedTable;
try {
sortedTable = get();
} catch (InterruptedException e) {
LOGGER.debug("Interactive table sorting cancelled");
return;
// cancelled, ignore
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof CanceledExecutionException) {
LOGGER.debug("Interactive table sorting cancelled");
return;
}
if (cause == null) {
cause = e;
}
String error = "Error sorting table: " + cause.getMessage();
LOGGER.error(error, e);
JOptionPane.showMessageDialog(m_parentComponent.getRootPane(), error + "\nSee log files for details", "Sort error", JOptionPane.ERROR_MESSAGE);
return;
}
m_cntModel.setDataTableOnSort(sortedTable, m_sortOrder);
}
use of org.knime.core.data.DataTable in project knime-core by knime.
the class TreeDataCreator method readData.
/**
* Reads the data from <b>learnData</b> into memory.
* Each column is represented by a TreeColumnData object corresponding to its type
* and whether it is a attribute or target column.
*
* @param learnData
* @param configuration
* @param exec
* @return the TreeData object that holds all data in memory
* @throws CanceledExecutionException
*/
public TreeData readData(final BufferedDataTable learnData, final TreeEnsembleLearnerConfiguration configuration, final ExecutionMonitor exec) throws CanceledExecutionException {
if (learnData.size() <= 1) {
throw new IllegalArgumentException("The input table must contain at least 2 rows!");
}
int index = 0;
final long nrRows = learnData.size();
final int nrLearnCols = m_attrColCreators.length;
final boolean[] supportMissings = new boolean[nrLearnCols];
for (int i = 0; i < nrLearnCols; i++) {
supportMissings[i] = m_attrColCreators[i].acceptsMissing();
}
int rejectedMissings = 0;
final int nrHilitePatterns = m_configuration.getNrHilitePatterns();
// sort learnData according to the target column to enable equal size sampling
final int targetColIdx = learnData.getDataTableSpec().findColumnIndex(m_configuration.getTargetColumn());
Comparator<DataCell> targetComp = learnData.getDataTableSpec().getColumnSpec(targetColIdx).getType().getComparator();
DataTableSorter sorter = new DataTableSorter(learnData, learnData.size(), new Comparator<DataRow>() {
@Override
public int compare(final DataRow arg0, final DataRow arg1) {
return targetComp.compare(arg0.getCell(targetColIdx), arg1.getCell(targetColIdx));
}
});
final ExecutionMonitor sortExec = exec.createSubProgress(0.5);
final DataTable sortedTable = sorter.sort(sortExec);
final ExecutionMonitor readExec = exec.createSubProgress(0.5);
for (DataRow r : sortedTable) {
double progress = index / (double) nrRows;
readExec.setProgress(progress, "Row " + index + " of " + nrRows + " (\"" + r.getKey() + "\")");
readExec.checkCanceled();
boolean shouldReject = false;
for (int i = 0; i < nrLearnCols; i++) {
DataCell c = r.getCell(i);
if (c.isMissing() && !supportMissings[i]) {
shouldReject = true;
break;
}
}
DataCell targetCell = r.getCell(nrLearnCols);
if (targetCell.isMissing()) {
shouldReject = true;
}
if (shouldReject) {
rejectedMissings += 1;
continue;
}
if (index < nrHilitePatterns) {
m_dataRowsForHiliteContainer.addRowToTable(r);
}
final RowKey key = r.getKey();
for (int i = 0; i < nrLearnCols; i++) {
DataCell c = r.getCell(i);
m_attrColCreators[i].add(key, c);
}
m_targetColCreator.add(key, targetCell);
index++;
}
if (nrHilitePatterns > 0 && index > nrHilitePatterns) {
m_viewMessage = "Hilite (& color graphs) are based on a subset of " + "the data (" + nrHilitePatterns + "/" + index + ")";
}
if (rejectedMissings > 0) {
StringBuffer warnMsgBuilder = new StringBuffer();
warnMsgBuilder.append(rejectedMissings).append("/");
warnMsgBuilder.append(learnData.size());
warnMsgBuilder.append(" row(s) were ignored because they ");
warnMsgBuilder.append("contain missing values.");
m_warningMessage = warnMsgBuilder.toString();
}
CheckUtils.checkArgument(rejectedMissings < learnData.size(), "No rows left after removing missing values (table has %d row(s))", learnData.size());
int nrLearnAttributes = 0;
for (int i = 0; i < m_attrColCreators.length; i++) {
nrLearnAttributes += m_attrColCreators[i].getNrAttributes();
}
TreeAttributeColumnData[] columns = new TreeAttributeColumnData[nrLearnAttributes];
int learnAttributeIndex = 0;
for (int i = 0; i < m_attrColCreators.length; i++) {
TreeAttributeColumnDataCreator creator = m_attrColCreators[i];
for (int a = 0; a < creator.getNrAttributes(); a++) {
final TreeAttributeColumnData columnData = creator.createColumnData(a, configuration);
columnData.getMetaData().setAttributeIndex(learnAttributeIndex);
columns[learnAttributeIndex++] = columnData;
}
}
TreeTargetColumnData targetCol = m_targetColCreator.createColumnData();
return new TreeData(columns, targetCol, m_treeType);
}
use of org.knime.core.data.DataTable in project knime-core by knime.
the class AppendedRowsTableTest method testAppendedRowsTableDataTableArray.
/**
* Class under test for void AppendedRowsTable(DataTable[]).
*/
public void testAppendedRowsTableDataTableArray() {
DataTable firstTable = new DefaultTable(DATA, DATA_H, DATA_TYPES);
DataTable firstTableMissing = new DefaultTable(DATA_MISS_LAST, DATA_MISS_LAST_H, DATA_MISS_LAST_TYPES);
DataTable firstTableShuffle = new DefaultTable(DATA_SHUFFLE, DATA_SHUFFLE_H, DATA_SHUFFLE_TYPES);
DataTable secondTable = new DefaultTable(DATA_2, DATA_H, DATA_TYPES);
new AppendedRowsTable(firstTable, secondTable);
try {
new AppendedRowsTable(firstTable, null);
fail();
} catch (NullPointerException npe) {
// do nothing
}
try {
new AppendedRowsTable((DataTable) null, secondTable);
fail();
} catch (NullPointerException npe) {
// do nothing
}
new AppendedRowsTable(new DataTable[] { firstTableMissing, secondTable });
new AppendedRowsTable(new DataTable[] { firstTable, firstTableShuffle });
}
use of org.knime.core.data.DataTable in project knime-core by knime.
the class AppendedRowsTableTest method testGetDataTableSpec.
/**
* Test method for getDataTableSpec().
*/
public void testGetDataTableSpec() {
DataTable firstTable = new DefaultTable(DATA, DATA_H, DATA_TYPES);
DataTable firstTableShuffle = new DefaultTable(DATA_SHUFFLE, DATA_SHUFFLE_H, DATA_SHUFFLE_TYPES);
DataTable ap = new AppendedRowsTable(new DataTable[] { firstTable, firstTableShuffle });
assertTrue(ap.getDataTableSpec().equalStructure(firstTable.getDataTableSpec()));
}
use of org.knime.core.data.DataTable in project knime-core by knime.
the class JoinedTableTest method testMergedTable.
/**
* Test for constructor.
*/
public final void testMergedTable() {
DataColumnSpec[] leftCols = new DataColumnSpec[3];
DataColumnSpec[] rightCols = new DataColumnSpec[3];
System.arraycopy(COLS, 0, leftCols, 0, 3);
System.arraycopy(COLS, 3, rightCols, 0, 3);
DataTable leftTable = new DefaultTable(new DataRow[0], new DataTableSpec(leftCols));
DataTable rightTable = new DefaultTable(new DataRow[0], new DataTableSpec(rightCols));
new JoinedTable(leftTable, rightTable);
try {
new JoinedTable(null, rightTable);
fail();
} catch (NullPointerException ne) {
NodeLogger.getLogger(JoinedTableTest.class).debug("Got expected exception: " + ne.getClass(), ne);
}
try {
new JoinedTable(leftTable, null);
fail();
} catch (NullPointerException ne) {
NodeLogger.getLogger(JoinedTableTest.class).debug("Got expected exception: " + ne.getClass(), ne);
}
try {
new JoinedTable(leftTable, leftTable);
fail();
} catch (IllegalArgumentException iae) {
NodeLogger.getLogger(JoinedTableTest.class).debug("Got expected exception: " + iae.getClass(), iae);
}
try {
new JoinedTable(leftTable, leftTable);
fail();
} catch (IllegalArgumentException iae) {
NodeLogger.getLogger(JoinedTableTest.class).debug("Got expected exception: " + iae.getClass(), iae);
}
rightCols[1] = leftCols[2];
rightTable = new DefaultTable(new DataRow[0], new DataTableSpec(rightCols));
try {
new JoinedTable(leftTable, rightTable);
fail();
} catch (IllegalArgumentException iae) {
NodeLogger.getLogger(JoinedTableTest.class).debug("Got expected exception: " + iae.getClass(), iae);
}
}
Aggregations