Search in sources :

Example 6 with DATA_TYPE

use of org.kie.pmml.api.enums.DATA_TYPE in project drools by kiegroup.

the class KiePMMLDefineFunctionInstanceFactory method getKiePMMLDefineFunction.

static KiePMMLDefineFunction getKiePMMLDefineFunction(final DefineFunction defineFunction) {
    final List<KiePMMLParameterField> kiePMMLParameterFields = getKiePMMLParameterFields(defineFunction.getParameterFields());
    DATA_TYPE dataType = defineFunction.getDataType() != null ? DATA_TYPE.byName(defineFunction.getDataType().value()) : null;
    OP_TYPE opType = defineFunction.getOpType() != null ? OP_TYPE.byName(defineFunction.getOpType().value()) : null;
    return new KiePMMLDefineFunction(defineFunction.getName(), getKiePMMLExtensions(defineFunction.getExtensions()), dataType, opType, kiePMMLParameterFields, getKiePMMLExpression(defineFunction.getExpression()));
}
Also used : KiePMMLDefineFunction(org.kie.pmml.commons.transformations.KiePMMLDefineFunction) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) KiePMMLParameterField(org.kie.pmml.commons.transformations.KiePMMLParameterField) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE)

Example 7 with DATA_TYPE

use of org.kie.pmml.api.enums.DATA_TYPE in project drools by kiegroup.

the class KiePMMLMiningFieldInstanceFactory method getKiePMMLMiningField.

public static KiePMMLMiningField getKiePMMLMiningField(final MiningField toConvert, final Field<?> field) {
    String name = toConvert.getName() != null ? toConvert.getName().getValue() : "" + toConvert.hashCode();
    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<KiePMMLInterval> intervals = field instanceof DataField ? getKiePMMLIntervals(((DataField) field).getIntervals()) : Collections.emptyList();
    final KiePMMLMiningField.Builder builder = KiePMMLMiningField.builder(name, Collections.emptyList()).withFieldUsageType(fieldUsageType).withOpType(opType).withDataType(dataType).withMissingValueTreatmentMethod(missingValueTreatmentMethod).withInvalidValueTreatmentMethod(invalidValueTreatmentMethod).withMissingValueReplacement(missingValueReplacement).withInvalidValueReplacement(invalidValueReplacement).withAllowedValues(allowedValues).withIntervals(intervals);
    return builder.build();
}
Also used : 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) KiePMMLInterval(org.kie.pmml.commons.model.expressions.KiePMMLInterval) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) KiePMMLMiningField(org.kie.pmml.commons.model.KiePMMLMiningField) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) INVALID_VALUE_TREATMENT_METHOD(org.kie.pmml.api.enums.INVALID_VALUE_TREATMENT_METHOD)

Example 8 with DATA_TYPE

use of org.kie.pmml.api.enums.DATA_TYPE in project drools by kiegroup.

the class KiePMMLMapValuesInstanceFactory method getKiePMMLMapValues.

static KiePMMLMapValues getKiePMMLMapValues(final MapValues mapValues) {
    DATA_TYPE dataType = mapValues.getDataType() != null ? DATA_TYPE.byName(mapValues.getDataType().value()) : null;
    KiePMMLMapValues.Builder builder = KiePMMLMapValues.builder(UUID.randomUUID().toString(), getKiePMMLExtensions(mapValues.getExtensions()), mapValues.getOutputColumn()).withKiePMMLInlineTable(getKiePMMLInlineTable(mapValues.getInlineTable())).withDataType(dataType);
    if (mapValues.getDefaultValue() != null) {
        builder = builder.withDefaultValue(mapValues.getDefaultValue().toString());
    }
    if (mapValues.getMapMissingTo() != null) {
        builder = builder.withMapMissingTo(mapValues.getMapMissingTo().toString());
    }
    if (mapValues.hasFieldColumnPairs()) {
        builder = builder.withKiePMMLFieldColumnPairs(getKiePMMLFieldColumnPairs(mapValues.getFieldColumnPairs()));
    }
    return builder.build();
}
Also used : KiePMMLMapValues(org.kie.pmml.commons.model.expressions.KiePMMLMapValues) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE)

Example 9 with DATA_TYPE

use of org.kie.pmml.api.enums.DATA_TYPE in project drools by kiegroup.

the class CommonCodegenUtilsTest method literalExprFromDataType.

