use of org.kie.pmml.api.enums.OP_TYPE in project drools by kiegroup.
the class KiePMMLParameterFieldInstanceFactory method getKiePMMLParameterField.
static KiePMMLParameterField getKiePMMLParameterField(final ParameterField parameterField) {
DATA_TYPE dataType = parameterField.getDataType() != null ? DATA_TYPE.byName(parameterField.getDataType().value()) : null;
OP_TYPE opType = parameterField.getOpType() != null ? OP_TYPE.byName(parameterField.getOpType().value()) : null;
return KiePMMLParameterField.builder(parameterField.getName().getValue(), Collections.emptyList()).withDataType(dataType).withOpType(opType).withDisplayName(parameterField.getDisplayName()).build();
}
use of org.kie.pmml.api.enums.OP_TYPE in project drools by kiegroup.
the class KiePMMLClassificationTableFactory method setStaticGetter.
// not-public code-generation
static void setStaticGetter(final RegressionCompilationDTO compilationDTO, final LinkedHashMap<String, KiePMMLTableSourceCategory> regressionTablesMap, final MethodDeclaration staticGetterMethod, final String variableName) {
final BlockStmt classificationTableBody = staticGetterMethod.getBody().orElseThrow(() -> new KiePMMLException(String.format(MISSING_BODY_TEMPLATE, staticGetterMethod)));
final VariableDeclarator variableDeclarator = getVariableDeclarator(classificationTableBody, TO_RETURN).orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_IN_BODY, TO_RETURN, classificationTableBody)));
final BlockStmt newBody = new BlockStmt();
final Map<String, Expression> regressionTableCategoriesMap = new LinkedHashMap<>();
regressionTablesMap.forEach((className, tableSourceCategory) -> {
MethodCallExpr methodCallExpr = new MethodCallExpr();
methodCallExpr.setScope(new NameExpr(className));
methodCallExpr.setName(KiePMMLRegressionTableFactory.GETKIEPMML_TABLE);
regressionTableCategoriesMap.put(tableSourceCategory.getCategory(), methodCallExpr);
});
// populate map
String categoryTableMapName = String.format(VARIABLE_NAME_TEMPLATE, CATEGORICAL_TABLE_MAP, variableName);
createPopulatedLinkedHashMap(newBody, categoryTableMapName, Arrays.asList(String.class.getSimpleName(), KiePMMLRegressionTable.class.getName()), regressionTableCategoriesMap);
final MethodCallExpr initializer = variableDeclarator.getInitializer().orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_INITIALIZER_TEMPLATE, TO_RETURN, classificationTableBody))).asMethodCallExpr();
final MethodCallExpr builder = getChainedMethodCallExprFrom("builder", initializer);
builder.setArgument(0, new StringLiteralExpr(variableName));
final REGRESSION_NORMALIZATION_METHOD regressionNormalizationMethod = compilationDTO.getDefaultREGRESSION_NORMALIZATION_METHOD();
getChainedMethodCallExprFrom("withRegressionNormalizationMethod", initializer).setArgument(0, new NameExpr(regressionNormalizationMethod.getClass().getSimpleName() + "." + regressionNormalizationMethod.name()));
OP_TYPE opType = compilationDTO.getOP_TYPE();
getChainedMethodCallExprFrom("withOpType", initializer).setArgument(0, new NameExpr(opType.getClass().getSimpleName() + "." + opType.name()));
getChainedMethodCallExprFrom("withCategoryTableMap", initializer).setArgument(0, new NameExpr(categoryTableMapName));
boolean isBinary = compilationDTO.isBinary(regressionTablesMap.size());
final Expression probabilityMapFunctionExpression = getProbabilityMapFunctionExpression(compilationDTO.getModelNormalizationMethod(), isBinary);
getChainedMethodCallExprFrom("withProbabilityMapFunction", initializer).setArgument(0, probabilityMapFunctionExpression);
getChainedMethodCallExprFrom("withIsBinary", initializer).setArgument(0, getExpressionForObject(isBinary));
getChainedMethodCallExprFrom("withTargetField", initializer).setArgument(0, getExpressionForObject(compilationDTO.getTargetFieldName()));
getChainedMethodCallExprFrom("withTargetCategory", initializer).setArgument(0, getExpressionForObject(null));
classificationTableBody.getStatements().forEach(newBody::addStatement);
staticGetterMethod.setBody(newBody);
}
use of org.kie.pmml.api.enums.OP_TYPE in project drools by kiegroup.
the class ModelUtils method convertToKieTargetField.
/**
* Return a <code>org.kie.pmml.api.models.TargetField</code> out of a <code>org.dmg.pmml.Target</code>
* @param toConvert
* @return
*/
public static TargetField convertToKieTargetField(final Target toConvert) {
final List<org.kie.pmml.api.models.TargetValue> targetValues = convertToKieTargetValueList(toConvert.getTargetValues());
final OP_TYPE opType = toConvert.getOpType() != null ? OP_TYPE.byName(toConvert.getOpType().value()) : null;
final CAST_INTEGER castInteger = toConvert.getCastInteger() != null ? CAST_INTEGER.byName(toConvert.getCastInteger().value()) : null;
final Double min = toConvert.getMin() != null ? toConvert.getMin().doubleValue() : null;
final Double max = toConvert.getMax() != null ? toConvert.getMax().doubleValue() : null;
final Double rescaleConstant = toConvert.getRescaleConstant() != null ? toConvert.getRescaleConstant().doubleValue() : null;
final Double rescaleFactor = toConvert.getRescaleFactor() != null ? toConvert.getRescaleFactor().doubleValue() : null;
return new TargetField(targetValues, opType, toConvert.getField().getValue(), castInteger, min, max, rescaleConstant, rescaleFactor);
}
use of org.kie.pmml.api.enums.OP_TYPE 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);
}
use of org.kie.pmml.api.enums.OP_TYPE in project drools by kiegroup.
the class ModelUtils method convertToKieMiningField.
/**
* Return a <code>org.kie.pmml.api.models.MiningField</code> out of a <code>org.dmg.pmml.MiningField</code> and
* relative <code>org.dmg.pmml.DataField</code> ones
* @param toConvert
* @param field
* @return
*/
public static org.kie.pmml.api.models.MiningField convertToKieMiningField(final MiningField toConvert, final Field<?> field) {
final String name = toConvert.getName() != null ? toConvert.getName().getValue() : null;
final FIELD_USAGE_TYPE fieldUsageType = toConvert.getUsageType() != null ? FIELD_USAGE_TYPE.byName(toConvert.getUsageType().value()) : null;
final OP_TYPE opType = toConvert.getOpType() != null ? OP_TYPE.byName(toConvert.getOpType().value()) : null;
final DATA_TYPE dataType = field.getDataType() != null ? DATA_TYPE.byName(field.getDataType().value()) : null;
final MISSING_VALUE_TREATMENT_METHOD missingValueTreatmentMethod = toConvert.getMissingValueTreatment() != null ? MISSING_VALUE_TREATMENT_METHOD.byName(toConvert.getMissingValueTreatment().value()) : null;
final INVALID_VALUE_TREATMENT_METHOD invalidValueTreatmentMethod = toConvert.getInvalidValueTreatment() != null ? INVALID_VALUE_TREATMENT_METHOD.byName(toConvert.getInvalidValueTreatment().value()) : null;
final String missingValueReplacement = toConvert.getMissingValueReplacement() != null ? toConvert.getMissingValueReplacement().toString() : null;
final String invalidValueReplacement = toConvert.getInvalidValueReplacement() != null ? toConvert.getInvalidValueReplacement().toString() : null;
final List<String> allowedValues = field instanceof DataField ? convertDataFieldValues(((DataField) field).getValues()) : Collections.emptyList();
final List<org.kie.pmml.api.models.Interval> intervals = field instanceof DataField ? convertDataFieldIntervals(((DataField) field).getIntervals()) : Collections.emptyList();
return new org.kie.pmml.api.models.MiningField(name, fieldUsageType, opType, dataType, missingValueTreatmentMethod, invalidValueTreatmentMethod, missingValueReplacement, invalidValueReplacement, allowedValues, intervals);
}
Aggregations