Search in sources :

Example 86 with DataField

use of org.dmg.pmml.DataField in project drools by kiegroup.

the class ModelUtils method convertToKieOutputField.

/**
 * Return a <code>org.kie.pmml.api.models.OutputField</code> out of a <code>org.dmg.pmml.OutputField</code> one
 * @param toConvert
 * @param field - this may be <code>null</code>
 * @return
 */
public static org.kie.pmml.api.models.OutputField convertToKieOutputField(final OutputField toConvert, final Field<?> field) {
    final String name = toConvert.getName() != null ? toConvert.getName().getValue() : null;
    final OP_TYPE opType = toConvert.getOpType() != null ? OP_TYPE.byName(toConvert.getOpType().value()) : null;
    final DATA_TYPE dataFieldDataType = field != null ? DATA_TYPE.byName(field.getDataType().value()) : null;
    final DATA_TYPE dataType = toConvert.getDataType() != null ? DATA_TYPE.byName(toConvert.getDataType().value()) : dataFieldDataType;
    final String targetField = toConvert.getTargetField() != null ? toConvert.getTargetField().getValue() : null;
    final RESULT_FEATURE resultFeature = toConvert.getResultFeature() != null ? RESULT_FEATURE.byName(toConvert.getResultFeature().value()) : null;
    final List<String> allowedValues = field instanceof DataField ? convertDataFieldValues(((DataField) field).getValues()) : null;
    return new org.kie.pmml.api.models.OutputField(name, opType, dataType, targetField, resultFeature, allowedValues);
}
Also used : DataField(org.dmg.pmml.DataField) RESULT_FEATURE(org.kie.pmml.api.enums.RESULT_FEATURE) OutputField(org.dmg.pmml.OutputField) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE)

Example 87 with DataField

use of org.dmg.pmml.DataField in project drools by kiegroup.

the class ModelUtils method convertToKieMiningField.

/**
 * Return a <code>org.kie.pmml.api.models.MiningField</code> out of a <code>org.dmg.pmml.MiningField</code> and
 * relative <code>org.dmg.pmml.DataField</code> ones
 * @param toConvert
 * @param field
 * @return
 */
public static org.kie.pmml.api.models.MiningField convertToKieMiningField(final MiningField toConvert, final Field<?> field) {
    final String name = toConvert.getName() != null ? toConvert.getName().getValue() : null;
    final FIELD_USAGE_TYPE fieldUsageType = toConvert.getUsageType() != null ? FIELD_USAGE_TYPE.byName(toConvert.getUsageType().value()) : null;
    final OP_TYPE opType = toConvert.getOpType() != null ? OP_TYPE.byName(toConvert.getOpType().value()) : null;
    final DATA_TYPE dataType = field.getDataType() != null ? DATA_TYPE.byName(field.getDataType().value()) : null;
    final MISSING_VALUE_TREATMENT_METHOD missingValueTreatmentMethod = toConvert.getMissingValueTreatment() != null ? MISSING_VALUE_TREATMENT_METHOD.byName(toConvert.getMissingValueTreatment().value()) : null;
    final INVALID_VALUE_TREATMENT_METHOD invalidValueTreatmentMethod = toConvert.getInvalidValueTreatment() != null ? INVALID_VALUE_TREATMENT_METHOD.byName(toConvert.getInvalidValueTreatment().value()) : null;
    final String missingValueReplacement = toConvert.getMissingValueReplacement() != null ? toConvert.getMissingValueReplacement().toString() : null;
    final String invalidValueReplacement = toConvert.getInvalidValueReplacement() != null ? toConvert.getInvalidValueReplacement().toString() : null;
    final List<String> allowedValues = field instanceof DataField ? convertDataFieldValues(((DataField) field).getValues()) : Collections.emptyList();
    final List<org.kie.pmml.api.models.Interval> intervals = field instanceof DataField ? convertDataFieldIntervals(((DataField) field).getIntervals()) : Collections.emptyList();
    return new org.kie.pmml.api.models.MiningField(name, fieldUsageType, opType, dataType, missingValueTreatmentMethod, invalidValueTreatmentMethod, missingValueReplacement, invalidValueReplacement, allowedValues, intervals);
}
Also used : MiningField(org.dmg.pmml.MiningField) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) INVALID_VALUE_TREATMENT_METHOD(org.kie.pmml.api.enums.INVALID_VALUE_TREATMENT_METHOD) MISSING_VALUE_TREATMENT_METHOD(org.kie.pmml.api.enums.MISSING_VALUE_TREATMENT_METHOD) FIELD_USAGE_TYPE(org.kie.pmml.api.enums.FIELD_USAGE_TYPE) DataField(org.dmg.pmml.DataField) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) Interval(org.dmg.pmml.Interval)

