use of org.dmg.pmml.Constant in project drools by kiegroup.
the class PMMLModelTestUtils method getDerivedField.
public static DerivedField getDerivedField(String fieldName) {
DerivedField toReturn = new DerivedField();
toReturn.setName(FieldName.create(fieldName));
toReturn.setDataType(getRandomDataType());
toReturn.setOpType(getRandomOpType());
Constant expression = new Constant(5);
expression.setDataType(DataType.INTEGER);
toReturn.setExpression(expression);
toReturn.setDisplayName("Display-" + fieldName);
return toReturn;
}
use of org.dmg.pmml.Constant in project jpmml-r by jpmml.
the class Formula method addField.
public void addField(Field<?> field) {
RExpEncoder encoder = getEncoder();
Feature feature = new ContinuousFeature(encoder, field);
if (field instanceof DerivedField) {
DerivedField derivedField = (DerivedField) field;
Expression expression = derivedField.requireExpression();
if (expression instanceof Apply) {
Apply apply = (Apply) expression;
if (checkApply(apply, PMMLFunctions.POW, FieldRef.class, Constant.class)) {
List<Expression> expressions = apply.getExpressions();
FieldRef fieldRef = (FieldRef) expressions.get(0);
Constant constant = (Constant) expressions.get(1);
try {
String string = ValueUtil.asString(constant.getValue());
int power = Integer.parseInt(string);
feature = new PowerFeature(encoder, fieldRef.requireField(), DataType.DOUBLE, power);
} catch (NumberFormatException nfe) {
// Ignored
}
}
}
}
putFeature(field.requireName(), feature);
this.fields.add(field);
}
use of org.dmg.pmml.Constant in project jpmml-r by jpmml.
the class FormulaUtil method parseRevalue.
private static Map<String, String> parseRevalue(FunctionExpression.Argument replaceArgument) {
Map<String, String> result = new LinkedHashMap<>();
FunctionExpression vectorExpression = toVectorExpression(replaceArgument);
List<FunctionExpression.Argument> objectArguments = vectorExpression.getArguments();
for (FunctionExpression.Argument objectArgument : objectArguments) {
String from = objectArgument.getTag();
if (from == null) {
throw new IllegalArgumentException();
}
Constant constant = (Constant) objectArgument.getExpression();
String to = (String) constant.getValue();
if (to == null) {
throw new IllegalArgumentException();
}
result.put(from, to);
}
return result;
}
Aggregations