use of org.dmg.pmml.Constant in project drools by kiegroup.
the class KiePMMLComplexPartialScoreFactoryTest method getComplexPartialScoreVariableDeclaration.
@Test
public void getComplexPartialScoreVariableDeclaration() throws IOException {
final String variableName = "variableName";
Constant constant = new Constant();
constant.setValue(value1);
ComplexPartialScore complexPartialScore = new ComplexPartialScore();
complexPartialScore.setExpression(constant);
BlockStmt retrieved = KiePMMLComplexPartialScoreFactory.getComplexPartialScoreVariableDeclaration(variableName, complexPartialScore);
String text = getFileContent(TEST_01_SOURCE);
Statement expected = JavaParserUtils.parseBlock(String.format(text, constant.getValue(), variableName));
assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
List<Class<?>> imports = Arrays.asList(KiePMMLConstant.class, KiePMMLComplexPartialScore.class, Collections.class);
commonValidateCompilationWithImports(retrieved, imports);
}
use of org.dmg.pmml.Constant in project jpmml-r by jpmml.
the class ExpressionTranslatorTest method translateParenthesizedExpression.
@Test
public void translateParenthesizedExpression() {
String string = "TRUE | TRUE & FALSE";
Constant trueConstant = PMMLUtil.createConstant("true", DataType.BOOLEAN);
Constant falseConstant = PMMLUtil.createConstant("false", DataType.BOOLEAN);
Expression expected = PMMLUtil.createApply(PMMLFunctions.OR, trueConstant, PMMLUtil.createApply(PMMLFunctions.AND, trueConstant, falseConstant));
Expression actual = ExpressionTranslator.translateExpression(string);
assertTrue(ReflectionUtil.equals(expected, actual));
string = "(TRUE | TRUE) & FALSE";
expected = PMMLUtil.createApply(PMMLFunctions.AND, PMMLUtil.createApply(PMMLFunctions.OR, trueConstant, trueConstant), falseConstant);
actual = ExpressionTranslator.translateExpression(string);
assertTrue(ReflectionUtil.equals(expected, actual));
}
use of org.dmg.pmml.Constant in project jpmml-r by jpmml.
the class FormulaUtil method parseVector.
private static List<String> parseVector(FunctionExpression.Argument argument) {
List<String> result = new ArrayList<>();
FunctionExpression vectorExpression = toVectorExpression(argument);
List<FunctionExpression.Argument> objectArguments = vectorExpression.getArguments();
for (FunctionExpression.Argument objectArgument : objectArguments) {
Constant constant = (Constant) objectArgument.getExpression();
String string = ValueUtil.asString(constant.getValue());
result.add(string);
}
return result;
}
use of org.dmg.pmml.Constant in project drools by kiegroup.
the class KiePMMLTransformationDictionaryFactoryTest method getDerivedField.
private DerivedField getDerivedField(int counter) {
Constant constant = new Constant();
constant.setValue(value1);
DerivedField toReturn = new DerivedField();
toReturn.setName(FieldName.create(PARAM_2 + counter));
toReturn.setDataType(DataType.DOUBLE);
toReturn.setOpType(OpType.CONTINUOUS);
toReturn.setExpression(constant);
return toReturn;
}
use of org.dmg.pmml.Constant in project drools by kiegroup.
the class KiePMMLConstantFactoryTest method getConstantVariableDeclaration.
@Test
public void getConstantVariableDeclaration() throws IOException {
String variableName = "variableName";
Object value = 2342.21;
Constant constant = new Constant();
constant.setValue(value);
BlockStmt retrieved = KiePMMLConstantFactory.getConstantVariableDeclaration(variableName, constant);
String text = getFileContent(TEST_01_SOURCE);
Statement expected = JavaParserUtils.parseBlock(String.format(text, variableName, value));
assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
List<Class<?>> imports = Arrays.asList(KiePMMLConstant.class, Collections.class);
commonValidateCompilationWithImports(retrieved, imports);
}
Aggregations