diff --git a/pmml-rexp/src/main/java/org/jpmml/rexp/BinaryTreeConverter.java b/pmml-rexp/src/main/java/org/jpmml/rexp/BinaryTreeConverter.java index 180b53a..3a46a09 100644 --- a/pmml-rexp/src/main/java/org/jpmml/rexp/BinaryTreeConverter.java +++ b/pmml-rexp/src/main/java/org/jpmml/rexp/BinaryTreeConverter.java @@ -42,6 +42,7 @@ import org.jpmml.converter.CategoricalLabel; import org.jpmml.converter.ContinuousFeature; import org.jpmml.converter.Feature; +import org.jpmml.converter.FieldNames; import org.jpmml.converter.ModelUtil; import org.jpmml.converter.Schema; import org.jpmml.converter.SchemaUtil; @@ -89,7 +90,7 @@ public TreeModel encodeModel(Schema schema){ throw new IllegalArgumentException(); } - output.addOutputFields(ModelUtil.createEntityIdField("nodeId", DataType.STRING)); + output.addOutputFields(ModelUtil.createEntityIdField(FieldNames.NODE_ID, DataType.STRING)); TreeModel treeModel = encodeTreeModel(tree, schema) .setOutput(output); diff --git a/pmml-rexp/src/main/java/org/jpmml/rexp/EarthConverter.java b/pmml-rexp/src/main/java/org/jpmml/rexp/EarthConverter.java index ef28b5e..7ce1aff 100644 --- a/pmml-rexp/src/main/java/org/jpmml/rexp/EarthConverter.java +++ b/pmml-rexp/src/main/java/org/jpmml/rexp/EarthConverter.java @@ -31,12 +31,12 @@ import org.dmg.pmml.PMMLFunctions; import org.dmg.pmml.general_regression.GeneralRegressionModel; import org.jpmml.converter.ContinuousFeature; +import org.jpmml.converter.ExpressionUtil; import org.jpmml.converter.Feature; import org.jpmml.converter.FieldNameUtil; import org.jpmml.converter.FortranMatrixUtil; import org.jpmml.converter.InteractionFeature; import org.jpmml.converter.ModelUtil; -import org.jpmml.converter.PMMLUtil; import org.jpmml.converter.Schema; import org.jpmml.converter.SchemaUtil; import org.jpmml.converter.ValueUtil; @@ -186,15 +186,15 @@ private Apply createHingeFunction(int dir, Feature feature, double cut){ switch(dir){ case -1: - expression = PMMLUtil.createApply(PMMLFunctions.SUBTRACT, PMMLUtil.createConstant(cut), feature.ref()); + expression = ExpressionUtil.createApply(PMMLFunctions.SUBTRACT, ExpressionUtil.createConstant(cut), feature.ref()); break; case 1: - expression = PMMLUtil.createApply(PMMLFunctions.SUBTRACT, feature.ref(), PMMLUtil.createConstant(cut)); + expression = ExpressionUtil.createApply(PMMLFunctions.SUBTRACT, feature.ref(), ExpressionUtil.createConstant(cut)); break; default: throw new IllegalArgumentException(); } - return PMMLUtil.createApply(PMMLFunctions.MAX, expression, PMMLUtil.createConstant(0d)); + return ExpressionUtil.createApply(PMMLFunctions.MAX, expression, ExpressionUtil.createConstant(0d)); } } diff --git a/pmml-rexp/src/main/java/org/jpmml/rexp/FormulaUtil.java b/pmml-rexp/src/main/java/org/jpmml/rexp/FormulaUtil.java index 01582f4..ecf5cca 100644 --- a/pmml-rexp/src/main/java/org/jpmml/rexp/FormulaUtil.java +++ b/pmml-rexp/src/main/java/org/jpmml/rexp/FormulaUtil.java @@ -41,6 +41,7 @@ import org.dmg.pmml.MapValues; import org.dmg.pmml.OpType; import org.dmg.pmml.PMMLFunctions; +import org.jpmml.converter.ExpressionUtil; import org.jpmml.converter.Feature; import org.jpmml.converter.PMMLUtil; import org.jpmml.converter.ValueUtil; @@ -352,7 +353,7 @@ private Expression encodeIfElseExpression(FunctionExpression functionExpression, expressionFields.putAll(noArgument); // XXX: "Missing values in test give missing values in the result" - Apply apply = PMMLUtil.createApply(PMMLFunctions.IF, + Apply apply = ExpressionUtil.createApply(PMMLFunctions.IF, prepareExpression(testArgument, expressionFields, encoder), prepareExpression(yesArgument, expressionFields, encoder), prepareExpression(noArgument, expressionFields, encoder) @@ -466,7 +467,7 @@ private MapValues createMapValues(String name, Map mapping, List mapping.put(category, category); } - return PMMLUtil.createMapValues(name, mapping); + return ExpressionUtil.createMapValues(name, mapping); } static diff --git a/pmml-rexp/src/main/java/org/jpmml/rexp/IForestConverter.java b/pmml-rexp/src/main/java/org/jpmml/rexp/IForestConverter.java index 634c298..7e5df8e 100644 --- a/pmml-rexp/src/main/java/org/jpmml/rexp/IForestConverter.java +++ b/pmml-rexp/src/main/java/org/jpmml/rexp/IForestConverter.java @@ -39,9 +39,9 @@ import org.dmg.pmml.tree.Node; import org.dmg.pmml.tree.TreeModel; import org.jpmml.converter.ContinuousFeature; +import org.jpmml.converter.ExpressionUtil; import org.jpmml.converter.FortranMatrixUtil; import org.jpmml.converter.ModelUtil; -import org.jpmml.converter.PMMLUtil; import org.jpmml.converter.Schema; import org.jpmml.converter.Transformation; import org.jpmml.converter.ValueUtil; @@ -121,7 +121,7 @@ public String getName(String name){ @Override public Expression createExpression(FieldRef fieldRef){ - return PMMLUtil.createApply(PMMLFunctions.DIVIDE, fieldRef, PMMLUtil.createConstant(avgPathLength(xrow.asScalar()))); + return ExpressionUtil.createApply(PMMLFunctions.DIVIDE, fieldRef, ExpressionUtil.createConstant(avgPathLength(xrow.asScalar()))); } }; @@ -140,7 +140,7 @@ public boolean isFinalResult(){ @Override public Expression createExpression(FieldRef fieldRef){ - return PMMLUtil.createApply(PMMLFunctions.POW, PMMLUtil.createConstant(2d), PMMLUtil.createApply(PMMLFunctions.MULTIPLY, PMMLUtil.createConstant(-1d), fieldRef)); + return ExpressionUtil.createApply(PMMLFunctions.POW, ExpressionUtil.createConstant(2d), ExpressionUtil.createApply(PMMLFunctions.MULTIPLY, ExpressionUtil.createConstant(-1d), fieldRef)); } }; diff --git a/pmml-rexp/src/main/java/org/jpmml/rexp/MVRConverter.java b/pmml-rexp/src/main/java/org/jpmml/rexp/MVRConverter.java index d552c26..a9154fb 100644 --- a/pmml-rexp/src/main/java/org/jpmml/rexp/MVRConverter.java +++ b/pmml-rexp/src/main/java/org/jpmml/rexp/MVRConverter.java @@ -29,11 +29,11 @@ import org.dmg.pmml.PMMLFunctions; import org.dmg.pmml.general_regression.GeneralRegressionModel; import org.jpmml.converter.ContinuousFeature; +import org.jpmml.converter.ExpressionUtil; import org.jpmml.converter.Feature; import org.jpmml.converter.FieldNameUtil; import org.jpmml.converter.FortranMatrixUtil; import org.jpmml.converter.ModelUtil; -import org.jpmml.converter.PMMLUtil; import org.jpmml.converter.Schema; import org.jpmml.converter.SchemaUtil; import org.jpmml.converter.ValueUtil; @@ -130,7 +130,7 @@ private void scaleFeatures(RExpEncoder encoder){ ContinuousFeature continuousFeature = feature.toContinuousFeature(); - Apply apply = PMMLUtil.createApply(PMMLFunctions.DIVIDE, continuousFeature.ref(), PMMLUtil.createConstant(factor)); + Apply apply = ExpressionUtil.createApply(PMMLFunctions.DIVIDE, continuousFeature.ref(), ExpressionUtil.createConstant(factor)); DerivedField derivedField = encoder.createDerivedField(FieldNameUtil.create("scale", continuousFeature), OpType.CONTINUOUS, DataType.DOUBLE, apply); diff --git a/pmml-rexp/src/main/java/org/jpmml/rexp/PreProcessEncoder.java b/pmml-rexp/src/main/java/org/jpmml/rexp/PreProcessEncoder.java index 15ee5bc..465bd0b 100644 --- a/pmml-rexp/src/main/java/org/jpmml/rexp/PreProcessEncoder.java +++ b/pmml-rexp/src/main/java/org/jpmml/rexp/PreProcessEncoder.java @@ -31,11 +31,11 @@ import org.dmg.pmml.OpType; import org.dmg.pmml.PMMLFunctions; import org.jpmml.converter.ContinuousFeature; +import org.jpmml.converter.ExpressionUtil; import org.jpmml.converter.Feature; import org.jpmml.converter.FeatureUtil; import org.jpmml.converter.FieldNameUtil; import org.jpmml.converter.FortranMatrixUtil; -import org.jpmml.converter.PMMLUtil; import org.jpmml.converter.ValueUtil; public class PreProcessEncoder extends TransformerEncoder { @@ -105,30 +105,30 @@ private Expression encodeExpression(String name, Expression expression){ Double max = ranges.get(1); if(!ValueUtil.isZero(min)){ - expression = PMMLUtil.createApply(PMMLFunctions.SUBTRACT, expression, PMMLUtil.createConstant(min)); + expression = ExpressionUtil.createApply(PMMLFunctions.SUBTRACT, expression, ExpressionUtil.createConstant(min)); } // End if if(!ValueUtil.isOne(max - min)){ - expression = PMMLUtil.createApply(PMMLFunctions.DIVIDE, expression, PMMLUtil.createConstant(max - min)); + expression = ExpressionUtil.createApply(PMMLFunctions.DIVIDE, expression, ExpressionUtil.createConstant(max - min)); } } Double mean = this.mean.get(name); if(mean != null && !ValueUtil.isZero(mean)){ - expression = PMMLUtil.createApply(PMMLFunctions.SUBTRACT, expression, PMMLUtil.createConstant(mean)); + expression = ExpressionUtil.createApply(PMMLFunctions.SUBTRACT, expression, ExpressionUtil.createConstant(mean)); } Double std = this.std.get(name); if(std != null && !ValueUtil.isOne(std)){ - expression = PMMLUtil.createApply(PMMLFunctions.DIVIDE, expression, PMMLUtil.createConstant(std)); + expression = ExpressionUtil.createApply(PMMLFunctions.DIVIDE, expression, ExpressionUtil.createConstant(std)); } Double median = this.median.get(name); if(median != null){ - expression = PMMLUtil.createApply(PMMLFunctions.IF, - PMMLUtil.createApply(PMMLFunctions.ISNOTMISSING, new FieldRef(name)), + expression = ExpressionUtil.createApply(PMMLFunctions.IF, + ExpressionUtil.createApply(PMMLFunctions.ISNOTMISSING, new FieldRef(name)), expression, - PMMLUtil.createConstant(median) + ExpressionUtil.createConstant(median) ); } diff --git a/pmml-rexp/src/main/java/org/jpmml/rexp/SVMConverter.java b/pmml-rexp/src/main/java/org/jpmml/rexp/SVMConverter.java index 220c2b0..25ae310 100644 --- a/pmml-rexp/src/main/java/org/jpmml/rexp/SVMConverter.java +++ b/pmml-rexp/src/main/java/org/jpmml/rexp/SVMConverter.java @@ -36,11 +36,11 @@ import org.dmg.pmml.support_vector_machine.SupportVectorMachineModel; import org.jpmml.converter.ContinuousFeature; import org.jpmml.converter.ContinuousLabel; +import org.jpmml.converter.ExpressionUtil; import org.jpmml.converter.Feature; import org.jpmml.converter.FieldNameUtil; import org.jpmml.converter.FortranMatrix; import org.jpmml.converter.ModelUtil; -import org.jpmml.converter.PMMLUtil; import org.jpmml.converter.Schema; import org.jpmml.converter.SchemaUtil; import org.jpmml.converter.Transformation; @@ -102,7 +102,7 @@ public SupportVectorMachineModel encodeModel(Schema schema){ @Override public Expression createExpression(FieldRef fieldRef){ - return PMMLUtil.createApply(PMMLFunctions.LESSOREQUAL, fieldRef, PMMLUtil.createConstant(0d)); + return ExpressionUtil.createApply(PMMLFunctions.LESSOREQUAL, fieldRef, ExpressionUtil.createConstant(0d)); } }; @@ -260,11 +260,11 @@ private void scaleFeatures(RExpEncoder encoder){ Expression expression = continuousFeature.ref(); if(!ValueUtil.isZero(center)){ - expression = PMMLUtil.createApply(PMMLFunctions.SUBTRACT, expression, PMMLUtil.createConstant(center)); + expression = ExpressionUtil.createApply(PMMLFunctions.SUBTRACT, expression, ExpressionUtil.createConstant(center)); } // End if if(!ValueUtil.isOne(scale)){ - expression = PMMLUtil.createApply(PMMLFunctions.DIVIDE, expression, PMMLUtil.createConstant(scale)); + expression = ExpressionUtil.createApply(PMMLFunctions.DIVIDE, expression, ExpressionUtil.createConstant(scale)); } DerivedField derivedField = encoder.createDerivedField(FieldNameUtil.create("scale", continuousFeature), OpType.CONTINUOUS, DataType.DOUBLE, expression); diff --git a/pmml-rexp/src/main/java/org/jpmml/rexp/WrappedModelConverter.java b/pmml-rexp/src/main/java/org/jpmml/rexp/WrappedModelConverter.java index 6d13e40..b039414 100644 --- a/pmml-rexp/src/main/java/org/jpmml/rexp/WrappedModelConverter.java +++ b/pmml-rexp/src/main/java/org/jpmml/rexp/WrappedModelConverter.java @@ -26,8 +26,8 @@ import org.dmg.pmml.Model; import org.dmg.pmml.OpType; import org.jpmml.converter.CategoricalLabel; +import org.jpmml.converter.FieldUtil; import org.jpmml.converter.Label; -import org.jpmml.converter.PMMLUtil; import org.jpmml.converter.Schema; public class WrappedModelConverter extends FilterModelConverter { @@ -83,7 +83,7 @@ public void encodeSchema(RExpEncoder encoder){ RBooleanVector invertLevels = DecorationUtil.getBooleanElement(wrappedModel, "invert_levels"); if(invertLevels.asScalar()){ - values = PMMLUtil.getValues(dataField); + values = FieldUtil.getValues(dataField); Label label = new CategoricalLabel(dataField.requireName(), dataField.requireDataType(), Lists.reverse(values)); diff --git a/pmml-rexp/src/main/javacc/expression.jj b/pmml-rexp/src/main/javacc/expression.jj index 80f7f15..6fb5cf2 100644 --- a/pmml-rexp/src/main/javacc/expression.jj +++ b/pmml-rexp/src/main/javacc/expression.jj @@ -35,7 +35,7 @@ import org.dmg.pmml.Expression; import org.dmg.pmml.FieldRef; import org.dmg.pmml.Interval; import org.dmg.pmml.PMMLFunctions; -import org.jpmml.converter.PMMLUtil; +import org.jpmml.converter.ExpressionUtil; import org.jpmml.converter.visitors.ExpressionCompactor; public class ExpressionTranslator { @@ -423,10 +423,10 @@ Expression IfExpression(): { if(second != null){ - return PMMLUtil.createApply(PMMLFunctions.IF, condition, first, second); + return ExpressionUtil.createApply(PMMLFunctions.IF, condition, first, second); } - return PMMLUtil.createApply(PMMLFunctions.IF, condition, first); + return ExpressionUtil.createApply(PMMLFunctions.IF, condition, first); } } @@ -437,7 +437,7 @@ Expression OrExpression(): Expression right; } { - left = AndExpression() (operator = right = AndExpression() { left = PMMLUtil.createApply(translateLogicalOperator(operator), left, right); })* + left = AndExpression() (operator = right = AndExpression() { left = ExpressionUtil.createApply(translateLogicalOperator(operator), left, right); })* { return left; @@ -451,7 +451,7 @@ Expression AndExpression(): Expression right; } { - left = NegationExpression() (operator = right = NegationExpression() { left = PMMLUtil.createApply(translateLogicalOperator(operator), left, right); })* + left = NegationExpression() (operator = right = NegationExpression() { left = ExpressionUtil.createApply(translateLogicalOperator(operator), left, right); })* { return left; @@ -468,7 +468,7 @@ Expression NegationExpression(): { if(operator != null){ - return PMMLUtil.createApply(PMMLFunctions.NOT, expression); + return ExpressionUtil.createApply(PMMLFunctions.NOT, expression); } return expression; @@ -482,7 +482,7 @@ Expression RelationalExpression(): Expression right; } { - left = AdditiveExpression() ((operator = | operator = | operator = | operator = | operator = | operator = ) right = AdditiveExpression() { left = PMMLUtil.createApply(translateRelationalOperator(operator), left, right); })? + left = AdditiveExpression() ((operator = | operator = | operator = | operator = | operator = | operator = ) right = AdditiveExpression() { left = ExpressionUtil.createApply(translateRelationalOperator(operator), left, right); })? { return left; @@ -496,7 +496,7 @@ Expression AdditiveExpression(): Expression right; } { - left = MultiplicativeExpression() ((operator = | operator = ) right = MultiplicativeExpression() { left = PMMLUtil.createApply(translateArithmeticOperator(operator), left, right); })* + left = MultiplicativeExpression() ((operator = | operator = ) right = MultiplicativeExpression() { left = ExpressionUtil.createApply(translateArithmeticOperator(operator), left, right); })* { return left; @@ -510,7 +510,7 @@ Expression MultiplicativeExpression(): Expression right; } { - left = UnaryExpression() ((operator = | operator = | operator = ) right = UnaryExpression() { left = PMMLUtil.createApply(translateArithmeticOperator(operator), left, right); })* + left = UnaryExpression() ((operator = | operator = | operator = ) right = UnaryExpression() { left = ExpressionUtil.createApply(translateArithmeticOperator(operator), left, right); })* { return left; @@ -527,7 +527,7 @@ Expression UnaryExpression(): { if(sign != null && sign.kind == MINUS){ - expression = PMMLUtil.toNegative(expression); + expression = ExpressionUtil.toNegative(expression); } return expression; @@ -541,7 +541,7 @@ Expression ExponentiationExpression(): Expression right = null; } { - left = PrimaryExpression() ((operator = | operator = ) right = UnaryExpression() { left = PMMLUtil.createApply(PMMLFunctions.POW, left, right); })? + left = PrimaryExpression() ((operator = | operator = ) right = UnaryExpression() { left = ExpressionUtil.createApply(PMMLFunctions.POW, left, right); })? { return left; @@ -604,7 +604,7 @@ Expression FunctionInvocationExpression(): FunctionExpression.Argument argument = arguments.get(0); if(!argument.hasTag() && !(argument.getExpression() instanceof FunctionExpression)){ - return PMMLUtil.createApply(pmmlFunction, argument.getExpression()); + return ExpressionUtil.createApply(pmmlFunction, argument.getExpression()); } } } catch(IllegalArgumentException iae){ diff --git a/pmml-rexp/src/test/java/org/jpmml/rexp/ExpressionTranslatorTest.java b/pmml-rexp/src/test/java/org/jpmml/rexp/ExpressionTranslatorTest.java index 341a889..a8d794d 100644 --- a/pmml-rexp/src/test/java/org/jpmml/rexp/ExpressionTranslatorTest.java +++ b/pmml-rexp/src/test/java/org/jpmml/rexp/ExpressionTranslatorTest.java @@ -28,7 +28,7 @@ import org.dmg.pmml.FieldRef; import org.dmg.pmml.Interval; import org.dmg.pmml.PMMLFunctions; -import org.jpmml.converter.PMMLUtil; +import org.jpmml.converter.ExpressionUtil; import org.jpmml.model.ReflectionUtil; import org.jpmml.rexp.ExpressionTranslator; import org.jpmml.rexp.FunctionExpression; @@ -44,17 +44,17 @@ public class ExpressionTranslatorTest { public void translate(){ String string = "(1.0 + log(A / B)) ^ 2"; - Expression expected = PMMLUtil.createApply(PMMLFunctions.POW, - PMMLUtil.createApply(PMMLFunctions.ADD, - PMMLUtil.createConstant("1.0", DataType.DOUBLE), - PMMLUtil.createApply(PMMLFunctions.LN, - PMMLUtil.createApply(PMMLFunctions.DIVIDE, + Expression expected = ExpressionUtil.createApply(PMMLFunctions.POW, + ExpressionUtil.createApply(PMMLFunctions.ADD, + ExpressionUtil.createConstant(DataType.DOUBLE, "1.0"), + ExpressionUtil.createApply(PMMLFunctions.LN, + ExpressionUtil.createApply(PMMLFunctions.DIVIDE, new FieldRef("A"), new FieldRef("B") ) ) ), - PMMLUtil.createConstant("2", DataType.INTEGER) + ExpressionUtil.createConstant(DataType.INTEGER, "2") ); Expression actual = ExpressionTranslator.translateExpression(string); @@ -66,10 +66,10 @@ public void translate(){ public void translateIfExpression(){ String string = "if(is.na(x)) TRUE else FALSE"; - Expression expected = PMMLUtil.createApply(PMMLFunctions.IF, - PMMLUtil.createApply(PMMLFunctions.ISMISSING, new FieldRef("x")), - PMMLUtil.createConstant("true", DataType.BOOLEAN), - PMMLUtil.createConstant("false", DataType.BOOLEAN) + Expression expected = ExpressionUtil.createApply(PMMLFunctions.IF, + ExpressionUtil.createApply(PMMLFunctions.ISMISSING, new FieldRef("x")), + ExpressionUtil.createConstant(DataType.BOOLEAN, "true"), + ExpressionUtil.createConstant(DataType.BOOLEAN, "false") ); Expression actual = ExpressionTranslator.translateExpression(string); @@ -81,12 +81,12 @@ public void translateIfExpression(){ public void translateLogicalExpression(){ String string = "a >= 0.0 & b >= 0.0 | c <= 0.0"; - Expression expected = PMMLUtil.createApply(PMMLFunctions.OR, - PMMLUtil.createApply(PMMLFunctions.AND, - PMMLUtil.createApply(PMMLFunctions.GREATEROREQUAL, new FieldRef("a"), PMMLUtil.createConstant("0.0", DataType.DOUBLE)), - PMMLUtil.createApply(PMMLFunctions.GREATEROREQUAL, new FieldRef("b"), PMMLUtil.createConstant("0.0", DataType.DOUBLE)) + Expression expected = ExpressionUtil.createApply(PMMLFunctions.OR, + ExpressionUtil.createApply(PMMLFunctions.AND, + ExpressionUtil.createApply(PMMLFunctions.GREATEROREQUAL, new FieldRef("a"), ExpressionUtil.createConstant(DataType.DOUBLE, "0.0")), + ExpressionUtil.createApply(PMMLFunctions.GREATEROREQUAL, new FieldRef("b"), ExpressionUtil.createConstant(DataType.DOUBLE, "0.0")) ), - PMMLUtil.createApply(PMMLFunctions.LESSOREQUAL, new FieldRef("c"), PMMLUtil.createConstant("0.0", DataType.DOUBLE)) + ExpressionUtil.createApply(PMMLFunctions.LESSOREQUAL, new FieldRef("c"), ExpressionUtil.createConstant(DataType.DOUBLE, "0.0")) ); Expression actual = ExpressionTranslator.translateExpression(string); @@ -98,15 +98,15 @@ public void translateLogicalExpression(){ public void translateLogicalExpressionChain(){ String string = "(x == 0) | ((x == 1) | (x == 2)) | x == 3"; - Apply left = PMMLUtil.createApply(PMMLFunctions.EQUAL, new FieldRef("x"), PMMLUtil.createConstant("0", DataType.INTEGER)); - Apply middleLeft = PMMLUtil.createApply(PMMLFunctions.EQUAL, new FieldRef("x"), PMMLUtil.createConstant("1", DataType.INTEGER)); - Apply middleRight = PMMLUtil.createApply(PMMLFunctions.EQUAL, new FieldRef("x"), PMMLUtil.createConstant("2", DataType.INTEGER)); - Apply right = PMMLUtil.createApply(PMMLFunctions.EQUAL, new FieldRef("x"), PMMLUtil.createConstant("3", DataType.INTEGER)); + Apply left = ExpressionUtil.createApply(PMMLFunctions.EQUAL, new FieldRef("x"), ExpressionUtil.createConstant(DataType.INTEGER, "0")); + Apply middleLeft = ExpressionUtil.createApply(PMMLFunctions.EQUAL, new FieldRef("x"), ExpressionUtil.createConstant(DataType.INTEGER, "1")); + Apply middleRight = ExpressionUtil.createApply(PMMLFunctions.EQUAL, new FieldRef("x"), ExpressionUtil.createConstant(DataType.INTEGER, "2")); + Apply right = ExpressionUtil.createApply(PMMLFunctions.EQUAL, new FieldRef("x"), ExpressionUtil.createConstant(DataType.INTEGER, "3")); - Expression expected = PMMLUtil.createApply(PMMLFunctions.OR, - PMMLUtil.createApply(PMMLFunctions.OR, + Expression expected = ExpressionUtil.createApply(PMMLFunctions.OR, + ExpressionUtil.createApply(PMMLFunctions.OR, left, - PMMLUtil.createApply(PMMLFunctions.OR, + ExpressionUtil.createApply(PMMLFunctions.OR, middleLeft, middleRight ) ), @@ -117,7 +117,7 @@ public void translateLogicalExpressionChain(){ assertTrue(ReflectionUtil.equals(expected, actual)); - expected = PMMLUtil.createApply(PMMLFunctions.OR, left, middleLeft, middleRight, right); + expected = ExpressionUtil.createApply(PMMLFunctions.OR, left, middleLeft, middleRight, right); actual = ExpressionTranslator.translateExpression(string, true); @@ -128,13 +128,13 @@ public void translateLogicalExpressionChain(){ public void translateRelationalExpression(){ String string = "if(x < 0) \"negative\" else if(x > 0) \"positive\" else \"zero\""; - Expression expected = PMMLUtil.createApply(PMMLFunctions.IF, - PMMLUtil.createApply(PMMLFunctions.LESSTHAN, new FieldRef("x"), PMMLUtil.createConstant("0", DataType.INTEGER)), - PMMLUtil.createConstant("negative", DataType.STRING), - PMMLUtil.createApply(PMMLFunctions.IF, - PMMLUtil.createApply(PMMLFunctions.GREATERTHAN, new FieldRef("x"), PMMLUtil.createConstant("0", DataType.INTEGER)), - PMMLUtil.createConstant("positive", DataType.STRING), - PMMLUtil.createConstant("zero", DataType.STRING) + Expression expected = ExpressionUtil.createApply(PMMLFunctions.IF, + ExpressionUtil.createApply(PMMLFunctions.LESSTHAN, new FieldRef("x"), ExpressionUtil.createConstant(DataType.INTEGER, "0")), + ExpressionUtil.createConstant(DataType.STRING, "negative"), + ExpressionUtil.createApply(PMMLFunctions.IF, + ExpressionUtil.createApply(PMMLFunctions.GREATERTHAN, new FieldRef("x"), ExpressionUtil.createConstant(DataType.INTEGER, "0")), + ExpressionUtil.createConstant(DataType.STRING, "positive"), + ExpressionUtil.createConstant(DataType.STRING, "zero") ) ); @@ -147,9 +147,9 @@ public void translateRelationalExpression(){ public void translateArithmeticExpressionChain(){ String string = "A + B - X + C"; - Expression expected = PMMLUtil.createApply(PMMLFunctions.ADD, - PMMLUtil.createApply(PMMLFunctions.SUBTRACT, - PMMLUtil.createApply(PMMLFunctions.ADD, new FieldRef("A"), new FieldRef("B")), + Expression expected = ExpressionUtil.createApply(PMMLFunctions.ADD, + ExpressionUtil.createApply(PMMLFunctions.SUBTRACT, + ExpressionUtil.createApply(PMMLFunctions.ADD, new FieldRef("A"), new FieldRef("B")), new FieldRef("X") ), new FieldRef("C") @@ -164,9 +164,9 @@ public void translateArithmeticExpressionChain(){ public void translateExponentiationExpression(){ String string = "-2^-3"; - Expression expected = PMMLUtil.createApply(PMMLFunctions.MULTIPLY, - PMMLUtil.createConstant(-1), - PMMLUtil.createApply(PMMLFunctions.POW, PMMLUtil.createConstant("2", DataType.INTEGER), PMMLUtil.createConstant("-3", DataType.INTEGER)) + Expression expected = ExpressionUtil.createApply(PMMLFunctions.MULTIPLY, + ExpressionUtil.createConstant(-1), + ExpressionUtil.createApply(PMMLFunctions.POW, ExpressionUtil.createConstant(DataType.INTEGER, "2"), ExpressionUtil.createConstant(DataType.INTEGER, "-3")) ); Expression actual = ExpressionTranslator.translateExpression(string); @@ -175,12 +175,12 @@ public void translateExponentiationExpression(){ string = "-2^-2*1.5"; - expected = PMMLUtil.createApply(PMMLFunctions.MULTIPLY, - PMMLUtil.createApply(PMMLFunctions.MULTIPLY, - PMMLUtil.createConstant(-1), - PMMLUtil.createApply(PMMLFunctions.POW, PMMLUtil.createConstant("2", DataType.INTEGER), PMMLUtil.createConstant("-2", DataType.INTEGER)) + expected = ExpressionUtil.createApply(PMMLFunctions.MULTIPLY, + ExpressionUtil.createApply(PMMLFunctions.MULTIPLY, + ExpressionUtil.createConstant(-1), + ExpressionUtil.createApply(PMMLFunctions.POW, ExpressionUtil.createConstant(DataType.INTEGER, "2"), ExpressionUtil.createConstant(DataType.INTEGER, "-2")) ), - PMMLUtil.createConstant("1.5", DataType.DOUBLE) + ExpressionUtil.createConstant(DataType.DOUBLE, "1.5") ); actual = ExpressionTranslator.translateExpression(string); @@ -215,22 +215,22 @@ public void translateFunctionExpression(){ List expressions = checkFunctionExpression((FunctionExpression)first.getExpression(), "child", null, null); assertTrue(ReflectionUtil.equals(new FieldRef("A"), expressions.get(0))); - assertTrue(ReflectionUtil.equals(PMMLUtil.createApply(PMMLFunctions.LN, new FieldRef("A")), expressions.get(1))); + assertTrue(ReflectionUtil.equals(ExpressionUtil.createApply(PMMLFunctions.LN, new FieldRef("A")), expressions.get(1))); assertEquals("child(1 + B, right = 0)", second.format()); assertEquals("child(1 + B, right = 0)", second.formatExpression()); expressions = checkFunctionExpression((FunctionExpression)second.getExpression(), "child", null, "right"); - assertTrue(ReflectionUtil.equals(PMMLUtil.createApply(PMMLFunctions.ADD, PMMLUtil.createConstant("1", DataType.INTEGER), new FieldRef("B")), expressions.get(0))); - assertTrue(ReflectionUtil.equals(PMMLUtil.createConstant("0", DataType.INTEGER), expressions.get(1))); + assertTrue(ReflectionUtil.equals(ExpressionUtil.createApply(PMMLFunctions.ADD, ExpressionUtil.createConstant(DataType.INTEGER, "1"), new FieldRef("B")), expressions.get(0))); + assertTrue(ReflectionUtil.equals(ExpressionUtil.createConstant(DataType.INTEGER, "0"), expressions.get(1))); assertEquals("\"third\" = child(left = 0, c(A, B, C))", third.format()); assertEquals("child(left = 0, c(A, B, C))", third.formatExpression()); expressions = checkFunctionExpression((FunctionExpression)third.getExpression(), "child", "left", null); - assertTrue(ReflectionUtil.equals(PMMLUtil.createConstant("0", DataType.INTEGER), expressions.get(0))); + assertTrue(ReflectionUtil.equals(ExpressionUtil.createConstant(DataType.INTEGER, "0"), expressions.get(0))); checkFunctionExpression((FunctionExpression)expressions.get(1), "c", null, null, null); } @@ -239,10 +239,10 @@ public void translateFunctionExpression(){ public void translateParenthesizedExpression(){ String string = "TRUE | TRUE & FALSE"; - Constant trueConstant = PMMLUtil.createConstant("true", DataType.BOOLEAN); - Constant falseConstant = PMMLUtil.createConstant("false", DataType.BOOLEAN); + Constant trueConstant = ExpressionUtil.createConstant(DataType.BOOLEAN, "true"); + Constant falseConstant = ExpressionUtil.createConstant(DataType.BOOLEAN, "false"); - Expression expected = PMMLUtil.createApply(PMMLFunctions.OR, trueConstant, PMMLUtil.createApply(PMMLFunctions.AND, trueConstant, falseConstant)); + Expression expected = ExpressionUtil.createApply(PMMLFunctions.OR, trueConstant, ExpressionUtil.createApply(PMMLFunctions.AND, trueConstant, falseConstant)); Expression actual = ExpressionTranslator.translateExpression(string); @@ -250,7 +250,7 @@ public void translateParenthesizedExpression(){ string = "(TRUE | TRUE) & FALSE"; - expected = PMMLUtil.createApply(PMMLFunctions.AND, PMMLUtil.createApply(PMMLFunctions.OR, trueConstant, trueConstant), falseConstant); + expected = ExpressionUtil.createApply(PMMLFunctions.AND, ExpressionUtil.createApply(PMMLFunctions.OR, trueConstant, trueConstant), falseConstant); actual = ExpressionTranslator.translateExpression(string); diff --git a/pom.xml b/pom.xml index 226156a..af99734 100644 --- a/pom.xml +++ b/pom.xml @@ -70,12 +70,12 @@ org.jpmml pmml-converter - 1.5.5 + 1.5.6 org.jpmml pmml-converter-testing - 1.5.5 + 1.5.6 @@ -87,7 +87,7 @@ org.jpmml pmml-xgboost - 1.7.4 + 1.8.3