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()));
}
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();
}
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();
}
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"));
}
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);
}
Aggregations