Skip to content

Commit

Permalink
Updated JPMML-Converter dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
vruusmann committed Feb 10, 2024
1 parent e7e441f commit aa54647
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions pmml-rexp/src/main/java/org/jpmml/rexp/EarthConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}
5 changes: 3 additions & 2 deletions pmml-rexp/src/main/java/org/jpmml/rexp/FormulaUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -466,7 +467,7 @@ private MapValues createMapValues(String name, Map<String, String> mapping, List
mapping.put(category, category);
}

return PMMLUtil.createMapValues(name, mapping);
return ExpressionUtil.createMapValues(name, mapping);
}

static
Expand Down
6 changes: 3 additions & 3 deletions pmml-rexp/src/main/java/org/jpmml/rexp/IForestConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())));
}
};

Expand All @@ -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));
}
};

Expand Down
4 changes: 2 additions & 2 deletions pmml-rexp/src/main/java/org/jpmml/rexp/MVRConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
16 changes: 8 additions & 8 deletions pmml-rexp/src/main/java/org/jpmml/rexp/PreProcessEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<RGenericVector> {
Expand Down Expand Up @@ -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)
);
}

Expand Down
8 changes: 4 additions & 4 deletions pmml-rexp/src/main/java/org/jpmml/rexp/SVMConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
};

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<RGenericVector, RExp> {
Expand Down Expand Up @@ -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));

Expand Down
24 changes: 12 additions & 12 deletions pmml-rexp/src/main/javacc/expression.jj
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -437,7 +437,7 @@ Expression OrExpression():
Expression right;
}
{
left = AndExpression() (operator = <OR> right = AndExpression() { left = PMMLUtil.createApply(translateLogicalOperator(operator), left, right); })*
left = AndExpression() (operator = <OR> right = AndExpression() { left = ExpressionUtil.createApply(translateLogicalOperator(operator), left, right); })*

{
return left;
Expand All @@ -451,7 +451,7 @@ Expression AndExpression():
Expression right;
}
{
left = NegationExpression() (operator = <AND> right = NegationExpression() { left = PMMLUtil.createApply(translateLogicalOperator(operator), left, right); })*
left = NegationExpression() (operator = <AND> right = NegationExpression() { left = ExpressionUtil.createApply(translateLogicalOperator(operator), left, right); })*

{
return left;
Expand All @@ -468,7 +468,7 @@ Expression NegationExpression():

{
if(operator != null){
return PMMLUtil.createApply(PMMLFunctions.NOT, expression);
return ExpressionUtil.createApply(PMMLFunctions.NOT, expression);
}

return expression;
Expand All @@ -482,7 +482,7 @@ Expression RelationalExpression():
Expression right;
}
{
left = AdditiveExpression() ((operator = <EQUAL> | operator = <NOT_EQUAL> | operator = <LESS_THAN> | operator = <LESS_OR_EQUAL> | operator = <GREATER_THAN> | operator = <GREATER_OR_EQUAL>) right = AdditiveExpression() { left = PMMLUtil.createApply(translateRelationalOperator(operator), left, right); })?
left = AdditiveExpression() ((operator = <EQUAL> | operator = <NOT_EQUAL> | operator = <LESS_THAN> | operator = <LESS_OR_EQUAL> | operator = <GREATER_THAN> | operator = <GREATER_OR_EQUAL>) right = AdditiveExpression() { left = ExpressionUtil.createApply(translateRelationalOperator(operator), left, right); })?

{
return left;
Expand All @@ -496,7 +496,7 @@ Expression AdditiveExpression():
Expression right;
}
{
left = MultiplicativeExpression() ((operator = <PLUS> | operator = <MINUS>) right = MultiplicativeExpression() { left = PMMLUtil.createApply(translateArithmeticOperator(operator), left, right); })*
left = MultiplicativeExpression() ((operator = <PLUS> | operator = <MINUS>) right = MultiplicativeExpression() { left = ExpressionUtil.createApply(translateArithmeticOperator(operator), left, right); })*

{
return left;
Expand All @@ -510,7 +510,7 @@ Expression MultiplicativeExpression():
Expression right;
}
{
left = UnaryExpression() ((operator = <MULTIPLY> | operator = <DIVIDE> | operator = <MODULO>) right = UnaryExpression() { left = PMMLUtil.createApply(translateArithmeticOperator(operator), left, right); })*
left = UnaryExpression() ((operator = <MULTIPLY> | operator = <DIVIDE> | operator = <MODULO>) right = UnaryExpression() { left = ExpressionUtil.createApply(translateArithmeticOperator(operator), left, right); })*

{
return left;
Expand All @@ -527,7 +527,7 @@ Expression UnaryExpression():

{
if(sign != null && sign.kind == MINUS){
expression = PMMLUtil.toNegative(expression);
expression = ExpressionUtil.toNegative(expression);
}

return expression;
Expand All @@ -541,7 +541,7 @@ Expression ExponentiationExpression():
Expression right = null;
}
{
left = PrimaryExpression() ((operator = <POWER> | operator = <POWER_MULTIPLY>) right = UnaryExpression() { left = PMMLUtil.createApply(PMMLFunctions.POW, left, right); })?
left = PrimaryExpression() ((operator = <POWER> | operator = <POWER_MULTIPLY>) right = UnaryExpression() { left = ExpressionUtil.createApply(PMMLFunctions.POW, left, right); })?

{
return left;
Expand Down Expand Up @@ -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){
Expand Down
Loading

0 comments on commit aa54647

Please sign in to comment.