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());
}
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);
}
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);
}
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);
}
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);
}
Aggregations