use of org.knime.core.data.container.DataContainer in project knime-core by knime.
the class NextValidValueStatisticTB method init.
/**
* {@inheritDoc}
*/
@Override
protected void init(final DataTableSpec spec, final int amountOfColumns) {
m_index = spec.findColumnIndex(m_columnName);
m_nextCells = new DataContainer(new DataTableSpec(spec.getColumnSpec(m_index)));
}
use of org.knime.core.data.container.DataContainer in project knime-core by knime.
the class Rule2DPlotter method updatePaintModel.
/**
* {@inheritDoc}
*/
@Override
protected void updatePaintModel() {
super.updatePaintModel();
if (m_rules != null) {
Rule2DDrawingPane drawingPane = getDrawingPane();
drawingPane.setOriginalRuleTable(m_rules);
String xName = getXColName();
String yName = getYColName();
int xIdx = -1;
int yIdx = -1;
if (xName != null && yName != null) {
xIdx = m_rules.getDataTableSpec().findColumnIndex(xName);
yIdx = m_rules.getDataTableSpec().findColumnIndex(yName);
}
if (xIdx >= 0 && yIdx >= 0) {
Coordinate x = getColHeader().getCoordinate();
Coordinate y = getRowHeader().getCoordinate();
// check if the coordinates are valid
if (x == null || y == null) {
return;
}
// calculate the coordinates of the rules here
// List<DataRow> rows = new ArrayList<DataRow>();
DataColumnSpecCreator creator = new DataColumnSpecCreator("xValues", FuzzyIntervalCell.TYPE);
DataColumnSpec col1 = creator.createSpec();
creator = new DataColumnSpecCreator("yValues", FuzzyIntervalCell.TYPE);
DataColumnSpec col2 = creator.createSpec();
DataTableSpec spec = new DataTableSpec(new DataColumnSpec[] { col1, col2 });
DataContainer rows = new DataContainer(spec);
for (RowIterator itr = m_rules.iterator(); itr.hasNext(); ) {
DataRow currRow = itr.next();
DataCell[] newCells = new DataCell[2];
for (int cell = 0; cell < currRow.getNumCells(); cell++) {
// if (!m_rules.getDataTableSpec().getColumnSpec(cell)
// .getType().isCompatible(
// FuzzyIntervalValue.class)) {
// continue;
// }
Rectangle rect = calculateDrawingRectangle();
double a;
double b;
double c;
double d;
if (cell == xIdx) {
if (currRow.getCell(cell).isMissing()) {
// normalize xValues
a = getXmin();
b = getXmin();
c = getXmax();
d = getXmax();
} else {
// normalize xValues
a = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinSupport();
b = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinCore();
c = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxCore();
d = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxSupport();
}
double newA = x.calculateMappedValue(new DoubleCell(a), rect.width, true);
double newB = x.calculateMappedValue(new DoubleCell(b), rect.width, true);
double newC = x.calculateMappedValue(new DoubleCell(c), rect.width, true);
double newD = x.calculateMappedValue(new DoubleCell(d), rect.width, true);
DataCell newInterval = new FuzzyIntervalCell(rect.x + newA, rect.x + newB, rect.x + newC, rect.x + newD);
newCells[0] = newInterval;
}
if (cell == yIdx) {
if (currRow.getCell(cell).isMissing()) {
a = getYmin();
b = getYmin();
c = getYmax();
d = getYmax();
} else {
// normalize yValues
a = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinSupport();
b = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinCore();
c = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxCore();
d = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxSupport();
}
double newA = y.calculateMappedValue(new DoubleCell(a), rect.height, true);
double newB = y.calculateMappedValue(new DoubleCell(b), rect.height, true);
double newC = y.calculateMappedValue(new DoubleCell(c), rect.height, true);
double newD = y.calculateMappedValue(new DoubleCell(d), rect.height, true);
DataCell newInterval = new FuzzyIntervalCell(rect.y + rect.height - newD, rect.y + rect.height - newC, rect.y + rect.height - newB, rect.y + rect.height - newA);
newCells[1] = newInterval;
}
}
// create new row out of the normalized cells
rows.addRowToTable(new DefaultRow(currRow.getKey(), newCells));
}
rows.close();
drawingPane.setNormalizedRules(new DefaultDataArray(rows.getTable(), 1, m_rules.size()));
}
super.updatePaintModel();
}
}
use of org.knime.core.data.container.DataContainer in project knime-core by knime.
the class DataColumnPropertiesView method createPropsTable.
private DataTable createPropsTable(final DataTableSpec tableSpec) {
// output has as many cols
int numOfCols = tableSpec.getNumColumns();
String[] colNames = new String[numOfCols];
DataType[] colTypes = new DataType[numOfCols];
// colnames are the same as incoming, types are all StringTypes
for (int c = 0; c < numOfCols; c++) {
colNames[c] = tableSpec.getColumnSpec(c).getName();
colTypes[c] = StringCell.TYPE;
}
// get keys for ALL props in the table. Each will show in one row.
HashSet<String> allKeys = new LinkedHashSet<String>();
for (int c = 0; c < numOfCols; c++) {
Enumeration<String> props = tableSpec.getColumnSpec(c).getProperties().properties();
while (props.hasMoreElements()) {
allKeys.add(props.nextElement());
}
}
DataContainer result = new DataContainer(new DataTableSpec(colNames, colTypes));
// now construct the rows we wanna display
for (String key : allKeys) {
DataCell[] cells = new DataCell[numOfCols];
for (int c = 0; c < numOfCols; c++) {
String cellValue = "";
if (tableSpec.getColumnSpec(c).getProperties().containsProperty(key)) {
cellValue = tableSpec.getColumnSpec(c).getProperties().getProperty(key);
}
cells[c] = new StringCell(cellValue);
}
result.addRowToTable(new DefaultRow(key, cells));
}
result.close();
return result.getTable();
}
use of org.knime.core.data.container.DataContainer in project knime-core by knime.
the class SQLExtractNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
DatabasePortObject dbIn = (DatabasePortObject) inData[0];
String query = dbIn.getConnectionSettings(getCredentialsProvider()).getQuery();
final String flowVarName = m_flowVariableName.getStringValue();
pushFlowVariableString(flowVarName, query);
// Create a table with the SQL query in a StringCell
DataContainer container = exec.createDataContainer(createSpec(flowVarName));
container.addRowToTable(new DefaultRow(RowKey.createRowKey(0), new StringCell(query)));
container.close();
BufferedDataTable outTable = (BufferedDataTable) container.getTable();
return new PortObject[] { FlowVariablePortObject.INSTANCE, outTable };
}
use of org.knime.core.data.container.DataContainer in project knime-core by knime.
the class Statistics3Table 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);
@SuppressWarnings("unchecked") Iterator<Entry<DataCell, Integer>>[] it = new Iterator[(outSpec.getNumColumns() / 3)];
long[] totals = new long[it.length];
for (int i = 0, index = 0; i < m_nominalValues.size(); i++) {
Map<DataCell, Integer> currentMap = m_nominalValues.get(i);
if (currentMap != null) {
it[index] = currentMap.entrySet().iterator();
totals[index] = currentMap.values().stream().collect(Collectors.summingLong(Integer::valueOf));
index += 1;
}
}
DataContainer cont = new DataContainer(outSpec, true);
int rowIndex = 0;
do {
boolean addEnd = true;
DataCell[] cells = new DataCell[3 * it.length];
for (int i = 0; i < it.length; i++) {
if (it[i].hasNext()) {
Map.Entry<DataCell, Integer> e = it[i].next();
cells[3 * i] = e.getKey();
int count = e.getValue().intValue();
cells[3 * i + 1] = new IntCell(count);
cells[3 * i + 2] = new DoubleCell((double) count / totals[i]);
addEnd = false;
} else {
cells[3 * i] = DataType.getMissingCell();
cells[3 * i + 1] = DataType.getMissingCell();
cells[3 * i + 2] = DataType.getMissingCell();
}
}
if (addEnd) {
break;
}
cont.addRowToTable(new DefaultRow(RowKey.createRowKey(rowIndex++), cells));
} while (true);
cont.close();
return cont.getTable();
}
Aggregations