Search in sources :

Example 41 with DerivedField

use of org.dmg.pmml.DerivedFieldDocument.DerivedField in project knime-core by knime.

the class PMMLDataDictionaryTranslator method addOrUpdateColSpecsForDerivedFields.

/**
 * @param pmmlDoc the PMML document to analyze
 * @param colSpecs the list to add the data column specs to
 */
private void addOrUpdateColSpecsForDerivedFields(final PMMLDocument pmmlDoc, final List<DataColumnSpec> colSpecs) {
    DerivedField[] derivedFields = DerivedFieldMapper.getDerivedFields(pmmlDoc.getPMML());
    DerivedFieldMapper mapper = new DerivedFieldMapper(derivedFields);
    Set<String> mappedColumnNames = mapper.getDerivedNames();
    for (DerivedField df : derivedFields) {
        String name = df.getName();
        DataType dataType = getKNIMEDataType(df.getDataType());
        if (!mappedColumnNames.contains(name)) {
            /* It is a "real" column - not one that is mapping to another
                 * column. Hence add a data column spec. */
            DataColumnSpecCreator specCreator = new DataColumnSpecCreator(name, dataType);
            DataColumnSpec newSpec = specCreator.createSpec();
            colSpecs.add(newSpec);
            m_activeDerivedFields.add(name);
        } else {
            /* Update the data type of the referenced data column spec
                 * by replacing it with a spec of the new type. */
            String colName = mapper.getColumnName(name);
            DataColumnSpecCreator specCreator = new DataColumnSpecCreator(colName, dataType);
            DataColumnSpec newSpec = specCreator.createSpec();
            for (int i = 0; i < colSpecs.size(); i++) {
                if (colSpecs.get(i).getName().equals(colName)) {
                    colSpecs.remove(i);
                    colSpecs.add(i, newSpec);
                    break;
                }
            }
            m_activeDerivedFields.add(colName);
        }
    }
}
Also used : DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataType(org.knime.core.data.DataType) DerivedField(org.dmg.pmml.DerivedFieldDocument.DerivedField)

Aggregations

DerivedField (org.dmg.pmml.DerivedFieldDocument.DerivedField)41 ArrayList (java.util.ArrayList)12 FieldRef (org.dmg.pmml.FieldRefDocument.FieldRef)11 BigInteger (java.math.BigInteger)9 DerivedFieldMapper (org.knime.core.node.port.pmml.preproc.DerivedFieldMapper)8 MapValues (org.dmg.pmml.MapValuesDocument.MapValues)7 DataColumnSpec (org.knime.core.data.DataColumnSpec)6 Apply (org.dmg.pmml.ApplyDocument.Apply)5 DiscretizeBin (org.dmg.pmml.DiscretizeBinDocument.DiscretizeBin)5 Discretize (org.dmg.pmml.DiscretizeDocument.Discretize)5 Interval (org.dmg.pmml.IntervalDocument.Interval)5 NormDiscrete (org.dmg.pmml.NormDiscreteDocument.NormDiscrete)5 DataCell (org.knime.core.data.DataCell)5 DataType (org.knime.core.data.DataType)5 LinkedHashMap (java.util.LinkedHashMap)4 LinkedHashSet (java.util.LinkedHashSet)4 Map (java.util.Map)4 LocalTransformations (org.dmg.pmml.LocalTransformationsDocument.LocalTransformations)4 NeuralLayer (org.dmg.pmml.NeuralLayerDocument.NeuralLayer)4 NeuralOutput (org.dmg.pmml.NeuralOutputDocument.NeuralOutput)4