@Test
public void literalExprFromDataType() {
    Map<DATA_TYPE, String> inputMap = new HashMap<>();
    inputMap.put(DATA_TYPE.STRING, "TEST");
    inputMap.put(DATA_TYPE.INTEGER, "1");
    inputMap.put(DATA_TYPE.FLOAT, "2.0");
    inputMap.put(DATA_TYPE.DOUBLE, "3.0");
    inputMap.put(DATA_TYPE.BOOLEAN, "true");
    inputMap.put(DATA_TYPE.DATE, "2021-06-01");
    inputMap.put(DATA_TYPE.TIME, "11:21:31");
    inputMap.put(DATA_TYPE.DATE_TIME, "2021-06-01T11:21:31");
    inputMap.put(DATA_TYPE.DATE_DAYS_SINCE_0, "10");
    inputMap.put(DATA_TYPE.DATE_DAYS_SINCE_1960, "20");
    inputMap.put(DATA_TYPE.DATE_DAYS_SINCE_1970, "30");
    inputMap.put(DATA_TYPE.DATE_DAYS_SINCE_1980, "40");
    inputMap.put(DATA_TYPE.TIME_SECONDS, "50");
    inputMap.put(DATA_TYPE.DATE_TIME_SECONDS_SINCE_0, "60");
    inputMap.put(DATA_TYPE.DATE_TIME_SECONDS_SINCE_1960, "70");
    inputMap.put(DATA_TYPE.DATE_TIME_SECONDS_SINCE_1970, "80");
    inputMap.put(DATA_TYPE.DATE_TIME_SECONDS_SINCE_1980, "90");
    for (Map.Entry<DATA_TYPE, String> input : inputMap.entrySet()) {
        assertTrue(literalExprFrom(input.getKey(), null) instanceof NullLiteralExpr);
        Expression output = literalExprFrom(input.getKey(), input.getValue());
        switch(input.getKey()) {
            case STRING:
                assertTrue(output instanceof StringLiteralExpr);
                break;
            case INTEGER:
                assertTrue(output instanceof IntegerLiteralExpr);
                break;
            case DOUBLE:
            case FLOAT:
                assertTrue(output instanceof DoubleLiteralExpr);
                break;
            case BOOLEAN:
                assertTrue(output instanceof BooleanLiteralExpr);
                break;
            case DATE:
            case TIME:
            case DATE_TIME:
                assertTrue(output instanceof MethodCallExpr);
                break;
            case DATE_DAYS_SINCE_0:
            case DATE_DAYS_SINCE_1960:
            case DATE_DAYS_SINCE_1970:
            case DATE_DAYS_SINCE_1980:
            case TIME_SECONDS:
            case DATE_TIME_SECONDS_SINCE_0:
            case DATE_TIME_SECONDS_SINCE_1960:
            case DATE_TIME_SECONDS_SINCE_1970:
            case DATE_TIME_SECONDS_SINCE_1980:
                assertTrue(output instanceof LongLiteralExpr);
        }
    }
    assertThrows(IllegalArgumentException.class, () -> literalExprFrom(null, null));
    assertThrows(IllegalArgumentException.class, () -> literalExprFrom(null, "test"));
}
Also used : IntegerLiteralExpr(com.github.javaparser.ast.expr.IntegerLiteralExpr) HashMap(java.util.HashMap) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) NullLiteralExpr(com.github.javaparser.ast.expr.NullLiteralExpr) Expression(com.github.javaparser.ast.expr.Expression) DoubleLiteralExpr(com.github.javaparser.ast.expr.DoubleLiteralExpr) BooleanLiteralExpr(com.github.javaparser.ast.expr.BooleanLiteralExpr) LongLiteralExpr(com.github.javaparser.ast.expr.LongLiteralExpr) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) Map(java.util.Map) HashMap(java.util.HashMap) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) Test(org.junit.Test)

Example 10 with DATA_TYPE

use of org.kie.pmml.api.enums.DATA_TYPE in project drools by kiegroup.

the class PreProcessTest method convertInputDataNotConvertibles.

