Search in sources :

Example 21 with Constant

use of org.dmg.pmml.Constant in project drools by kiegroup.

the class PMMLModelTestUtils method getDerivedField.

public static DerivedField getDerivedField(String fieldName) {
    DerivedField toReturn = new DerivedField();
    toReturn.setName(FieldName.create(fieldName));
    toReturn.setDataType(getRandomDataType());
    toReturn.setOpType(getRandomOpType());
    Constant expression = new Constant(5);
    expression.setDataType(DataType.INTEGER);
    toReturn.setExpression(expression);
    toReturn.setDisplayName("Display-" + fieldName);
    return toReturn;
}
Also used : Constant(org.dmg.pmml.Constant) DerivedField(org.dmg.pmml.DerivedField)

Example 22 with Constant

use of org.dmg.pmml.Constant in project jpmml-r by jpmml.

the class Formula method addField.

public void addField(Field<?> field) {
    RExpEncoder encoder = getEncoder();
    Feature feature = new ContinuousFeature(encoder, field);
    if (field instanceof DerivedField) {
        DerivedField derivedField = (DerivedField) field;
        Expression expression = derivedField.requireExpression();
        if (expression instanceof Apply) {
            Apply apply = (Apply) expression;
            if (checkApply(apply, PMMLFunctions.POW, FieldRef.class, Constant.class)) {
                List<Expression> expressions = apply.getExpressions();
                FieldRef fieldRef = (FieldRef) expressions.get(0);
                Constant constant = (Constant) expressions.get(1);
                try {
                    String string = ValueUtil.asString(constant.getValue());
                    int power = Integer.parseInt(string);
                    feature = new PowerFeature(encoder, fieldRef.requireField(), DataType.DOUBLE, power);
                } catch (NumberFormatException nfe) {
                // Ignored
                }
            }
        }
    }
    putFeature(field.requireName(), feature);
    this.fields.add(field);
}
Also used : PowerFeature(org.jpmml.converter.PowerFeature) FieldRef(org.dmg.pmml.FieldRef) Apply(org.dmg.pmml.Apply) Constant(org.dmg.pmml.Constant) Feature(org.jpmml.converter.Feature) PowerFeature(org.jpmml.converter.PowerFeature) BinaryFeature(org.jpmml.converter.BinaryFeature) ContinuousFeature(org.jpmml.converter.ContinuousFeature) BooleanFeature(org.jpmml.converter.BooleanFeature) InteractionFeature(org.jpmml.converter.InteractionFeature) CategoricalFeature(org.jpmml.converter.CategoricalFeature) ContinuousFeature(org.jpmml.converter.ContinuousFeature) Expression(org.dmg.pmml.Expression) DerivedField(org.dmg.pmml.DerivedField)

Example 23 with Constant

use of org.dmg.pmml.Constant in project jpmml-r by jpmml.

the class FormulaUtil method parseRevalue.

private static Map<String, String> parseRevalue(FunctionExpression.Argument replaceArgument) {
    Map<String, String> result = new LinkedHashMap<>();
    FunctionExpression vectorExpression = toVectorExpression(replaceArgument);
    List<FunctionExpression.Argument> objectArguments = vectorExpression.getArguments();
    for (FunctionExpression.Argument objectArgument : objectArguments) {
        String from = objectArgument.getTag();
        if (from == null) {
            throw new IllegalArgumentException();
        }
        Constant constant = (Constant) objectArgument.getExpression();
        String to = (String) constant.getValue();
        if (to == null) {
            throw new IllegalArgumentException();
        }
        result.put(from, to);
    }
    return result;
}
Also used : Constant(org.dmg.pmml.Constant) LinkedHashMap(java.util.LinkedHashMap)

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