Search in sources :

Example 1 with Closure

use of org.dmg.pmml.IntervalDocument.Interval.Closure in project knime-core by knime.

the class PMMLBinningTranslator method initializeFrom.

/**
 * {@inheritDoc}
 */
@Override
public List<Integer> initializeFrom(final DerivedField[] derivedFields) {
    m_mapper = new DerivedFieldMapper(derivedFields);
    List<Integer> consumed = new ArrayList(derivedFields.length);
    for (int i = 0; i < derivedFields.length; i++) {
        DerivedField df = derivedFields[i];
        if (!df.isSetDiscretize()) {
            // only reading discretize entries other entries are skipped
            continue;
        }
        consumed.add(i);
        Discretize discretize = df.getDiscretize();
        DiscretizeBin[] pmmlBins = discretize.getDiscretizeBinArray();
        NumericBin[] knimeBins = new NumericBin[pmmlBins.length];
        for (int j = 0; j < pmmlBins.length; j++) {
            DiscretizeBin bin = pmmlBins[j];
            String binName = bin.getBinValue();
            Interval interval = bin.getInterval();
            double leftValue = interval.getLeftMargin();
            double rightValue = interval.getRightMargin();
            Closure.Enum closure = interval.getClosure();
            boolean leftOpen = true;
            boolean rightOpen = true;
            if (Closure.OPEN_CLOSED == closure) {
                rightOpen = false;
            } else if (Closure.CLOSED_OPEN == closure) {
                leftOpen = false;
            } else if (Closure.CLOSED_CLOSED == closure) {
                leftOpen = false;
                rightOpen = false;
            }
            knimeBins[j] = new NumericBin(binName, leftOpen, leftValue, rightOpen, rightValue);
        }
        /**
         * This field contains the name of the column in KNIME that
         * corresponds to the derived field in PMML. This is necessary if
         * derived fields are defined on other derived fields and the
         * columns in KNIME are replaced with the preprocessed values.
         * In this case KNIME has to know the original names (e.g. A) while
         * PMML references to A', A'' etc.
         */
        String displayName = df.getDisplayName();
        if (displayName != null) {
            m_columnToBins.put(displayName, knimeBins);
            m_columnToAppend.put(displayName, null);
        } else if (df.getName() != null) {
            String field = m_mapper.getColumnName(discretize.getField());
            m_columnToBins.put(field, knimeBins);
            m_columnToAppend.put(field, df.getName());
        }
    }
    return consumed;
}
Also used : Closure(org.dmg.pmml.IntervalDocument.Interval.Closure) ArrayList(java.util.ArrayList) DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) Discretize(org.dmg.pmml.DiscretizeDocument.Discretize) DiscretizeBin(org.dmg.pmml.DiscretizeBinDocument.DiscretizeBin) DerivedField(org.dmg.pmml.DerivedFieldDocument.DerivedField) Interval(org.dmg.pmml.IntervalDocument.Interval)

Aggregations

ArrayList (java.util.ArrayList)1 DerivedField (org.dmg.pmml.DerivedFieldDocument.DerivedField)1 DiscretizeBin (org.dmg.pmml.DiscretizeBinDocument.DiscretizeBin)1 Discretize (org.dmg.pmml.DiscretizeDocument.Discretize)1 Interval (org.dmg.pmml.IntervalDocument.Interval)1 Closure (org.dmg.pmml.IntervalDocument.Interval.Closure)1 DerivedFieldMapper (org.knime.core.node.port.pmml.preproc.DerivedFieldMapper)1