use of org.knime.core.data.DataColumnDomainCreator in project knime-core by knime.
the class SplitCellFactory method getDomains.
/**
* Returns the domains that were computed while processing all rows.
*
* @return an array with domain
*/
public DataColumnDomain[] getDomains() {
DataColumnDomain[] domains = new DataColumnDomain[m_colSpecs.length];
int i = 0;
for (DataColumnSpec cs : m_domainCreator.createSpec()) {
DataColumnDomainCreator crea = new DataColumnDomainCreator(cs.getDomain());
if (!m_commonTypes[i].isCompatible(BoundedValue.class)) {
crea.setLowerBound(null);
crea.setUpperBound(null);
}
if (!m_commonTypes[i].isCompatible(NominalValue.class)) {
crea.setValues(null);
}
domains[i] = crea.createDomain();
i++;
}
return domains;
}
use of org.knime.core.data.DataColumnDomainCreator in project knime-core by knime.
the class AbstractMany2OneCellFactory method getColumnSpecs.
/**
* {@inheritDoc}
*/
@Override
public DataColumnSpec[] getColumnSpecs() {
// new column
DataColumnSpecCreator appendedColumnCreator = new DataColumnSpecCreator(m_appendedColumnName, StringCell.TYPE);
// possible values depend on allow multi occurrences
DataColumnDomainCreator possibleValuesCreator = new DataColumnDomainCreator(m_columnNames);
appendedColumnCreator.setDomain(possibleValuesCreator.createDomain());
return new DataColumnSpec[] { appendedColumnCreator.createSpec() };
}
use of org.knime.core.data.DataColumnDomainCreator in project knime-core by knime.
the class MissingValueHandling2Table method createTableSpecPrivate.
/* private helper that assumes the ColSetting to have the right format. */
private static DataTableSpec createTableSpecPrivate(final DataTableSpec spec, final MissingValueHandling2ColSetting[] sets) {
assert (spec.getNumColumns() == sets.length);
DataColumnSpec[] newSpecs = new DataColumnSpec[sets.length];
for (int i = 0; i < sets.length; i++) {
DataColumnSpec colSpec = spec.getColumnSpec(i);
DataColumnSpec newSpec = colSpec;
if (sets[i].getMethod() == MissingValueHandling2ColSetting.METHOD_FIX_VAL) {
DataColumnDomain dom = colSpec.getDomain();
Comparator<DataCell> comp = colSpec.getType().getComparator();
DataCell fixCell = sets[i].getFixCell();
boolean changed = false;
DataCell l = dom.getLowerBound();
// (but rather be null). It may happen anyway, we catch it here
if (l != null && !l.isMissing() && (comp.compare(fixCell, l) < 0)) {
changed = true;
l = fixCell;
}
DataCell u = dom.getUpperBound();
if (u != null && !u.isMissing() && (comp.compare(fixCell, u) > 0)) {
changed = true;
u = fixCell;
}
Set<DataCell> vals = dom.getValues();
if (vals != null && !vals.contains(fixCell)) {
changed = true;
vals = new LinkedHashSet<DataCell>(vals);
vals.add(fixCell);
}
if (changed) {
DataColumnDomain newDom = new DataColumnDomainCreator(vals, l, u).createDomain();
DataColumnSpecCreator c = new DataColumnSpecCreator(colSpec);
c.setDomain(newDom);
newSpec = c.createSpec();
}
}
newSpecs[i] = newSpec;
}
return new DataTableSpec(newSpecs);
}
use of org.knime.core.data.DataColumnDomainCreator in project knime-core by knime.
the class ColPropertyDialog method openDomainDialog.
/**
* Called when "domain..." button is pressed. Opens the dialog for domain settings, with components depending on the
* currently selected type.
*/
void openDomainDialog() {
// prepare a colProp with the default settings for the dialog
ColProperty domainProperty = (ColProperty) m_allColProps.get(m_colIdx).clone();
// set the new name and type - regardless of their correctness
domainProperty.changeColumnName(m_colNameField.getText());
DataType selectedType = (DataType) m_typeChooser.getSelectedItem();
if (!domainProperty.getColumnSpec().getType().equals(selectedType)) {
domainProperty.changeDomain(new DataColumnDomainCreator().createDomain());
}
domainProperty.changeColumnType(selectedType);
if (m_userDomainSettings != null) {
// calling this dialog for the 2nd time. Use vals from first call.
domainProperty.changeDomain(m_userDomainSettings.getColumnSpec().getDomain());
domainProperty.setReadPossibleValuesFromFile(m_userDomainSettings.getReadPossibleValuesFromFile());
}
DomainDialog domDlg = new DomainDialog(this, domainProperty);
ColProperty newSettings = domDlg.showDialog();
if (newSettings != null) {
m_userDomainSettings = newSettings;
}
}
use of org.knime.core.data.DataColumnDomainCreator in project knime-core by knime.
the class Statistics3Table method createOutSpecNominal.
/**
* Create spec containing only nominal columns in same order as the input spec.
*
* @param inSpec input spec
* @param nominalValues used in map of co-occurrences
* @return a new spec with all nominal columns
*/
public static DataTableSpec createOutSpecNominal(final DataTableSpec inSpec, final List<String> nominalValues) {
ArrayList<DataColumnSpec> cspecs = new ArrayList<DataColumnSpec>();
for (int i = 0; i < inSpec.getNumColumns(); i++) {
DataColumnSpec cspec = inSpec.getColumnSpec(i);
if (nominalValues.contains(cspec.getName())) {
cspecs.add(cspec);
String countCol = DataTableSpec.getUniqueColumnName(inSpec, cspec.getName() + "_Count");
cspecs.add(new DataColumnSpecCreator(countCol, IntCell.TYPE).createSpec());
String percentCol = DataTableSpec.getUniqueColumnName(inSpec, "Relative Frequency (" + cspec.getName() + ")");
DataColumnSpecCreator percentColSpecCreator = new DataColumnSpecCreator(percentCol, DoubleCell.TYPE);
percentColSpecCreator.setDomain(new DataColumnDomainCreator(new DoubleCell(0.0), new DoubleCell(1.0)).createDomain());
cspecs.add(percentColSpecCreator.createSpec());
}
}
return new DataTableSpec(cspecs.toArray(new DataColumnSpec[cspecs.size()]));
}
Aggregations