Search in sources :

Example 16 with Apply

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

the class ExpressionCompactorTest method compactLogicalExpression.

@Test
public void compactLogicalExpression() {
    FieldRef fieldRef = new FieldRef(FieldName.create("x"));
    Apply first = createApply("equal", fieldRef, createConstant("1"));
    Apply leftLeftChild = createApply("equal", fieldRef, createConstant("2/L/L"));
    Apply leftRightChild = createApply("equal", fieldRef, createConstant("2/L/R"));
    Apply leftChild = createApply("or", leftLeftChild, leftRightChild);
    Apply rightChild = createApply("equal", fieldRef, createConstant("2/R"));
    Apply second = createApply("or", leftChild, rightChild);
    Apply third = createApply("equal", fieldRef, createConstant("3"));
    Apply apply = compact(createApply("or", first, second, third));
    assertEquals(Arrays.asList(first, leftLeftChild, leftRightChild, rightChild, third), apply.getExpressions());
}
Also used : FieldRef(org.dmg.pmml.FieldRef) Apply(org.dmg.pmml.Apply) Test(org.junit.Test)

Example 17 with Apply

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

the class ExpressionTranslatorTest method translateLogicalExpression.

@Test
public void translateLogicalExpression() {
    Apply apply = (Apply) ExpressionTranslator.translateExpression("a >= 0.0 & b >= 0.0 | c <= 0.0");
    List<Expression> expressions = checkApply(apply, "or", Apply.class, Apply.class);
    Expression left = expressions.get(0);
    Expression right = expressions.get(1);
    expressions = checkApply((Apply) left, "and", Apply.class, Apply.class);
    checkApply((Apply) right, "lessOrEqual", FieldRef.class, Constant.class);
    left = expressions.get(0);
    right = expressions.get(1);
    checkApply((Apply) left, "greaterOrEqual", FieldRef.class, Constant.class);
    checkApply((Apply) right, "greaterOrEqual", FieldRef.class, Constant.class);
}
Also used : Expression(org.dmg.pmml.Expression) Apply(org.dmg.pmml.Apply) Test(org.junit.Test)

Example 18 with Apply

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

the class ExpressionTranslatorTest method translateExponentiationExpression.

@Test
public void translateExponentiationExpression() {
    Apply apply = (Apply) ExpressionTranslator.translateExpression("-2^-3");
    List<Expression> expressions = checkApply(apply, "*", Constant.class, Apply.class);
    Expression left = expressions.get(0);
    Expression right = expressions.get(1);
    checkConstant((Constant) left, "-1", null);
    expressions = checkApply((Apply) right, "pow", Constant.class, Constant.class);
    left = expressions.get(0);
    right = expressions.get(1);
    checkConstant((Constant) left, "2", null);
    checkConstant((Constant) right, "-3", null);
    apply = (Apply) ExpressionTranslator.translateExpression("-2^-2*1.5");
    expressions = checkApply(apply, "*", Apply.class, Constant.class);
    left = expressions.get(0);
    right = expressions.get(1);
    expressions = checkApply((Apply) left, "*", Constant.class, Apply.class);
    checkConstant((Constant) right, "1.5", DataType.DOUBLE);
    left = expressions.get(0);
    right = expressions.get(1);
    checkConstant((Constant) left, "-1", null);
    expressions = checkApply((Apply) right, "pow", Constant.class, Constant.class);
    left = expressions.get(0);
    right = expressions.get(1);
    checkConstant((Constant) left, "2", null);
    checkConstant((Constant) right, "-2", null);
}
Also used : Expression(org.dmg.pmml.Expression) Apply(org.dmg.pmml.Apply) Constant(org.dmg.pmml.Constant) Test(org.junit.Test)

Example 19 with Apply

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

the class ExpressionTranslatorTest method translateRelationalExpression.

@Test
public void translateRelationalExpression() {
    Apply apply = (Apply) ExpressionTranslator.translateExpression("if(x < 0) \"negative\" else if(x > 0) \"positive\" else \"zero\"");
    List<Expression> expressions = checkApply(apply, "if", Apply.class, Constant.class, Apply.class);
    Expression condition = expressions.get(0);
    checkApply((Apply) condition, "lessThan", FieldRef.class, Constant.class);
    Expression first = expressions.get(1);
    Expression second = expressions.get(2);
    checkConstant((Constant) first, "negative", null);
    expressions = checkApply((Apply) second, "if", Apply.class, Constant.class, Constant.class);
    condition = expressions.get(0);
    checkApply((Apply) condition, "greaterThan", FieldRef.class, Constant.class);
    first = expressions.get(1);
    second = expressions.get(2);
    checkConstant((Constant) first, "positive", null);
    checkConstant((Constant) second, "zero", null);
}
Also used : Expression(org.dmg.pmml.Expression) Apply(org.dmg.pmml.Apply) Constant(org.dmg.pmml.Constant) Test(org.junit.Test)

Example 20 with Apply

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

the class ExpressionTranslatorTest method translateIfExpression.

@Test
public void translateIfExpression() {
    Apply apply = (Apply) ExpressionTranslator.translateExpression("if(is.na(x)) TRUE else FALSE");
    List<Expression> expressions = checkApply(apply, "if", Apply.class, Constant.class, Constant.class);
    Expression condition = expressions.get(0);
    checkApply((Apply) condition, "isMissing", FieldRef.class);
    Expression first = expressions.get(1);
    Expression second = expressions.get(2);
    checkConstant((Constant) first, "true", DataType.BOOLEAN);
    checkConstant((Constant) second, "false", DataType.BOOLEAN);
}
Also used : Expression(org.dmg.pmml.Expression) Apply(org.dmg.pmml.Apply) Test(org.junit.Test)

Aggregations

Apply (org.dmg.pmml.Apply)25 Expression (org.dmg.pmml.Expression)11 Test (org.junit.Test)10 DerivedField (org.dmg.pmml.DerivedField)9 Feature (org.jpmml.converter.Feature)9 ContinuousFeature (org.jpmml.converter.ContinuousFeature)7 FieldRef (org.dmg.pmml.FieldRef)6 ArrayList (java.util.ArrayList)5 Constant (org.dmg.pmml.Constant)5 DataField (org.dmg.pmml.DataField)3 FieldName (org.dmg.pmml.FieldName)3 CategoricalFeature (org.jpmml.converter.CategoricalFeature)3 InteractionFeature (org.jpmml.converter.InteractionFeature)2 PMMLEncoder (org.jpmml.converter.PMMLEncoder)2 DocumentFeature (org.jpmml.sparkml.DocumentFeature)2 Binarizer (org.apache.spark.ml.feature.Binarizer)1 PCAModel (org.apache.spark.ml.feature.PCAModel)1 RegexTokenizer (org.apache.spark.ml.feature.RegexTokenizer)1 StringIndexerModel (org.apache.spark.ml.feature.StringIndexerModel)1 Tokenizer (org.apache.spark.ml.feature.Tokenizer)1