Example 88 with DataField

use of org.dmg.pmml.DataField in project drools by kiegroup.

the class PMMLModelTestUtils method getRandomDataField.

public static DataField getRandomDataField() {
    DataField toReturn = new DataField();
    toReturn.setName(FieldName.create(RandomStringUtils.random(6, true, false)));
    toReturn.setDataType(getRandomDataType());
    toReturn.setOpType(getRandomOpType());
    IntStream.range(0, 3).forEach(i -> {
        toReturn.addValues(getRandomValue(toReturn.getDataType()));
        toReturn.addIntervals(getRandomInterval());
    });
    return toReturn;
}
Also used : DataField(org.dmg.pmml.DataField)

Example 89 with DataField

use of org.dmg.pmml.DataField in project drools by kiegroup.

the class PMMLModelTestUtils method getDataField.

public static DataField getDataField(String fieldName, OpType opType, DataType dataType) {
    DataField toReturn = getDataField(fieldName, opType);
    toReturn.setDataType(dataType);
    return toReturn;
}
Also used : DataField(org.dmg.pmml.DataField)

Example 90 with DataField

use of org.dmg.pmml.DataField in project drools by kiegroup.

the class ModelUtilsTest method getDataTypeFromDataDictionary.

@Test
public void getDataTypeFromDataDictionary() {
    final DataDictionary dataDictionary = new DataDictionary();
    IntStream.range(0, 3).forEach(i -> {
        final DataField dataField = getRandomDataField();
        dataDictionary.addDataFields(dataField);
    });
    dataDictionary.getDataFields().forEach(dataField -> {
        DATA_TYPE retrieved = ModelUtils.getDATA_TYPE(getFieldsFromDataDictionary(dataDictionary), dataField.getName().getValue());
        assertNotNull(retrieved);
        DATA_TYPE expected = DATA_TYPE.byName(dataField.getDataType().value());
        assertEquals(expected, retrieved);
    });
}
Also used : DataField(org.dmg.pmml.DataField) PMMLModelTestUtils.getDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getDataField) PMMLModelTestUtils.getRandomDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField) DataDictionary(org.dmg.pmml.DataDictionary) CommonTestingUtils.getFieldsFromDataDictionary(org.kie.pmml.compiler.api.CommonTestingUtils.getFieldsFromDataDictionary) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) Test(org.junit.Test)

Aggregations

DataField (org.dmg.pmml.DataField)101 Test (org.junit.Test)51 DataDictionary (org.dmg.pmml.DataDictionary)42 MiningField (org.dmg.pmml.MiningField)42 MiningSchema (org.dmg.pmml.MiningSchema)30 PMMLModelTestUtils.getRandomDataField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField)28 RegressionModel (org.dmg.pmml.regression.RegressionModel)27 CommonTestingUtils.getFieldsFromDataDictionary (org.kie.pmml.compiler.api.CommonTestingUtils.getFieldsFromDataDictionary)27 FieldName (org.dmg.pmml.FieldName)24 Model (org.dmg.pmml.Model)24 PMMLModelTestUtils.getDataField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getDataField)22 DataType (org.dmg.pmml.DataType)19 OutputField (org.dmg.pmml.OutputField)19 PMMLModelTestUtils.getRandomMiningField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomMiningField)19 PMMLModelTestUtils.getMiningField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getMiningField)18 ArrayList (java.util.ArrayList)17 List (java.util.List)17 PMML (org.dmg.pmml.PMML)17 Collectors (java.util.stream.Collectors)16 OpType (org.dmg.pmml.OpType)15