use of org.knime.core.data.DataColumnDomainCreator in project knime-core by knime.
the class RuleEngineNodeModel method updateColSpec.
/**
* Updates the prediction column specification if the rule outcomes are computable in advance.
* <br/>
* This will add all outcomes, not just the possibles.
* <br/>
* Sorry for the high complexity.
*
* @param rules The {@link Rule}s we want to analyse.
* @param outType The output data type.
* @param colSpecCreator The column creator.
*/
private static void updateColSpec(final List<Rule> rules, final DataType outType, final DataColumnSpecCreator colSpecCreator, final FlowVariableProvider nm) {
List<DataValue> results = new ArrayList<DataValue>(rules.size());
for (Rule rule : rules) {
try {
DataValue result = rule.getOutcome().getComputedResult(new DefaultRow("", new double[0]), new VariableProvider() {
/**
* {@inheritDoc}
*/
@Override
@Deprecated
public int getRowCount() {
throw new IllegalStateException("We will catch this.");
}
/**
* {@inheritDoc}
*/
@Override
public long getRowCountLong() {
throw new IllegalStateException("We will catch this.");
}
/**
* {@inheritDoc}
*/
@Override
@Deprecated
public int getRowIndex() {
throw new IllegalStateException("We will catch this.");
}
/**
* {@inheritDoc}
*/
@Override
public long getRowIndexLong() {
throw new IllegalStateException("We will catch this.");
}
/**
* {@inheritDoc}
*/
@Override
public Object readVariable(final String arg0, final Class<?> arg1) {
return nm.readVariable(arg0, arg1);
}
});
results.add(result);
} catch (RuntimeException e) {
// We stop, cannot update properly
return;
}
}
Set<DataCell> values = new LinkedHashSet<DataCell>(results.size());
if (outType.equals(StringCell.TYPE)) {
for (DataValue dataValue : results) {
if (dataValue instanceof StringCell) {
values.add((StringCell) dataValue);
} else if (dataValue instanceof StringValue) {
StringValue sv = (StringValue) dataValue;
values.add(new StringCell(sv.getStringValue()));
} else {
values.add(new StringCell(dataValue.toString()));
}
}
colSpecCreator.setDomain(new DataColumnDomainCreator(values).createDomain());
} else if (outType.isCompatible(DoubleValue.class)) {
DataCell min = new DoubleCell(Double.POSITIVE_INFINITY), max = new DoubleCell(Double.NEGATIVE_INFINITY);
for (DataValue dataValue : results) {
if (dataValue instanceof DoubleValue) {
DoubleValue dv = (DoubleValue) dataValue;
double d = dv.getDoubleValue();
min = d < ((DoubleValue) min).getDoubleValue() ? (DataCell) dv : min;
max = d > ((DoubleValue) max).getDoubleValue() ? (DataCell) dv : max;
values.add((DataCell) dv);
}
}
DataColumnDomainCreator dcdc = new DataColumnDomainCreator();
if (min instanceof DoubleValue && max instanceof DoubleValue) {
double mi = ((DoubleValue) min).getDoubleValue(), ma = ((DoubleValue) max).getDoubleValue();
if (mi != Double.POSITIVE_INFINITY && ma != Double.NEGATIVE_INFINITY && !Double.isNaN(mi) && !Double.isNaN(ma)) {
dcdc.setLowerBound(min);
dcdc.setUpperBound(max);
}
}
colSpecCreator.setDomain(dcdc.createDomain());
}
}
use of org.knime.core.data.DataColumnDomainCreator in project knime-core by knime.
the class SubgroupMinerModel method createItemsetOutputSpec.
private DataTableSpec createItemsetOutputSpec() {
/*
* creating the ouput spec with (maxDepth + 1) String columns and the
* first column as an int colum (the support)
*/
DataColumnSpec[] colSpecs = new DataColumnSpec[m_maxItemSetLength.getIntValue() + 1];
DataColumnSpecCreator colspeccreator = new DataColumnSpecCreator("Support(0-1):", DoubleCell.TYPE);
colspeccreator.setDomain(new DataColumnDomainCreator(new DoubleCell(0), new DoubleCell(1)).createDomain());
colSpecs[0] = colspeccreator.createSpec();
for (int i = 1; i < m_maxItemSetLength.getIntValue() + 1; i++) {
colSpecs[i] = new DataColumnSpecCreator("Item_" + i, StringCell.TYPE).createSpec();
}
return new DataTableSpec(colSpecs);
}
Aggregations