Search in sources :

Example 36 with DataColumnDomainCreator

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;
}
Also used : DataColumnDomain(org.knime.core.data.DataColumnDomain) DataColumnSpec(org.knime.core.data.DataColumnSpec) BoundedValue(org.knime.core.data.BoundedValue) NominalValue(org.knime.core.data.NominalValue) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator)

Example 37 with DataColumnDomainCreator

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() };
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator)

Example 38 with DataColumnDomainCreator

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);
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnDomain(org.knime.core.data.DataColumnDomain) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataCell(org.knime.core.data.DataCell) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator)

Example 39 with DataColumnDomainCreator

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;
    }
}
Also used : DataType(org.knime.core.data.DataType) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator)

Example 40 with DataColumnDomainCreator

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()]));
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DoubleCell(org.knime.core.data.def.DoubleCell) ArrayList(java.util.ArrayList) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator)

Aggregations

DataColumnDomainCreator (org.knime.core.data.DataColumnDomainCreator)57 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)51 DataColumnSpec (org.knime.core.data.DataColumnSpec)43 DoubleCell (org.knime.core.data.def.DoubleCell)28 DataCell (org.knime.core.data.DataCell)27 DataTableSpec (org.knime.core.data.DataTableSpec)26 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)15 ArrayList (java.util.ArrayList)14 DataColumnDomain (org.knime.core.data.DataColumnDomain)12 DataRow (org.knime.core.data.DataRow)12 DataType (org.knime.core.data.DataType)12 DoubleValue (org.knime.core.data.DoubleValue)11 StringCell (org.knime.core.data.def.StringCell)8 BufferedDataTable (org.knime.core.node.BufferedDataTable)7 LinkedHashSet (java.util.LinkedHashSet)6 Coordinate (org.knime.base.util.coordinate.Coordinate)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 LinkedHashMap (java.util.LinkedHashMap)5 NumericCoordinate (org.knime.base.util.coordinate.NumericCoordinate)5