use of org.kie.pmml.api.enums.RESULT_FEATURE in project drools by kiegroup.
the class KiePMMLOutputFieldInstanceFactory method getKiePMMLOutputField.
public static KiePMMLOutputField getKiePMMLOutputField(final OutputField outputField) {
String name = outputField.getName() != null ? outputField.getName().getValue() : "" + outputField.hashCode();
final String targetField = outputField.getTargetField() != null ? outputField.getTargetField().getValue() : null;
final RESULT_FEATURE resultFeature = outputField.getResultFeature() != null ? RESULT_FEATURE.byName(outputField.getResultFeature().value()) : null;
final DATA_TYPE dataType = outputField.getDataType() != null ? DATA_TYPE.byName(outputField.getDataType().value()) : null;
final KiePMMLExpression kiePMMLExpression = outputField.getExpression() != null ? getKiePMMLExpression(outputField.getExpression()) : null;
final KiePMMLOutputField.Builder builder = KiePMMLOutputField.builder(name, Collections.emptyList()).withResultFeature(resultFeature).withTargetField(targetField).withValue(outputField.getValue()).withDataType(dataType).withRank(outputField.getRank()).withKiePMMLExpression(kiePMMLExpression);
return builder.build();
}
use of org.kie.pmml.api.enums.RESULT_FEATURE in project drools by kiegroup.
the class ModelUtilsTest method convertToKieOutputField.
@Test
public void convertToKieOutputField() {
final OutputField toConvert = getRandomOutputField();
org.kie.pmml.api.models.OutputField retrieved = ModelUtils.convertToKieOutputField(toConvert, null);
assertNotNull(retrieved);
assertEquals(toConvert.getName().getValue(), retrieved.getName());
OP_TYPE expectedOpType = OP_TYPE.byName(toConvert.getOpType().value());
assertEquals(expectedOpType, retrieved.getOpType());
DATA_TYPE expectedDataType = DATA_TYPE.byName(toConvert.getDataType().value());
assertEquals(expectedDataType, retrieved.getDataType());
assertEquals(toConvert.getTargetField().getValue(), retrieved.getTargetField());
RESULT_FEATURE expectedResultFeature = RESULT_FEATURE.byName(toConvert.getResultFeature().value());
assertEquals(expectedResultFeature, retrieved.getResultFeature());
toConvert.setOpType(null);
toConvert.setTargetField(null);
retrieved = ModelUtils.convertToKieOutputField(toConvert, null);
assertNull(retrieved.getOpType());
assertNull(retrieved.getTargetField());
}
use of org.kie.pmml.api.enums.RESULT_FEATURE in project drools by kiegroup.
the class KiePMMLOutputFieldFactory method getOutputFieldVariableDeclaration.
static BlockStmt getOutputFieldVariableDeclaration(final String variableName, final OutputField outputField) {
final MethodDeclaration methodDeclaration = OUTPUTFIELD_TEMPLATE.getMethodsByName(GETKIEPMMLOUTPUTFIELD).get(0).clone();
final BlockStmt outputFieldBody = methodDeclaration.getBody().orElseThrow(() -> new KiePMMLException(String.format(MISSING_BODY_TEMPLATE, methodDeclaration)));
final VariableDeclarator variableDeclarator = getVariableDeclarator(outputFieldBody, OUTPUTFIELD).orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_IN_BODY, OUTPUTFIELD, outputFieldBody)));
variableDeclarator.setName(variableName);
final BlockStmt toReturn = new BlockStmt();
final Expression expressionExpr;
if (outputField.getExpression() != null) {
String nestedVariableName = String.format("%s_Expression", variableName);
BlockStmt toAdd = getKiePMMLExpressionBlockStmt(nestedVariableName, outputField.getExpression());
toAdd.getStatements().forEach(toReturn::addStatement);
expressionExpr = new NameExpr(nestedVariableName);
} else {
expressionExpr = new NullLiteralExpr();
}
final MethodCallExpr initializer = variableDeclarator.getInitializer().orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_INITIALIZER_TEMPLATE, OUTPUTFIELD, toReturn))).asMethodCallExpr();
final MethodCallExpr builder = getChainedMethodCallExprFrom("builder", initializer);
final StringLiteralExpr nameExpr = new StringLiteralExpr(outputField.getName().getValue());
final RESULT_FEATURE resultFeature = RESULT_FEATURE.byName(outputField.getResultFeature().value());
final NameExpr resultFeatureExpr = new NameExpr(RESULT_FEATURE.class.getName() + "." + resultFeature.name());
final Expression targetFieldExpr = outputField.getTargetField() != null ? getExpressionForObject(outputField.getTargetField().getValue()) : new NullLiteralExpr();
final Expression valueExpr = outputField.getValue() != null ? getExpressionForObject(outputField.getValue()) : new NullLiteralExpr();
final Expression dataTypeExpression = getExpressionForDataType(outputField.getDataType());
final Expression rankExpr = outputField.getRank() != null ? getExpressionForObject(outputField.getRank()) : new NullLiteralExpr();
builder.setArgument(0, nameExpr);
getChainedMethodCallExprFrom("withResultFeature", initializer).setArgument(0, resultFeatureExpr);
getChainedMethodCallExprFrom("withTargetField", initializer).setArgument(0, targetFieldExpr);
getChainedMethodCallExprFrom("withValue", initializer).setArgument(0, valueExpr);
getChainedMethodCallExprFrom("withDataType", initializer).setArgument(0, dataTypeExpression);
getChainedMethodCallExprFrom("withRank", initializer).setArgument(0, rankExpr);
getChainedMethodCallExprFrom("withKiePMMLExpression", initializer).setArgument(0, expressionExpr);
outputFieldBody.getStatements().forEach(toReturn::addStatement);
return toReturn;
}
use of org.kie.pmml.api.enums.RESULT_FEATURE in project drools by kiegroup.
the class ModelUtils method convertToKieOutputField.
/**
* Return a <code>org.kie.pmml.api.models.OutputField</code> out of a <code>org.dmg.pmml.OutputField</code> one
* @param toConvert
* @param field - this may be <code>null</code>
* @return
*/
public static org.kie.pmml.api.models.OutputField convertToKieOutputField(final OutputField toConvert, final Field<?> field) {
final String name = toConvert.getName() != null ? toConvert.getName().getValue() : null;
final OP_TYPE opType = toConvert.getOpType() != null ? OP_TYPE.byName(toConvert.getOpType().value()) : null;
final DATA_TYPE dataFieldDataType = field != null ? DATA_TYPE.byName(field.getDataType().value()) : null;
final DATA_TYPE dataType = toConvert.getDataType() != null ? DATA_TYPE.byName(toConvert.getDataType().value()) : dataFieldDataType;
final String targetField = toConvert.getTargetField() != null ? toConvert.getTargetField().getValue() : null;
final RESULT_FEATURE resultFeature = toConvert.getResultFeature() != null ? RESULT_FEATURE.byName(toConvert.getResultFeature().value()) : null;
final List<String> allowedValues = field instanceof DataField ? convertDataFieldValues(((DataField) field).getValues()) : null;
return new org.kie.pmml.api.models.OutputField(name, opType, dataType, targetField, resultFeature, allowedValues);
}
Aggregations