@Test(expected = KiePMMLException.class)
public void convertInputDataNotConvertibles() {
    List<KiePMMLMiningField> miningFields = IntStream.range(0, 3).mapToObj(i -> {
        DATA_TYPE dataType = DATA_TYPE.values()[i];
        new MiningField("FIELD-" + i, null, null, dataType, null, null, null, null, null, null);
        return KiePMMLMiningField.builder("FIELD-" + i, null).withDataType(dataType).build();
    }).collect(Collectors.toList());
    PMMLRequestData pmmlRequestData = new PMMLRequestData("123", "modelName");
    pmmlRequestData.addRequestParam("FIELD-0", 123);
    pmmlRequestData.addRequestParam("FIELD-1", true);
    pmmlRequestData.addRequestParam("FIELD-2", "123");
    PreProcess.convertInputData(miningFields, pmmlRequestData);
}
Also used : IntStream(java.util.stream.IntStream) CLOSURE(org.kie.pmml.api.enums.CLOSURE) KiePMMLConstant(org.kie.pmml.commons.model.expressions.KiePMMLConstant) Arrays(java.util.Arrays) KiePMMLParameterField(org.kie.pmml.commons.transformations.KiePMMLParameterField) KiePMMLMiningField(org.kie.pmml.commons.model.KiePMMLMiningField) KiePMMLInterval(org.kie.pmml.commons.model.expressions.KiePMMLInterval) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) ArrayList(java.util.ArrayList) MiningField(org.kie.pmml.api.models.MiningField) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) KiePMMLTransformationDictionary(org.kie.pmml.commons.transformations.KiePMMLTransformationDictionary) Map(java.util.Map) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) KiePMMLFieldRef(org.kie.pmml.commons.model.expressions.KiePMMLFieldRef) MISSING_VALUE_TREATMENT_METHOD(org.kie.pmml.api.enums.MISSING_VALUE_TREATMENT_METHOD) INVALID_VALUE_TREATMENT_METHOD(org.kie.pmml.api.enums.INVALID_VALUE_TREATMENT_METHOD) MINING_FUNCTION(org.kie.pmml.api.enums.MINING_FUNCTION) ParameterInfo(org.kie.api.pmml.ParameterInfo) KiePMMLDefineFunction(org.kie.pmml.commons.transformations.KiePMMLDefineFunction) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Collectors(java.util.stream.Collectors) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) List(java.util.List) KiePMMLApply(org.kie.pmml.commons.model.expressions.KiePMMLApply) Assert.assertNull(org.junit.Assert.assertNull) PMMLRequestData(org.kie.api.pmml.PMMLRequestData) KiePMMLTestingModel(org.kie.pmml.commons.testingutility.KiePMMLTestingModel) Optional(java.util.Optional) Collections(java.util.Collections) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) Assert.assertEquals(org.junit.Assert.assertEquals) KiePMMLDerivedField(org.kie.pmml.commons.transformations.KiePMMLDerivedField) PMMLRequestData(org.kie.api.pmml.PMMLRequestData) KiePMMLMiningField(org.kie.pmml.commons.model.KiePMMLMiningField) MiningField(org.kie.pmml.api.models.MiningField) KiePMMLMiningField(org.kie.pmml.commons.model.KiePMMLMiningField) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) Test(org.junit.Test)

Aggregations

DATA_TYPE (org.kie.pmml.api.enums.DATA_TYPE)36 Test (org.junit.Test)17 OP_TYPE (org.kie.pmml.api.enums.OP_TYPE)15 DataField (org.dmg.pmml.DataField)10 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 INVALID_VALUE_TREATMENT_METHOD (org.kie.pmml.api.enums.INVALID_VALUE_TREATMENT_METHOD)8 MISSING_VALUE_TREATMENT_METHOD (org.kie.pmml.api.enums.MISSING_VALUE_TREATMENT_METHOD)8 KiePMMLException (org.kie.pmml.api.exceptions.KiePMMLException)8 List (java.util.List)7 MiningField (org.dmg.pmml.MiningField)7 KiePMMLMiningField (org.kie.pmml.commons.model.KiePMMLMiningField)7 KiePMMLInterval (org.kie.pmml.commons.model.expressions.KiePMMLInterval)7 KiePMMLDefineFunction (org.kie.pmml.commons.transformations.KiePMMLDefineFunction)7 KiePMMLParameterField (org.kie.pmml.commons.transformations.KiePMMLParameterField)7 Optional (java.util.Optional)6 Collectors (java.util.stream.Collectors)6 IntStream (java.util.stream.IntStream)6 Assert.assertEquals (org.junit.Assert.assertEquals)6