use of org.knime.core.data.RowKey in project knime-core by knime.
the class SubgroupMinerModel method preprocess.
private List<BitVectorValue> preprocess(final DataTable inData, final ExecutionMonitor exec) throws CanceledExecutionException {
// TODO: check in configure that only Double values are in the table
m_tidRowKeyMapping = new HashMap<Integer, RowKey>();
m_nrOfRows = 0;
int totalNrRows = ((BufferedDataTable) inData).getRowCount();
m_maxBitsetLength = 0;
List<BitVectorValue> bitSets = new ArrayList<BitVectorValue>();
int bitVectorIndex = inData.getDataTableSpec().findColumnIndex(m_bitVectorColumn.getStringValue());
if (bitVectorIndex < 0) {
return new ArrayList<BitVectorValue>();
}
for (RowIterator itr = inData.iterator(); itr.hasNext(); ) {
exec.checkCanceled();
DataRow currRow = itr.next();
DataCell dc = currRow.getCell(bitVectorIndex);
if (dc.isMissing()) {
continue;
}
BitVectorValue currCell = ((BitVectorValue) currRow.getCell(bitVectorIndex));
if (currCell.length() > Integer.MAX_VALUE) {
throw new IllegalArgumentException("bit vector in row " + currRow.getKey().getString() + " is too long: " + currCell.length() + ". Only bit vectors up to " + Integer.MAX_VALUE + " are supported by this node.");
}
m_maxBitsetLength = Math.max(m_maxBitsetLength, (int) currCell.length());
bitSets.add(currCell);
m_tidRowKeyMapping.put(m_nrOfRows, currRow.getKey());
m_nrOfRows++;
exec.setProgress((double) m_nrOfRows / (double) totalNrRows, "preprocessing......." + m_nrOfRows);
}
LOGGER.debug("max length: " + m_maxBitsetLength);
return bitSets;
}
use of org.knime.core.data.RowKey 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) };
}
use of org.knime.core.data.RowKey in project knime-core by knime.
the class HiLiteCollectorNodeModel method loadInternals.
/**
* {@inheritDoc}
*/
@Override
protected void loadInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
this.reset();
File f = new File(nodeInternDir, KEY_ANNOTATIONS);
NodeSettingsRO sett = NodeSettings.loadFromXML(new FileInputStream(f));
RowKey[] rowKeys = sett.getRowKeyArray("row_keys", (RowKey[]) null);
if (rowKeys != null) {
for (RowKey key : rowKeys) {
try {
NodeSettingsRO subSett = sett.getNodeSettings(key.toString());
Map<Integer, String> map = new LinkedHashMap<Integer, String>();
for (String i : subSett.keySet()) {
try {
int idx = Integer.parseInt(i);
m_lastIndex = (m_lastIndex == null ? idx : Math.max(m_lastIndex, idx));
map.put(idx, subSett.getString(i));
} catch (InvalidSettingsException ise) {
// ignored
}
}
m_annotationMap.put(key, map);
} catch (InvalidSettingsException ise) {
// ignored
}
}
}
}
use of org.knime.core.data.RowKey in project knime-core by knime.
the class HiLiteCollectorNodeModel method saveInternals.
/**
* {@inheritDoc}
*/
@Override
protected void saveInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
NodeSettings sett = new NodeSettings(KEY_ANNOTATIONS);
RowKey[] cells = m_annotationMap.keySet().toArray(new RowKey[m_annotationMap.size()]);
sett.addRowKeyArray("row_keys", cells);
for (RowKey cell : cells) {
NodeSettingsWO subSett = sett.addNodeSettings(cell.toString());
for (Map.Entry<Integer, String> e : m_annotationMap.get(cell).entrySet()) {
subSett.addString(e.getKey().toString(), e.getValue());
}
}
File f = new File(nodeInternDir, KEY_ANNOTATIONS);
sett.saveToXML(new FileOutputStream(f));
}
use of org.knime.core.data.RowKey in project knime-core by knime.
the class JoinerNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
BufferedDataContainer dc = exec.createDataContainer(JoinedTable.createSpec(inData[0].getDataTableSpec(), inData[1].getDataTableSpec(), m_method, m_suffix));
DataTable leftTable = inData[0];
DataTable rightTable = inData[1];
// in the output
if (JoinedTable.METHOD_FILTER.equals(m_method)) {
DataTableSpec leftTableSpec = leftTable.getDataTableSpec();
DataTableSpec rightTableSpec = rightTable.getDataTableSpec();
LinkedHashSet<String> leftHash = new LinkedHashSet<String>();
for (DataColumnSpec c : leftTableSpec) {
leftHash.add(c.getName());
}
LinkedHashSet<String> rightHash = new LinkedHashSet<String>();
for (DataColumnSpec c : rightTableSpec) {
rightHash.add(c.getName());
}
rightHash.removeAll(leftHash);
String[] survivors = rightHash.toArray(new String[rightHash.size()]);
if (survivors.length < rightTableSpec.getNumColumns()) {
rightTable = new FilterColumnTable(rightTable, survivors);
}
}
final BitSet rightRows = new BitSet(inData[1].getRowCount());
final LinkedHashMap<RowKey, SoftReference<Helper>> map = new LinkedHashMap<RowKey, SoftReference<Helper>>(1024);
m_leftRows = 0;
m_outputRows = 0;
m_leftIt = null;
m_rightIt = null;
m_firstMapHelper = null;
m_exec = exec;
if (m_ignoreMissingRows) {
m_max = Math.min(inData[0].getRowCount(), inData[1].getRowCount());
} else {
m_max = Math.max(inData[0].getRowCount(), inData[1].getRowCount());
}
while (true) {
if (!readLeftChunk(leftTable, map)) {
if (!m_ignoreMissingRows) {
processRemainingRightRows(dc, leftTable, rightTable, rightRows);
}
break;
}
if ((m_rightIt == null) || (!m_rightIt.hasNext()) || (rightRows.nextClearBit(0) <= m_rightIt.getIndex())) {
m_rightIt = new CounterRowIterator(rightTable.iterator());
}
while (m_rightIt.hasNext() && (map.size() > 0)) {
m_exec.checkCanceled();
DataRow rightRow = m_rightIt.next();
SoftReference<Helper> sr = map.get(rightRow.getKey());
if (sr != null) {
Helper h = sr.get();
if (h == null) {
map.remove(rightRow.getKey());
} else {
h.m_rightRow = rightRow;
h.m_rightIndex = m_rightIt.getIndex();
if (h.m_leftIndex == m_leftRows) {
// m_firstMapHelper = h;
assert h.m_predecessor == null || !map.containsKey(h.m_predecessor.m_leftRow.getKey());
h.m_predecessor = null;
DataRow joinedRow = new JoinedRow(h.m_leftRow, h.m_rightRow);
dc.addRowToTable(joinedRow);
map.remove(rightRow.getKey());
rightRows.set(m_rightIt.getIndex());
m_leftRows++;
m_outputRows++;
printProgress(rightRow.getKey());
}
}
}
}
processRemainingLeftRowsInMap(dc, rightTable, map, rightRows);
if (!m_ignoreMissingRows) {
if (rightRows.cardinality() == inData[1].getRowCount()) {
processRemainingLeftRowsInTable(dc, leftTable, rightTable);
}
} else {
m_leftRows += map.size();
map.clear();
if (rightRows.cardinality() == inData[1].getRowCount()) {
break;
}
}
}
m_leftIt = null;
m_rightIt = null;
m_exec = null;
m_firstMapHelper = null;
dc.close();
return new BufferedDataTable[] { dc.getTable() };
}
Aggregations