Search in sources :

Example 26 with DataColumnDomain

use of org.knime.core.data.DataColumnDomain 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 27 with DataColumnDomain

use of org.knime.core.data.DataColumnDomain 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 28 with DataColumnDomain

use of org.knime.core.data.DataColumnDomain in project knime-core by knime.

the class DomainDialog method showDialog.

/**
 * Shows the dialog with the passed default settings (passed to the constructor). It will not return until the user
 * closes the dialog. If the dialog was canceled, <code>null</code> will be returned as result, otherwise the column
 * property passed to the constructor with a modified domain and nominal value flag will be returned.
 *
 * @return a modified col property object, or <code>null</code> if user canceled
 */
public ColProperty showDialog() {
    // fill in the values from the passed col property object
    // and the possible values - if set
    DataColumnDomain domain = m_colProp.getColumnSpec().getDomain();
    if ((domain != null) && (domain.getValues() != null)) {
        Set<DataCell> valList = domain.getValues();
        if (m_valueList != null) {
            m_valueList.setListData(valList.toArray());
        }
    }
    // now show the dialog, show it and wait until it comes back.
    setTitle("New domain settings for column '" + m_colProp.getColumnSpec().getName().toString() + "'");
    pack();
    centerDialog();
    setVisible(true);
    return m_result;
}
Also used : DataColumnDomain(org.knime.core.data.DataColumnDomain) DataCell(org.knime.core.data.DataCell)

Example 29 with DataColumnDomain

use of org.knime.core.data.DataColumnDomain in project knime-core by knime.

the class AppendedRowsTable method generateDataTableSpec.

/**
 * Factory method that determines the final {@link DataTableSpec} given the
 * tables.
 *
 * @param tableSpecs the table specs as in the constructor
 * @return the outcoming {qlink DataTableSpec}
 * @see #AppendedRowsTable(DataTable[])
 */
public static final DataTableSpec generateDataTableSpec(final DataTableSpec... tableSpecs) {
    // memorize the first column spec in the argument array for
    // each column name, we use it later on to initialize the column
    // spec creator.
    LinkedHashMap<String, DataColumnSpec> columnSet = new LinkedHashMap<String, DataColumnSpec>();
    LinkedHashMap<String, DataType> typeSet = new LinkedHashMap<String, DataType>();
    LinkedHashMap<String, DataColumnDomain> domainSet = new LinkedHashMap<String, DataColumnDomain>();
    // create final data table spec
    for (int i = 0; i < tableSpecs.length; i++) {
        DataTableSpec cur = tableSpecs[i];
        for (int c = 0; c < cur.getNumColumns(); c++) {
            DataColumnSpec colSpec = cur.getColumnSpec(c);
            String colName = colSpec.getName();
            // set the spec for this column if not yet done
            if (!columnSet.containsKey(colName)) {
                columnSet.put(colName, colSpec);
            }
            DataType colType = colSpec.getType();
            DataColumnDomain colDomain = colSpec.getDomain();
            // duplicates are welcome - but only if they match the type
            if (typeSet.containsKey(colName)) {
                DataType oldType = typeSet.get(colName);
                DataColumnDomain oldDomain = domainSet.get(colName);
                // the base type they share
                DataType type = DataType.getCommonSuperType(oldType, colType);
                assert type.isASuperTypeOf(oldType);
                assert type.isASuperTypeOf(colType);
                // that shouldn't happen though, eh: shit happens.
                if (!oldType.equals(type)) {
                    LOGGER.info("Confusing data types for column \"" + colName + "\": " + oldType.toString() + " vs. " + colType.toString() + "\n" + "Using common base type " + type.toString());
                    // that must not change the order.
                    typeSet.put(colName, type);
                }
                DataColumnDomain newDomain = merge(oldDomain, colDomain, type.getComparator());
                domainSet.put(colName, newDomain);
            } else {
                // doesn't contain the key
                typeSet.put(colName, colType);
                domainSet.put(colName, colDomain);
            }
        }
    // for all columns in the current table spec
    }
    // for all tables
    DataColumnSpec[] colSpecs = new DataColumnSpec[typeSet.size()];
    int i = 0;
    for (Map.Entry<String, DataType> entry : typeSet.entrySet()) {
        String name = entry.getKey();
        DataType type = entry.getValue();
        // domain is null, if we did not remember it (e.g. "keepDomain" was
        // false)
        DataColumnDomain domain = domainSet.get(name);
        DataColumnSpec initSpec = columnSet.get(name);
        DataColumnSpecCreator specCreator = new DataColumnSpecCreator(initSpec);
        specCreator.setDomain(domain);
        specCreator.setType(type);
        colSpecs[i++] = specCreator.createSpec();
    }
    return new DataTableSpec(colSpecs);
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) LinkedHashMap(java.util.LinkedHashMap) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnDomain(org.knime.core.data.DataColumnDomain) DataType(org.knime.core.data.DataType) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 30 with DataColumnDomain

