use of org.dmg.pmml.FieldRef in project jpmml-sparkml by jpmml.
the class ExpressionTranslatorTest method translateArithmeticExpression.
@Test
public void translateArithmeticExpression() {
String string = "-((x1 - 1) / (x2 + 1))";
Apply expected = PMMLUtil.createApply(PMMLFunctions.MULTIPLY, PMMLUtil.createConstant(-1), PMMLUtil.createApply(PMMLFunctions.DIVIDE, PMMLUtil.createApply(PMMLFunctions.SUBTRACT, new FieldRef(FieldName.create("x1")), PMMLUtil.createConstant(1, DataType.DOUBLE)), PMMLUtil.createApply(PMMLFunctions.ADD, new FieldRef(FieldName.create("x2")), PMMLUtil.createConstant(1, DataType.DOUBLE))));
checkExpression(expected, string);
}
use of org.dmg.pmml.FieldRef 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.FieldRef in project jpmml-r by jpmml.
the class PreProcessEncoder method encodeExpression.
private Expression encodeExpression(Feature feature) {
FieldName name = feature.getName();
Expression expression = feature.ref();
List<Double> ranges = this.ranges.get(name);
if (ranges != null) {
Double min = ranges.get(0);
Double max = ranges.get(1);
expression = PMMLUtil.createApply("/", PMMLUtil.createApply("-", expression, PMMLUtil.createConstant(min)), PMMLUtil.createConstant(max - min));
}
Double mean = this.mean.get(name);
if (mean != null) {
expression = PMMLUtil.createApply("-", expression, PMMLUtil.createConstant(mean));
}
Double std = this.std.get(name);
if (std != null) {
expression = PMMLUtil.createApply("/", expression, PMMLUtil.createConstant(std));
}
Double median = this.median.get(name);
if (median != null) {
expression = PMMLUtil.createApply("if", PMMLUtil.createApply("isNotMissing", new FieldRef(name)), expression, PMMLUtil.createConstant(median));
}
if (expression instanceof FieldRef) {
return null;
}
return expression;
}
use of org.dmg.pmml.FieldRef in project drools by kiegroup.
the class KiePMMLApplyFactoryTest method getApplyVariableDeclarationWithApply.
@Test
public void getApplyVariableDeclarationWithApply() throws IOException {
String variableName = "variableName";
Apply nestedApply = new Apply();
nestedApply.setFunction("nested_function");
String mapMissingTo = "mapMissingTo";
nestedApply.setMapMissingTo(mapMissingTo);
String defaultValue = "defaultValue";
nestedApply.setDefaultValue(defaultValue);
InvalidValueTreatmentMethod nestedInvalidValueTreatmentMethod = InvalidValueTreatmentMethod.AS_MISSING;
nestedApply.setInvalidValueTreatment(nestedInvalidValueTreatmentMethod);
FieldRef fieldRef1 = new FieldRef();
fieldRef1.setField(FieldName.create(PARAM_1));
FieldRef fieldRef2 = new FieldRef();
fieldRef2.setField(FieldName.create(PARAM_2));
nestedApply.addExpressions(fieldRef1, fieldRef2);
Apply apply = new Apply();
apply.setFunction(function);
InvalidValueTreatmentMethod invalidValueTreatmentMethod = InvalidValueTreatmentMethod.AS_MISSING;
apply.setInvalidValueTreatment(invalidValueTreatmentMethod);
apply.addExpressions(nestedApply);
BlockStmt retrieved = KiePMMLApplyFactory.getApplyVariableDeclaration(variableName, apply);
String text = getFileContent(TEST_03_SOURCE);
Statement expected = JavaParserUtils.parseBlock(String.format(text, PARAM_1, PARAM_2, defaultValue, mapMissingTo, nestedInvalidValueTreatmentMethod.value(), variableName, invalidValueTreatmentMethod.value()));
assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
List<Class<?>> imports = Arrays.asList(KiePMMLFieldRef.class, KiePMMLApply.class, Collections.class, Arrays.class);
commonValidateCompilationWithImports(retrieved, imports);
}
use of org.dmg.pmml.FieldRef in project drools by kiegroup.
the class KiePMMLDerivedFieldFactoryTest method getDerivedFieldVariableDeclarationWithFieldRef.
@Test
public void getDerivedFieldVariableDeclarationWithFieldRef() throws IOException {
final String variableName = "variableName";
FieldRef fieldRef = new FieldRef();
fieldRef.setField(FieldName.create("FIELD_REF"));
DerivedField derivedField = new DerivedField();
derivedField.setName(FieldName.create(PARAM_1));
derivedField.setDataType(DataType.DOUBLE);
derivedField.setOpType(OpType.CONTINUOUS);
derivedField.setExpression(fieldRef);
String dataType = getDATA_TYPEString(derivedField.getDataType());
String opType = getOP_TYPEString(derivedField.getOpType());
BlockStmt retrieved = KiePMMLDerivedFieldFactory.getDerivedFieldVariableDeclaration(variableName, derivedField);
String text = getFileContent(TEST_02_SOURCE);
Statement expected = JavaParserUtils.parseBlock(String.format(text, fieldRef.getField().getValue(), variableName, derivedField.getName().getValue(), dataType, opType));
assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
List<Class<?>> imports = Arrays.asList(KiePMMLFieldRef.class, KiePMMLDerivedField.class, Collections.class);
commonValidateCompilationWithImports(retrieved, imports);
}
Aggregations