use of org.kie.pmml.api.models.TargetValue in project drools by kiegroup.
the class KiePMMLTargetInstanceFactory method getKiePMMLTarget.
public static KiePMMLTarget getKiePMMLTarget(final Target target) {
final List<TargetValue> targetValues = target.hasTargetValues() ? target.getTargetValues().stream().map(KiePMMLTargetInstanceFactory::getKieTargetValue).collect(Collectors.toList()) : Collections.emptyList();
final OP_TYPE opType = target.getOpType() != null ? OP_TYPE.byName(target.getOpType().value()) : null;
final String field = target.getField() != null ? target.getField().getValue() : null;
final CAST_INTEGER castInteger = target.getCastInteger() != null ? CAST_INTEGER.byName(target.getCastInteger().value()) : null;
TargetField targetField = new TargetField(targetValues, opType, field, castInteger, target.getMin(), target.getMax(), target.getRescaleConstant(), target.getRescaleFactor());
final KiePMMLTarget.Builder builder = KiePMMLTarget.builder(targetField.getName(), Collections.emptyList(), targetField);
return builder.build();
}
use of org.kie.pmml.api.models.TargetValue in project drools by kiegroup.
the class KiePMMLModelFactoryUtilsTest method commonVerifyKiePMMLTargetFieldsMethodCallExpr.
private void commonVerifyKiePMMLTargetFieldsMethodCallExpr(MethodCallExpr retrieved, TargetField kieTargetField) throws IOException {
String text = getFileContent(TEST_15_SOURCE);
List<TargetValue> kieTargetValues = kieTargetField.getTargetValues();
String opType = OP_TYPE.class.getCanonicalName() + "." + kieTargetField.getOpType().toString();
String castInteger = CAST_INTEGER.class.getCanonicalName() + "." + kieTargetField.getCastInteger().toString();
Expression expected = JavaParserUtils.parseExpression(String.format(text, kieTargetField.getName(), kieTargetValues.get(0).getValue(), kieTargetValues.get(0).getDisplayValue(), kieTargetValues.get(0).getPriorProbability(), kieTargetValues.get(0).getDefaultValue(), kieTargetValues.get(1).getValue(), kieTargetValues.get(1).getDisplayValue(), kieTargetValues.get(1).getPriorProbability(), kieTargetValues.get(1).getDefaultValue(), kieTargetValues.get(2).getValue(), kieTargetValues.get(2).getDisplayValue(), kieTargetValues.get(2).getPriorProbability(), kieTargetValues.get(2).getDefaultValue(), opType, kieTargetField.getField(), castInteger, kieTargetField.getMin(), kieTargetField.getMax(), kieTargetField.getRescaleConstant(), kieTargetField.getRescaleFactor()));
assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
List<Class<?>> imports = Arrays.asList(Arrays.class, Collections.class, KiePMMLTarget.class, KiePMMLTargetValue.class, TargetField.class, TargetValue.class);
commonValidateCompilationWithImports(retrieved, imports);
}
use of org.kie.pmml.api.models.TargetValue in project drools by kiegroup.
the class KiePMMLTargetValueFactoryTest method getKiePMMLTargetValueVariableInitializer.
@Test
public void getKiePMMLTargetValueVariableInitializer() throws IOException {
TargetValue targetValue = convertToKieTargetValue(getRandomTargetValue());
MethodCallExpr retrieved = KiePMMLTargetValueFactory.getKiePMMLTargetValueVariableInitializer(targetValue);
String text = getFileContent(TEST_01_SOURCE);
Expression expected = JavaParserUtils.parseExpression(String.format(text, targetValue.getName(), targetValue.getValue(), targetValue.getDisplayValue(), targetValue.getPriorProbability(), targetValue.getDefaultValue()));
assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
List<Class<?>> imports = Arrays.asList(Arrays.class, Collections.class, KiePMMLTargetValue.class, TargetValue.class);
commonValidateCompilationWithImports(retrieved, imports);
}
use of org.kie.pmml.api.models.TargetValue in project drools by kiegroup.
the class TargetValueFactoryTest method getTargetValueVariableInitializer.
@Test
public void getTargetValueVariableInitializer() throws IOException {
TargetValue targetValue = convertToKieTargetValue(getRandomTargetValue());
ObjectCreationExpr retrieved = TargetValueFactory.getTargetValueVariableInitializer(targetValue);
String text = getFileContent(TEST_01_SOURCE);
Expression expected = JavaParserUtils.parseExpression(String.format(text, targetValue.getValue(), targetValue.getDisplayValue(), targetValue.getPriorProbability(), targetValue.getDefaultValue()));
assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
List<Class<?>> imports = Arrays.asList(Arrays.class, Collections.class, KiePMMLTargetValue.class, TargetValue.class);
commonValidateCompilationWithImports(retrieved, imports);
}
use of org.kie.pmml.api.models.TargetValue in project drools by kiegroup.
the class TargetFieldFactoryTest method getTargetFieldVariableInitializer.
@Test
public void getTargetFieldVariableInitializer() throws IOException {
TargetField kieTargetField = ModelUtils.convertToKieTargetField(getRandomTarget());
ObjectCreationExpr retrieved = TargetFieldFactory.getTargetFieldVariableInitializer(kieTargetField);
String text = getFileContent(TEST_01_SOURCE);
List<TargetValue> kieTargetValues = kieTargetField.getTargetValues();
String opType = OP_TYPE.class.getCanonicalName() + "." + kieTargetField.getOpType().toString();
String castInteger = CAST_INTEGER.class.getCanonicalName() + "." + kieTargetField.getCastInteger().toString();
Expression expected = JavaParserUtils.parseExpression(String.format(text, kieTargetValues.get(0).getValue(), kieTargetValues.get(0).getDisplayValue(), kieTargetValues.get(0).getPriorProbability(), kieTargetValues.get(0).getDefaultValue(), kieTargetValues.get(1).getValue(), kieTargetValues.get(1).getDisplayValue(), kieTargetValues.get(1).getPriorProbability(), kieTargetValues.get(1).getDefaultValue(), kieTargetValues.get(2).getValue(), kieTargetValues.get(2).getDisplayValue(), kieTargetValues.get(2).getPriorProbability(), kieTargetValues.get(2).getDefaultValue(), opType, kieTargetField.getField(), castInteger, kieTargetField.getMin(), kieTargetField.getMax(), kieTargetField.getRescaleConstant(), kieTargetField.getRescaleFactor()));
assertEquals(expected.toString(), retrieved.toString());
assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
List<Class<?>> imports = Arrays.asList(Arrays.class, Collections.class, KiePMMLTarget.class, KiePMMLTargetValue.class, TargetField.class, TargetValue.class);
commonValidateCompilationWithImports(retrieved, imports);
}
Aggregations