Search in sources :

Example 11 with Constant

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);
}
Also used : KiePMMLConstant(org.kie.pmml.commons.model.expressions.KiePMMLConstant) Constant(org.dmg.pmml.Constant) Statement(com.github.javaparser.ast.stmt.Statement) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) KiePMMLComplexPartialScore(org.kie.pmml.models.scorecard.model.KiePMMLComplexPartialScore) ComplexPartialScore(org.dmg.pmml.scorecard.ComplexPartialScore) Test(org.junit.Test)

Example 12 with Constant

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));
}
Also used : Expression(org.dmg.pmml.Expression) FunctionExpression(org.jpmml.rexp.FunctionExpression) Constant(org.dmg.pmml.Constant) Test(org.junit.Test)

Example 13 with Constant

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;
}
Also used : Constant(org.dmg.pmml.Constant) ArrayList(java.util.ArrayList)

Example 14 with Constant

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;
}
Also used : KiePMMLConstant(org.kie.pmml.commons.model.expressions.KiePMMLConstant) Constant(org.dmg.pmml.Constant) DerivedField(org.dmg.pmml.DerivedField) KiePMMLDerivedField(org.kie.pmml.commons.transformations.KiePMMLDerivedField)

Example 15 with Constant

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);
}
Also used : KiePMMLConstant(org.kie.pmml.commons.model.expressions.KiePMMLConstant) Constant(org.dmg.pmml.Constant) Statement(com.github.javaparser.ast.stmt.Statement) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) Test(org.junit.Test)

Aggregations

Constant (org.dmg.pmml.Constant)23 KiePMMLConstant (org.kie.pmml.commons.model.expressions.KiePMMLConstant)13 Test (org.junit.Test)10 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)7 Statement (com.github.javaparser.ast.stmt.Statement)7 Apply (org.dmg.pmml.Apply)7 DerivedField (org.dmg.pmml.DerivedField)7 FieldRef (org.dmg.pmml.FieldRef)6 KiePMMLApply (org.kie.pmml.commons.model.expressions.KiePMMLApply)5 DefineFunction (org.dmg.pmml.DefineFunction)4 ComplexPartialScore (org.dmg.pmml.scorecard.ComplexPartialScore)4 KiePMMLFieldRef (org.kie.pmml.commons.model.expressions.KiePMMLFieldRef)4 KiePMMLDerivedField (org.kie.pmml.commons.transformations.KiePMMLDerivedField)4 KiePMMLComplexPartialScore (org.kie.pmml.models.scorecard.model.KiePMMLComplexPartialScore)4 CommonTestingUtils.getDATA_TYPEString (org.kie.pmml.compiler.api.CommonTestingUtils.getDATA_TYPEString)3 CommonTestingUtils.getOP_TYPEString (org.kie.pmml.compiler.api.CommonTestingUtils.getOP_TYPEString)3 Expression (org.dmg.pmml.Expression)2 ParameterField (org.dmg.pmml.ParameterField)2 ContinuousFeature (org.jpmml.converter.ContinuousFeature)2 Feature (org.jpmml.converter.Feature)2