use of org.knime.core.data.DataColumnDomain in project knime-core by knime.

the class AffineTransTable method generateNewSpec.

/**
 * Creates a new DataTableSpec. The target column's type is set to
 * DoubleType, the domain is adjusted.
 */
private static DataTableSpec generateNewSpec(final DataTableSpec spec, final AffineTransConfiguration configuration) {
    String[] names = configuration.getNames();
    HashMap<String, Integer> hash = new HashMap<String, Integer>();
    for (int i = 0; i < names.length; i++) {
        hash.put(names[i], i);
    }
    for (int i = 0; i < spec.getNumColumns(); i++) {
        DataColumnSpec col = spec.getColumnSpec(i);
        Integer index = hash.get(col.getName());
        if (index != null) {
            DataType type = col.getType();
            // do we need to support IntValue also?
            if (!type.isCompatible(DoubleValue.class)) {
                throw new IllegalArgumentException("Not supported: " + type);
            }
        }
    }
    DataColumnSpec[] specs = new DataColumnSpec[spec.getNumColumns()];
    double[] newmin = configuration.getMin();
    double[] newmax = configuration.getMax();
    double[] scales = configuration.getScales();
    double[] translations = configuration.getTranslations();
    for (int i = 0; i < specs.length; i++) {
        DataColumnSpec colSpec = spec.getColumnSpec(i);
        DataColumnDomain colDomain = colSpec.getDomain();
        Integer indexObject = hash.get(colSpec.getName());
        if (indexObject == null) {
            specs[i] = colSpec;
        } else {
            int index = indexObject.intValue();
            assert !Double.isNaN(scales[index]);
            // determine domain
            double interval = newmax[index] - newmin[index];
            DataCell up = null;
            DataCell oldUp = colDomain.getUpperBound();
            if (oldUp != null && !oldUp.isMissing()) {
                double oldVal = ((DoubleValue) oldUp).getDoubleValue();
                double newVal = scales[index] * oldVal + translations[index];
                if (!Double.isNaN(newmax[index])) {
                    if (newVal > newmax[index] && ((newVal - newmax[index]) / interval) < VERY_SMALL) {
                        newVal = newmax[index];
                    }
                }
                up = new DoubleCell(newVal);
            }
            DataCell low = null;
            DataCell oldLow = colDomain.getLowerBound();
            if (oldLow != null && !oldLow.isMissing()) {
                double oldVal = ((DoubleValue) oldLow).getDoubleValue();
                double newVal = scales[index] * oldVal + translations[index];
                if (!Double.isNaN(newmin[index])) {
                    if (newVal < newmin[index] && ((newmin[index] - newVal) / interval) < VERY_SMALL) {
                        newVal = newmin[index];
                    }
                }
                low = new DoubleCell(newVal);
            }
            DataColumnDomain dom = new DataColumnDomainCreator(low, up).createDomain();
            DataType type = DoubleCell.TYPE;
            DataColumnSpecCreator c = new DataColumnSpecCreator(colSpec);
            // IntType must be converted to DoubleType!
            c.setType(type);
            c.setDomain(dom);
            specs[i] = c.createSpec();
        }
    }
    return new DataTableSpec(specs);
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) HashMap(java.util.HashMap) DoubleCell(org.knime.core.data.def.DoubleCell) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnDomain(org.knime.core.data.DataColumnDomain) DoubleValue(org.knime.core.data.DoubleValue) DataType(org.knime.core.data.DataType) DataCell(org.knime.core.data.DataCell)

Aggregations

DataColumnDomain (org.knime.core.data.DataColumnDomain)46 DataColumnSpec (org.knime.core.data.DataColumnSpec)34 DataCell (org.knime.core.data.DataCell)32 DataTableSpec (org.knime.core.data.DataTableSpec)20 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)16 DoubleValue (org.knime.core.data.DoubleValue)13 DataColumnDomainCreator (org.knime.core.data.DataColumnDomainCreator)12 DataType (org.knime.core.data.DataType)11 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)8 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)7 PMMLPortObjectSpec (org.knime.core.node.port.pmml.PMMLPortObjectSpec)6 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 LinkedHashSet (java.util.LinkedHashSet)5 DoubleCell (org.knime.core.data.def.DoubleCell)5 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 LinkedList (java.util.LinkedList)3 Set (java.util.Set)3 DataRow (org.knime.core.data.DataRow)3