Search in sources :

Example 1 with NameAndIndex

use of org.knime.base.node.mine.regression.pmmlgreg.VectorHandling.NameAndIndex in project knime-core by knime.

the class PMMLGeneralRegressionTranslator method updateVectorLengthsBasedOnDerivedFields.

/**
 * @param derivedFieldList
 */
private void updateVectorLengthsBasedOnDerivedFields(final List<DerivedField> derivedFieldList) {
    final Map<String, Integer> lengths = new LinkedHashMap<>();
    for (final DerivedField df : derivedFieldList) {
        final String name = df.getName();
        Optional<NameAndIndex> vni = VectorHandling.parse(name);
        if (vni.isPresent()) {
            final String key = vni.get().getName();
            try {
                String function = df.getApply().getFunction();
                if (!"substring".equals(function)) {
                    continue;
                }
                final List<FieldRef> fieldRefList = df.getApply().getFieldRefList();
                if (fieldRefList.isEmpty() || !key.equals(fieldRefList.get(0).getField())) {
                    LOGGER.debug("Field name is not related to the derived field name: " + fieldRefList + " <-> " + key);
                    continue;
                }
                if (2 != df.getApply().getConstantList().size()) {
                    LOGGER.debug("substring requires two parameters: " + df);
                    continue;
                }
                if (!DATATYPE.INTEGER.equals(df.getDataType())) {
                    LOGGER.debug("Array value should be integer: " + df);
                    continue;
                }
                if (!OPTYPE.CONTINUOUS.equals(df.getOptype())) {
                    LOGGER.debug("The optype should be continuous: " + df);
                    continue;
                }
                int index = vni.get().getIndex();
                int old = Math.max(0, lengths.getOrDefault(key, Integer.valueOf(0)).intValue());
                if (old <= index) {
                    lengths.put(key, index + 1);
                }
            } catch (RuntimeException e) {
                // Ignore
                LOGGER.debug(df.toString(), e);
            }
        }
    }
    LOGGER.debug(lengths);
    m_content.updateVectorLengths(lengths);
}
Also used : BigInteger(java.math.BigInteger) FieldRef(org.dmg.pmml.FieldRefDocument.FieldRef) NameAndIndex(org.knime.base.node.mine.regression.pmmlgreg.VectorHandling.NameAndIndex) DerivedField(org.dmg.pmml.DerivedFieldDocument.DerivedField) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

BigInteger (java.math.BigInteger)1 LinkedHashMap (java.util.LinkedHashMap)1 DerivedField (org.dmg.pmml.DerivedFieldDocument.DerivedField)1 FieldRef (org.dmg.pmml.FieldRefDocument.FieldRef)1 NameAndIndex (org.knime.base.node.mine.regression.pmmlgreg.VectorHandling.NameAndIndex)1